-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cfgov-footer_external-link-spacing
- Loading branch information
Showing
33 changed files
with
622 additions
and
41 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-1020 KB
.yarn/cache/@rollup-rollup-linux-x64-gnu-npm-4.9.6-c67944ac17-10.zip
Binary file not shown.
Binary file removed
BIN
-516 KB
.yarn/cache/@tanstack-query-core-npm-4.13.4-06c6632de9-a0ecb41d4a.zip
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-308 KB
.yarn/cache/@tanstack-react-query-npm-4.13.5-d478a3e963-56bb73e036.zip
Binary file not shown.
Binary file added
BIN
+331 KB
.yarn/cache/@tanstack-react-query-npm-4.36.1-435eddf619-764b860c3a.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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,29 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { ResponsiveMenu } from '~/src/index'; | ||
import '../PageHeader/header.less'; | ||
import { ExampleLinks } from './ResponsiveMenu'; | ||
|
||
const meta: Meta<typeof ResponsiveMenu> = { | ||
title: 'Components (Draft)/ResponsiveMenu', | ||
tags: ['autodocs'], | ||
component: ResponsiveMenu, | ||
argTypes: {} | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const LoggedIn: Story = { | ||
args: { | ||
links: ExampleLinks | ||
} | ||
}; | ||
|
||
export const LoggedOut: Story = { | ||
args: {} | ||
}; | ||
|
||
export const NoUser: Story = { | ||
args: {} | ||
}; |
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,114 @@ | ||
import '@testing-library/jest-dom'; | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import matchMediaMock from 'jest-matchmedia-mock'; | ||
import ResponsiveMenu, { ExampleLinks } from './ResponsiveMenu'; | ||
|
||
let matchMedia: matchMediaMock; | ||
|
||
describe('ResponsiveMenu', () => { | ||
beforeAll(() => { | ||
matchMedia = new matchMediaMock(); | ||
}); | ||
|
||
afterEach(() => { | ||
matchMedia.clear(); | ||
}); | ||
|
||
const resizeScreenSize = (width: number) => { | ||
Object.defineProperty(window, 'innerWidth', { | ||
writable: true, | ||
configurable: true, | ||
value: width | ||
}); | ||
window.dispatchEvent(new Event('resize')); | ||
}; | ||
|
||
it('does not render the menu without links', () => { | ||
resizeScreenSize(500); | ||
render(<ResponsiveMenu />); | ||
|
||
expect(screen.queryByTestId('menu-toggle')).not.toBeInTheDocument(); | ||
expect(screen.queryByRole('navigation')).not.toBeInTheDocument(); | ||
|
||
expect(screen.getByTestId('CfpbLogoLink')).toBeInTheDocument(); | ||
expect(screen.getByAltText('CFPB Logo')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders with custom links', () => { | ||
resizeScreenSize(500); | ||
render(<ResponsiveMenu links={ExampleLinks} />); | ||
|
||
// Menu is rendered | ||
const menuToggle = screen.getAllByRole('button')[0]; | ||
expect(menuToggle).toBeInTheDocument(); | ||
expect(screen.getByRole('navigation')).toBeInTheDocument(); | ||
|
||
// Links are rendered | ||
expect(screen.getByText('Home')).toBeInTheDocument(); | ||
expect(screen.getByText('Filing')).toBeInTheDocument(); | ||
expect(screen.getByText('John Sample')).toBeInTheDocument(); | ||
expect(screen.getByText('LOG OUT')).toBeInTheDocument(); | ||
}); | ||
|
||
it('toggles menu visibility on button click', () => { | ||
resizeScreenSize(500); | ||
|
||
render(<ResponsiveMenu links={ExampleLinks} />); | ||
const menuToggle = screen.getAllByRole('button')[0]; | ||
const navItems = screen.getByRole('navigation'); | ||
expect(navItems).not.toHaveClass('open'); | ||
expect(menuToggle).toHaveAttribute('aria-expanded', 'false'); | ||
|
||
fireEvent.click(menuToggle); | ||
|
||
expect(navItems).toHaveClass('open'); | ||
expect(menuToggle).toHaveAttribute('aria-expanded', 'true'); | ||
expect(menuToggle.querySelector('.sr-only')).toHaveTextContent( | ||
'Close menu' | ||
); | ||
|
||
fireEvent.click(menuToggle); | ||
|
||
expect(navItems).not.toHaveClass('open'); | ||
expect(menuToggle).toHaveAttribute('aria-expanded', 'false'); | ||
expect(menuToggle.querySelector('.sr-only')).toHaveTextContent('Open menu'); | ||
}); | ||
|
||
it('closes menu when clicking overlay', () => { | ||
render(<ResponsiveMenu links={ExampleLinks} />); | ||
const menuToggle = screen.getAllByRole('button')[0]; | ||
fireEvent.click(menuToggle); | ||
|
||
const overlay = screen.getByLabelText('Close menu'); | ||
fireEvent.click(overlay); | ||
|
||
expect(screen.getByRole('navigation')).not.toHaveClass('open'); | ||
}); | ||
|
||
it('closes menu when clicking a link', () => { | ||
render(<ResponsiveMenu links={ExampleLinks} />); | ||
const menuToggle = screen.getAllByRole('button')[0]; | ||
fireEvent.click(menuToggle); | ||
|
||
const link = screen.getByText('Home'); | ||
fireEvent.click(link); | ||
|
||
expect(screen.getByRole('navigation')).not.toHaveClass('open'); | ||
}); | ||
|
||
it('applies active class to the current page link', () => { | ||
render(<ResponsiveMenu links={ExampleLinks} />); | ||
const menuToggle = screen.getAllByRole('button')[0]; | ||
|
||
const activeLink = screen.getByText('Filing'); | ||
expect(activeLink).toHaveClass('active'); | ||
}); | ||
|
||
it('renders CFPB logo with custom href', () => { | ||
const customHref = 'https://example.com'; | ||
render(<ResponsiveMenu href={customHref} />); | ||
|
||
const logoLink = screen.getByTestId('CfpbLogoLink'); | ||
expect(logoLink).toHaveAttribute('href', customHref); | ||
}); | ||
}); |
Oops, something went wrong.