-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(frontend): Add tests for sidebar
New test cases have been added for the sidebar component checking for successful rendering, toggle functionality verification, and validation of transition application to navigation when the toggle button is clicked. Refs: #1
- Loading branch information
Showing
2 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/sections/dashboard/components/sidebar/sidebar.test.tsx
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,36 @@ | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import Sidebar from '@/sections/dashboard/components/sidebar/sidebar'; | ||
import React from 'react'; | ||
|
||
describe('Sidebar', () => { | ||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
it('should render Sidebar without throwing an error', () => { | ||
const sidebar = render(<Sidebar />); | ||
expect(sidebar).toBeTruthy(); | ||
}); | ||
|
||
it('given sidebar is closed when the toggle button is clicked then should toggle to open ', () => { | ||
const mockHandleToggle = jest.fn(); | ||
jest.spyOn(React, 'useState').mockReturnValue([false, mockHandleToggle]); | ||
|
||
render(<Sidebar />); | ||
|
||
const button = screen.getByRole('button'); | ||
fireEvent.click(button); | ||
|
||
expect(mockHandleToggle).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('should apply transition to nav when the toggle button is clicked', () => { | ||
render(<Sidebar />); | ||
const button = screen.getByRole('button'); | ||
|
||
fireEvent.click(button); | ||
|
||
const nav = screen.getByTestId('sidebar-nav'); | ||
expect(nav.className).toContain('duration-500'); | ||
}); | ||
}); |
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