-
Notifications
You must be signed in to change notification settings - Fork 218
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 #9140 from weseek/fix/114434-153970-add-descendant…
…s-page-list-modal-spec fix: add descendants page list modal spec
- Loading branch information
Showing
2 changed files
with
72 additions
and
1 deletion.
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
70 changes: 70 additions & 0 deletions
70
apps/app/src/client/components/DescendantsPageListModal.spec.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,70 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
|
||
import { DescendantsPageListModal } from './DescendantsPageListModal'; | ||
|
||
const mockClose = vi.hoisted(() => vi.fn()); | ||
const useIsDeviceLargerThanLg = vi.hoisted(() => vi.fn().mockReturnValue({ data: true })); | ||
|
||
vi.mock('next/router', () => ({ | ||
useRouter: () => ({ | ||
events: { | ||
on: vi.fn(), | ||
off: vi.fn(), | ||
}, | ||
}), | ||
})); | ||
|
||
vi.mock('~/stores/modal', () => ({ | ||
useDescendantsPageListModal: vi.fn().mockReturnValue({ | ||
data: { isOpened: true }, | ||
close: mockClose, | ||
}), | ||
})); | ||
|
||
vi.mock('~/stores/ui', () => ({ | ||
useIsDeviceLargerThanLg, | ||
})); | ||
|
||
describe('DescendantsPageListModal.tsx', () => { | ||
|
||
it('should render the modal when isOpened is true', () => { | ||
render(<DescendantsPageListModal />); | ||
expect(screen.getByTestId('descendants-page-list-modal')).not.toBeNull(); | ||
}); | ||
|
||
it('should call close function when close button is clicked', () => { | ||
render(<DescendantsPageListModal />); | ||
const closeButton = screen.getByLabelText('Close'); | ||
fireEvent.click(closeButton); | ||
expect(mockClose).toHaveBeenCalled(); | ||
}); | ||
|
||
describe('when device is larger than lg', () => { | ||
|
||
it('should render CustomNavTab', () => { | ||
render(<DescendantsPageListModal />); | ||
expect(screen.getByTestId('custom-nav-tab')).not.toBeNull(); | ||
}); | ||
|
||
it('should not render CustomNavDropdown', () => { | ||
render(<DescendantsPageListModal />); | ||
expect(screen.queryByTestId('custom-nav-dropdown')).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('when device is smaller than lg', () => { | ||
beforeEach(() => { | ||
useIsDeviceLargerThanLg.mockReturnValue({ data: false }); | ||
}); | ||
|
||
it('should render CustomNavDropdown on devices smaller than lg', () => { | ||
render(<DescendantsPageListModal />); | ||
expect(screen.queryByTestId('custom-nav-dropdown')).not.toBeNull(); | ||
}); | ||
|
||
it('should not render CustomNavTab', () => { | ||
render(<DescendantsPageListModal />); | ||
expect(screen.queryByTestId('custom-nav-tab')).toBeNull(); | ||
}); | ||
}); | ||
}); |