DescendantsPageListModal.spec.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { render, screen, fireEvent } from '@testing-library/react';
  2. import { DescendantsPageListModal } from './DescendantsPageListModal';
  3. const mockClose = vi.hoisted(() => vi.fn());
  4. const useIsDeviceLargerThanLg = vi.hoisted(() => vi.fn().mockReturnValue({ data: true }));
  5. vi.mock('next/router', () => ({
  6. useRouter: () => ({
  7. events: {
  8. on: vi.fn(),
  9. off: vi.fn(),
  10. },
  11. }),
  12. }));
  13. vi.mock('~/stores/modal', () => ({
  14. useDescendantsPageListModal: vi.fn().mockReturnValue({
  15. data: { isOpened: true },
  16. close: mockClose,
  17. }),
  18. }));
  19. vi.mock('~/stores/ui', () => ({
  20. useIsDeviceLargerThanLg,
  21. }));
  22. describe('DescendantsPageListModal.tsx', () => {
  23. it('should render the modal when isOpened is true', () => {
  24. render(<DescendantsPageListModal />);
  25. expect(screen.getByTestId('descendants-page-list-modal')).not.toBeNull();
  26. });
  27. it('should call close function when close button is clicked', () => {
  28. render(<DescendantsPageListModal />);
  29. const closeButton = screen.getByLabelText('Close');
  30. fireEvent.click(closeButton);
  31. expect(mockClose).toHaveBeenCalled();
  32. });
  33. describe('when device is larger than lg', () => {
  34. it('should render CustomNavTab', () => {
  35. render(<DescendantsPageListModal />);
  36. expect(screen.getByTestId('custom-nav-tab')).not.toBeNull();
  37. });
  38. it('should not render CustomNavDropdown', () => {
  39. render(<DescendantsPageListModal />);
  40. expect(screen.queryByTestId('custom-nav-dropdown')).toBeNull();
  41. });
  42. });
  43. describe('when device is smaller than lg', () => {
  44. beforeEach(() => {
  45. useIsDeviceLargerThanLg.mockReturnValue({ data: false });
  46. });
  47. it('should render CustomNavDropdown on devices smaller than lg', () => {
  48. render(<DescendantsPageListModal />);
  49. expect(screen.getByTestId('custom-nav-dropdown')).not.toBeNull();
  50. });
  51. it('should not render CustomNavTab', () => {
  52. render(<DescendantsPageListModal />);
  53. expect(screen.queryByTestId('custom-nav-tab')).toBeNull();
  54. });
  55. });
  56. });