Skip to content

Commit

Permalink
Merge pull request #9140 from weseek/fix/114434-153970-add-descendant…
Browse files Browse the repository at this point in the history
…s-page-list-modal-spec

fix: add descendants page list modal spec
  • Loading branch information
yuki-takei committed Sep 19, 2024
2 parents a5ab9d0 + 2737a02 commit a333bbb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const CustomNavDropdown = (props: CustomNavDropdownProps): JSX.Element =>
aria-haspopup="true"
aria-expanded={isDropdownOpen}
onClick={toggleDropdown}
data-testid="custom-nav-dropdown"
>
<span className="float-start">
{ Icon != null && <Icon /> } {i18n}
Expand Down Expand Up @@ -182,7 +183,7 @@ export const CustomNavTab = (props: CustomNavTabProps): JSX.Element => {
}

return (
<div className={`grw-custom-nav-tab ${styles['grw-custom-nav-tab']}`}>
<div data-testid="custom-nav-tab" className={`grw-custom-nav-tab ${styles['grw-custom-nav-tab']}`}>
<div ref={navContainerRef} className="d-flex justify-content-between">
<Nav className="nav-title">
{Object.entries(navTabMapping).map(([key, value]) => {
Expand Down
70 changes: 70 additions & 0 deletions apps/app/src/client/components/DescendantsPageListModal.spec.tsx
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();
});
});
});

0 comments on commit a333bbb

Please sign in to comment.