-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from dusek2/indexTest
Adding more unit tests index.js, skeleton.js
- Loading branch information
Showing
5 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import Skeleton from '../pages/skeleton/Skeleton'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
|
||
// Mocking useFontSize hook | ||
jest.mock('../contexts/FontSizeContext', () => ({ | ||
useFontSize: () => ({ | ||
fontSize: 16, // Sample font size | ||
darkMode: false, // Sample dark mode value | ||
}), | ||
})); | ||
|
||
describe('Skeleton Component', () => { | ||
test('renders skeleton route', () => { | ||
render(<Skeleton />); | ||
const skeletonRoute = screen.getByTestId('skeleton-route'); | ||
expect(skeletonRoute).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders navigation panel', () => { | ||
render(<Skeleton />); | ||
const navigationPanel = screen.getByTestId('navigation-panel'); | ||
expect(navigationPanel).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders frame', () => { | ||
render(<Skeleton />); | ||
const frame = screen.getByTestId('top-panel'); | ||
expect(frame).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders page content', () => { | ||
render(<Skeleton />); | ||
const pageContent = screen.getByTestId('page-content'); | ||
expect(pageContent).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createRoot } from "react-dom/client"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
import App from "../App"; | ||
import "../global.css"; | ||
|
||
// Mock createRoot function | ||
jest.mock("react-dom/client", () => ({ | ||
createRoot: jest.fn(), | ||
})); | ||
|
||
describe("index.js", () => { | ||
let mockRender; | ||
|
||
beforeEach(() => { | ||
// Mock render function | ||
mockRender = jest.fn(); | ||
|
||
// Mock createRoot implementation | ||
createRoot.mockReturnValue({ | ||
render: mockRender, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("sets up the root element and renders App within BrowserRouter", () => { | ||
// Require index.js to execute the setup | ||
require("../index"); | ||
|
||
// Verify createRoot is called with the root container | ||
expect(createRoot).toHaveBeenCalledTimes(1); | ||
expect(createRoot).toHaveBeenCalledWith(document.getElementById("root")); | ||
|
||
// Verify App component is rendered within BrowserRouter | ||
expect(mockRender).toHaveBeenCalledTimes(1); | ||
expect(mockRender.mock.calls[0][0]).toEqual( | ||
<BrowserRouter> | ||
<App data-testid="app-root" /> | ||
</BrowserRouter> | ||
); | ||
}); | ||
}); |