Skip to content

Commit

Permalink
feat: Identifier component MVP (#1044)
Browse files Browse the repository at this point in the history
* Add files for New Component: Indentifier, wrote and passing one test for IdentifierGov

* Adding Storybook example for default Identifier rendering IdentifierGov

* Adding Storybook example for default Identifier rendering IdentifierGov

* Moving comments to the bottom of each file

* Adding IdentifierMasthead and IdentifierLinks, importing to Identifier; rendering text confirming import in Storybook

* Adding test for ability to pass in section attributes via props

* d

* Add template for each Storybook example; hard coded IdentifierGov component to display a description and a link to USA.gov

* Adding props to IdentifierLinks to pass links as props

* Adding test for passing attributes as props

* Adding placeholder links array to Identifier component, adding test for IdentifierLinks accepting custom styles

* Adding test checking for passed in language prop

* Adding content map for IdentifierGov component copy

* Rendering imported copy from content map in IdentifierGov component

* Adding storybook examples matching USWDS

* Forgot to push my changes yesterday

* Passing test for correct copy based on passed in language

* Noting established pattern in existing component

* Updating the content mapobject naming to make it easier to conditionally render the correct language

* Moving interface to content file, using Record to create safe way to use a string to access properties of the content map object

* Adding another test checking for IdentifierGov default behavior (renders English) when passed no props

* Adding test checking for passing in attributes via props, adding the code to IdentifierMasthead to pass the test

* Adding bare bones structure based on USWDS code to IdentifierMasthead

* Some cleanup in the content file, adding classnames method to the Identifier parent component

* Adding children components to storybook, rendering in spanish in storybook when passed as props to IdentifierGov

* Commiting yarn build updates to yarn.lock

* Removing duplicate IdentifierGov test

* Rendering complete IdentifierGov component in storybook, commiting snapshots taken for test purposes

* Adding test checking for ability to pass in a className, commiting updated snapshots

* Moving IdentifierGov copy map back to parent file, updating snapshots

* Add test checking for ability to pass in custom className to IdentifierMasthead component

* Import subcomponents to Identifier.test in order to pass render check, update IdentifierMasthead test for aria-label to actually test for custom label, update IdentifierGov test to be more elegantly worded

* Add test to IdentifierMasthead to check for ability to pass in Spanishlanguage prop

* Update Identifier test wording to be more specific

* Replace hardcoded text with reference to copy object, include update to Identifier.test test props that I forgot to save in the previous commit

* Add IdentifierMasthead props to Identifier.stories and Identifier.test, fix spacing between identityDisclaimer and the link to the parentAgency

* Add optional boolean for logo and second logo to IdentifierMasthead, add tests for no logo, passed in logo, and multiple logos, also add new props to Identifier.stories rendering appropriate amount of logos and in appropriate language

* Clean up comments, add note re: necessity of supporting more than two logos

* Add appropriate props to multiple-logos + Spanish Storybook example

* Add IdentifierLinkItem subfolder and files, importing to IdentifierLinks and rendering a div

* Nest IdentifierLinks files appropriately; add IdentifierLink, IdentifierLinkItem subcomponents

* Add IdentifierLink and tests following conventions established in BreadcrumbLink component

* Add tests for IdentifierLinkItem, remove wayward aria-label and associated test

* Remove superfluous data-testids

* Add Logo folder and files with mostly pseudocode

* Update Identifier logo subcomponent name to IdentifierLogo to differentiate between it and the Logo in Footer

* Update Identifier.stories to pass links into IdentifierLinks properly, import IdentifierLogo into IdentifierMasthead

* Remove comments, refactored code, update IdentifierMasthead in .stories

* Add tests for IdentifierLogo checking for ability to pass in props, add map accounting for multiple parent agencies

* Add new IdentifierMasthead test data to pass check in Identifier.test, add USWDS’ taxpayer disclaimer sample text to Identifier.stories, add conditional taxpayer disclaimer prop and conditional rendering for parent agencies to IdentifierMasthead

* Add usa-link class to IdentifierLink and amend tests to check for usa-class

* Update IdentifierLinks test to use subcomponents, remove DRY testvars in IdentifierLink in favor of DAMP

* Add query to IdentifierLinks test, update IdentifierMasthead tests to reflect MVP check for rendering one agency and one logo

* Conditionally render taxpayer disclaimer prop in IdentifierMasthead, update Identifier.stories to render subcomponents with USWDS example text

* Add check for IdentifierLinks - render its subcomponents and render a custom link

* Add test to Identifier to check for ability to render without errors in English and Spanish, and render without a logo

* Add testParentAgencyNoLogos for no logo storybook examples

* Move taxpayer disclaimer out of the parent agency link

* Respond to PR feedback: move div in Masthead, remove commented out import in index.ts, remove disable in .stories, update .stories export to match new convention

* Export all new Identifier components within index.ts

* Remove IdentifierMasthead content map, transfer those props to the ParentAgency interface

* Update Identifier.test and IdentifierMasthead.test with new test data

* Fix Identifier test query, remove deprecated test data

* Place logos div inside of conditional logo rendering

* Refactor IdentifierLogo out of IdentifierMasthead file, passing it in and rendering as children in .stories file

* Refactor agency interface out of IdentifierMasthead, refactor test agency objects out of Identifier.stories, passing directly into components in stories

* Move container div from IdentifierMasthead into Identifier.stories

* Remove ariaLabel prop from IdentifierMasthead

* Remove superfluous test data from IdentifierMasthead tests

* Remove test data from IdentifierMasthead tests again

* Refactor content out of IdentifierGov, add example content to .stories

* Refactor img out of IdentifierLogo, may be able to get rid of this component altogether, TBD

* Render storybook examples for multiple parents and logos, english and spanish; update naming convention to remove the word identifier from storybook examples except for Default and Spanish

* Refactor hardcoded aria-label out of IdentifierLinks, passing it in via navProps in each storybook example with English and Spanish

* Add storybook example for more than two parent agencies, add storybook example for multiple parent agencies plus tax disclaimer copy

* Update Identifier tests to reflect refactored subcomponents and structure, add tests checking for cases with no logos, cases with more than two logos

* Remove superfluous import

* Update IdentifierMasthead tests with new structure and test data, check for rendering without errors, rendering in Spanish, rendering without a logo, rendering more than two logos

* Update Identifier.stories test data props

* Update test variable declarations, the test images didn't need to be arrays

* Update IdentifierLogo test file

* Remove comment from IdentifierLinks test file, pass a string instead of the test variable so expected doesn't point to the same place as actual

* Update IdentifierGov test file

* Fixes from PR feedback; remove custom className from storybook example, update IdentifierLogo prop agencyUrl to simply href and update everywhere, all hrefs now point to # and eslint check is disabled to reflect that in Identifier.stories

* Add fixes from PR feedback from Suz; structure IdentifierLogo like the rest of the components including JSX.IntrinsicElements in function signature instead of passed in props, update Identifier to take in and spread a divProps property on the parent div to handle anything the user might want to pass in to be applied to the entire component

* Remove unnecessary dependencies array from package.json

Co-authored-by: Brandon Lenz <brandonalenz@gmail.com>
  • Loading branch information
SirenaBorracha and brandonlenz authored Apr 5, 2021
1 parent 80d3db9 commit e79bc87
Show file tree
Hide file tree
Showing 18 changed files with 1,304 additions and 9 deletions.
416 changes: 416 additions & 0 deletions src/components/Identifier/Identifier/Identifier.stories.tsx

Large diffs are not rendered by default.

304 changes: 304 additions & 0 deletions src/components/Identifier/Identifier/Identifier.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
import React from 'react'
import { render } from '@testing-library/react'

import { Identifier } from './Identifier'
import { IdentifierMasthead } from '../IdentifierMasthead/IdentifierMasthead'
import { IdentifierLogo } from '../IdentifierLogo/IdentifierLogo'
import { IdentifierLinks } from '../IdentifierLinks/IdentifierLinks'
import { IdentifierLink } from '../IdentifierLink/IdentifierLink'
import { IdentifierLinkItem } from '../IdentifierLinkItem/IdentifierLinkItem'
import { IdentifierGov } from '../IdentifierGov/IdentifierGov'

import dotGovIcon from 'uswds/src/img/icon-dot-gov.svg'

const testIdentifierLogo = (
<img
src={dotGovIcon}
className="usa-identifier__logo-img"
alt="Test Agency Name logo"
/>
)

const testIdentifierLogoSpanish = (
<img
src={dotGovIcon}
className="usa-identifier__logo-img"
alt="Logo de Test Agency Name"
/>
)

const testLinks = [
<IdentifierLinkItem key="one">
<IdentifierLink href="#">About &lt;Parent shortname&gt;</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="two">
<IdentifierLink href="#">Accessibility support</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="three">
<IdentifierLink href="#">FOIA requests</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="four">
<IdentifierLink href="#">No FEAR Act data</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="five">
<IdentifierLink href="#">Office of the Inspector General</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="six">
<IdentifierLink href="#">Performance reports</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="seven">
<IdentifierLink href="#">Privacy policy</IdentifierLink>
</IdentifierLinkItem>,
]

const testLinksSpanish = [
<IdentifierLinkItem key="one">
<IdentifierLink href="#">Acerca de &lt;Parent shortname&gt;</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="two">
<IdentifierLink href="#">Soporte de accesibilidad</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="three">
<IdentifierLink href="#">Solicitud a través de FOIA</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="four">
<IdentifierLink href="#">Datos de la ley No FEAR</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="five">
<IdentifierLink href="#">Oficina del Inspector General</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="six">
<IdentifierLink href="#">Informes de desempeño</IdentifierLink>
</IdentifierLinkItem>,
<IdentifierLinkItem key="seven">
<IdentifierLink href="#">Política de privacidad</IdentifierLink>
</IdentifierLinkItem>,
]

const testIdentifierGovContent = [
<div className="usa-identifier__container" key="one">
<div
data-testid="identifierGov-description"
className="usa-identifier__usagov-description">
Looking for U.S. government information and services?
</div>
&nbsp;
<a
data-testid="identifierGov-link"
href="https://www.usa.gov/"
className="usa-link">
Visit USA.gov
</a>
</div>,
]

const testIdentifierGovContentSpanish = [
<div className="usa-identifier__container" key="two">
<div
data-testid="identifierGov-description"
className="usa-identifier__usagov-description">
¿Necesita información y servicios del Gobierno?
</div>
&nbsp;
<a
data-testid="identifierGov-link"
href="https://www.usa.gov/espanol/"
className="usa-link">
Visite USAGov en Español
</a>
</div>,
]

describe('Identifier component', () => {
it('renders without errors', () => {
const { getByRole, getAllByRole, queryByTestId } = render(
<Identifier>
<IdentifierMasthead aria-label="Agency identifier">
<div className="usa-identifier__container">
<div className="usa-identifier__logos">
<IdentifierLogo href="#" className="custom-class-name">
{testIdentifierLogo}
</IdentifierLogo>
</div>
<div
data-testid="identifierMasthead-agency-description"
className="usa-identifier__identity"
aria-label="Agency description">
<p className="usa-identifier__identity-domain">
domain.edu.mil.gov
</p>
<p className="usa-identifier__identity-disclaimer">
{`An official website of the `}
<a href="testlink">Test Agency Name</a>
</p>
</div>
</div>
</IdentifierMasthead>
<IdentifierLinks navProps={{ 'aria-label': 'Important links' }}>
{testLinks}
</IdentifierLinks>
<IdentifierGov aria-label="U.S. government information and services">
{testIdentifierGovContent}
</IdentifierGov>
</Identifier>
)

expect(queryByTestId('identifier')).toBeInTheDocument()
expect(queryByTestId('identifierMasthead')).toBeInTheDocument()
expect(queryByTestId('identifierGov')).toBeInTheDocument()
expect(getAllByRole('link')).toHaveLength(10)
expect(getByRole('navigation')).toBeInTheDocument()
})

it('renders in Spanish', () => {
const { getAllByRole, queryByText } = render(
<Identifier>
<IdentifierMasthead aria-label="Identificador de la agencia">
<div className="usa-identifier__container">
<div className="usa-identifier__logos">
<IdentifierLogo href="#">
{testIdentifierLogoSpanish}
</IdentifierLogo>
</div>
<div
data-testid="identifierMasthead-agency-description"
className="usa-identifier__identity"
aria-label="Descripción de la agencia">
<p className="usa-identifier__identity-domain">
domain.edu.mil.gov
</p>
<p className="usa-identifier__identity-disclaimer">
{`Un sitio web oficial de `}
<a href="testlink">Test Agency Name Spanish</a>
</p>
</div>
</div>
</IdentifierMasthead>
<IdentifierLinks navProps={{ 'aria-label': 'Enlaces importantes' }}>
{testLinksSpanish}
</IdentifierLinks>
<IdentifierGov aria-label="Información y servicios del Gobierno de EE. UU.">
{testIdentifierGovContentSpanish}
</IdentifierGov>
</Identifier>
)

expect(queryByText('Un sitio web oficial de')).toBeInTheDocument()
expect(queryByText('Visite USAGov en Español')).toBeInTheDocument()
expect(getAllByRole('link')).toHaveLength(10)
})

it('renders without logos', () => {
const { getAllByRole, getByTestId, queryByText } = render(
<Identifier>
<IdentifierMasthead aria-label="Agency identifier">
<div className="usa-identifier__container">
<div
data-testid="identifierMasthead-agency-description"
className="usa-identifier__identity"
aria-label="Agency description">
<p className="usa-identifier__identity-domain">
domain.edu.mil.gov
</p>
<p className="usa-identifier__identity-disclaimer">
{`An official website of the `}
<a href="testlink">Test Agency Name</a>
</p>
</div>
</div>
</IdentifierMasthead>
<IdentifierLinks navProps={{ 'aria-label': 'Important links' }}>
{testLinks}
</IdentifierLinks>
<IdentifierGov aria-label="U.S. government information and services">
{testIdentifierGovContent}
</IdentifierGov>
</Identifier>
)

expect(getByTestId('identifierMasthead-agency-description')).not.toContain(
'img'
)
expect(getAllByRole('link')).toHaveLength(9)
expect(queryByText('Privacy policy')).toBeInTheDocument()
})

it('renders more than two parent agencies', () => {
const { getAllByRole, queryByText } = render(
<Identifier>
<IdentifierMasthead aria-label="Agency identifier">
<div className="usa-identifier__container">
<div className="usa-identifier__logos">
<IdentifierLogo href="#">{testIdentifierLogo}</IdentifierLogo>
<IdentifierLogo href="#">{testIdentifierLogo}</IdentifierLogo>
<IdentifierLogo href="#">{testIdentifierLogo}</IdentifierLogo>
</div>
<div
data-testid="identifierMasthead-agency-description"
className="usa-identifier__identity"
aria-label="Agency description">
<p className="usa-identifier__identity-domain">
domain.edu.mil.gov
</p>
<p className="usa-identifier__identity-disclaimer">
{`An official website of the `}
<a href="testlink">Test Agency Name</a>
{`, `}
<a href="secondTestLink">Second Test Agency Name</a>
{`, and the `}
<a href="ThirdTestLink">Third Test Agency Name</a>
</p>
</div>
</div>
</IdentifierMasthead>
<IdentifierLinks navProps={{ 'aria-label': 'Important links' }}>
{testLinks}
</IdentifierLinks>
<IdentifierGov aria-label="U.S. government information and services">
{testIdentifierGovContent}
</IdentifierGov>
</Identifier>
)

expect(getAllByRole('img')).toHaveLength(3)
expect(getAllByRole('link')).toHaveLength(14)
expect(queryByText('Third Test Agency Name')).toBeInTheDocument()
})

it('renders tax disclaimer', () => {
const { getByTestId } = render(
<Identifier>
<IdentifierMasthead aria-label="Agency identifier">
<div className="usa-identifier__container">
<div className="usa-identifier__logos">
<IdentifierLogo href="#">{testIdentifierLogo}</IdentifierLogo>
</div>
<div
data-testid="identifierMasthead-agency-description"
className="usa-identifier__identity"
aria-label="Agency description">
<p className="usa-identifier__identity-domain">
domain.edu.mil.gov
</p>
<p className="usa-identifier__identity-disclaimer">
{`An official website of the `}
<a href="testlink">Test Agency Name</a>
{`. Produced and published at taxpayer expense.`}
</p>
</div>
</div>
</IdentifierMasthead>
<IdentifierLinks navProps={{ 'aria-label': 'Important links' }}>
{testLinks}
</IdentifierLinks>
<IdentifierGov aria-label="U.S. government information and services">
{testIdentifierGovContent}
</IdentifierGov>
</Identifier>
)

expect(
getByTestId('identifierMasthead-agency-description')
).toHaveTextContent('Produced and published at taxpayer expense.')
})
})
22 changes: 22 additions & 0 deletions src/components/Identifier/Identifier/Identifier.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import classnames from 'classnames'

interface IdentifierProps {
className?: string
children: React.ReactNode
}

export const Identifier = ({
className,
children,
...divProps
}: IdentifierProps & JSX.IntrinsicElements['div']): React.ReactElement => {
const classes = classnames('usa-identifier', className)
return (
<div data-testid="identifier" className={classes} {...divProps}>
{children}
</div>
)
}

export default Identifier
47 changes: 47 additions & 0 deletions src/components/Identifier/IdentifierGov/IdentifierGov.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import { render } from '@testing-library/react'
import renderer from 'react-test-renderer'

import { IdentifierGov } from './IdentifierGov'

describe('IdentifierGov component', () => {
it('renders without errors', () => {
const { queryByTestId } = render(<IdentifierGov />)
expect(queryByTestId('identifierGov')).toBeInTheDocument()
})

it('renders section attributes passed in through props', () => {
const { queryByTestId } = render(
<IdentifierGov aria-label="custom aria-label value" />
)

expect(queryByTestId('identifierGov')).toHaveAttribute(
'aria-label',
'custom aria-label value'
)
})

it('renders consistently in Spanish', () => {
const tree = renderer
.create(
<IdentifierGov>
<div className="usa-identifier__container">
<div
data-testid="identifierGov-description"
className="usa-identifier__usagov-description">
¿Necesita información y servicios del Gobierno?
</div>
&nbsp;
<a
data-testid="identifierGov-link"
href="https://www.usa.gov/espanol/"
className="usa-link">
Visite USAGov en Español
</a>
</div>
</IdentifierGov>
)
.toJSON()
expect(tree).toMatchSnapshot()
})
})
Loading

0 comments on commit e79bc87

Please sign in to comment.