generated from cloud-gov/.github
-
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.
- Loading branch information
Showing
4 changed files
with
139 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { describe, expect, it } from '@jest/globals'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { Banner } from '@/components/uswds/Banner'; | ||
|
||
describe('<Banner />', () => { | ||
describe('on initial load', () => { | ||
it('content is collapsed', () => { | ||
// act | ||
render(<Banner />); | ||
// assert | ||
const content = screen.queryByText('Official websites use .gov'); | ||
expect(content).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('when button is clicked', () => { | ||
it('content expands', async () => { | ||
// setup | ||
render(<Banner />); | ||
// act | ||
// There are two elements with this text, but only one is visible (the other is for screen readers). So we get the second of the two, which is the button we want. | ||
const button = screen.getAllByText('Here’s how you know')[1]; | ||
fireEvent.click(button); | ||
// assert | ||
const content = await screen.findByText('Official websites use .gov'); | ||
expect(content).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
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,63 @@ | ||
'use client'; | ||
|
||
import Image from 'next/image'; | ||
import { useState } from 'react'; | ||
|
||
export function Header() { | ||
const [isVisible, setIsVisible] = useState(false); | ||
|
||
const toggleMenu = () => setIsVisible(!isVisible); | ||
|
||
return ( | ||
<> | ||
<div className={`usa-overlay ${isVisible ? 'is-visible' : ''}`}></div> | ||
<header className="usa-header usa-header--basic"> | ||
<div className="usa-nav-container"> | ||
<div className="usa-navbar border-0 flex-justify-end"> | ||
<button type="button" className="usa-menu-btn" onClick={toggleMenu}> | ||
Menu | ||
</button> | ||
</div> | ||
<nav | ||
aria-label="Primary navigation" | ||
className={`usa-nav border-bottom border-base-light ${isVisible ? 'is-visible' : ''}`} | ||
> | ||
<button | ||
type="button" | ||
className="usa-nav__close" | ||
onClick={toggleMenu} | ||
> | ||
<Image | ||
src="/img/uswds/usa-icons/close.svg" | ||
role="img" | ||
alt="Close" | ||
height={24} | ||
width={24} | ||
/> | ||
</button> | ||
<ul className="usa-nav__primary usa-accordion"> | ||
<li className="usa-nav__primary-item"> | ||
<a | ||
href="javascript:void(0);" | ||
className="usa-nav-link usa-current" | ||
> | ||
<span>Product Section</span> | ||
</a> | ||
</li> | ||
<li className="usa-nav__primary-item"> | ||
<a href="javascript:void(0);" className="usa-nav-link"> | ||
<span>Product Section</span> | ||
</a> | ||
</li> | ||
<li className="usa-nav__primary-item"> | ||
<a href="javascript:void(0);" className="usa-nav-link"> | ||
<span>Product Section</span> | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
</header> | ||
</> | ||
); | ||
} |