Skip to content

Commit

Permalink
Merge branch 'main' into dateFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
werdnanoslen authored Feb 8, 2024
2 parents 68763b5 + eecbac1 commit 03b0236
Show file tree
Hide file tree
Showing 9 changed files with 1,540 additions and 672 deletions.
11 changes: 11 additions & 0 deletions __mocks__/tabbable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const lib = jest.requireActual('tabbable');

const tabbable = {
...lib,
tabbable: (node, options) => lib.tabbable(node, { ...options, displayCheck: 'none' }),
focusable: (node, options) => lib.focusable(node, { ...options, displayCheck: 'none' }),
isFocusable: (node, options) => lib.isFocusable(node, { ...options, displayCheck: 'none' }),
isTabbable: (node, options) => lib.isTabbable(node, { ...options, displayCheck: 'none' }),
};

module.exports = tabbable;
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,13 @@
"@svgr/webpack": "^8.0.1",
"@testing-library/dom": "^9.0.0",
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/react": "^12.1.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.0.4",
"@types/classnames": "^2.2.9",
"@types/jest": "^27.0.1",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/react-test-renderer": "^18.0.0",
"@types/jest": "^29.5.11",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"@types/react-test-renderer": "^18.0.7",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"@uswds/uswds": "3.7.1",
Expand All @@ -93,17 +92,17 @@
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-security": "^2.1.0",
"focus-trap-react": "^8.8.1",
"focus-trap-react": "^10.2.3",
"fork-ts-checker-webpack-plugin": "^9.0.0",
"happo-plugin-storybook": "^3.3.0",
"happo.io": "^8.3.1",
"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.1",
"mini-css-extract-plugin": "^2.6.1",
"prettier": "^2.7.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-test-renderer": "^17.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"sass": "^1.26.0",
"sass-loader": "^13.0.0",
"sass-resources-loader": "^2.0.1",
Expand All @@ -129,6 +128,7 @@
"json-schema": "0.4.0",
"glob-parent": "5.1.2",
"trim": "0.0.3",
"trim-newlines": "3.0.1"
"trim-newlines": "3.0.1",
"@types/react": "18.2.48"
}
}
17 changes: 10 additions & 7 deletions src/components/Footer/SocialLinks/SocialLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react'
import classnames from 'classnames'
import { Icon } from '../../Icon/Icons'
import { IconProps } from '../../Icon/Icon'

type SocialLinksProps = {
links: React.ReactNode[]
Expand Down Expand Up @@ -34,28 +35,30 @@ export const SocialLink = ({
name,
...props
}: SocialLinkProps & JSX.IntrinsicElements['a']): React.ReactElement => {
let icon: Icon
let IconComponent: React.ComponentType<IconProps>
switch (name) {
case 'Facebook':
icon = <Icon.Facebook className="usa-social-link__icon" name={name} />
IconComponent = Icon.Facebook
break
case 'Twitter':
icon = <Icon.Twitter className="usa-social-link__icon" name={name} />
IconComponent = Icon.Twitter
break
case 'YouTube':
icon = <Icon.Youtube className="usa-social-link__icon" name={name} />
IconComponent = Icon.Youtube
break
case 'Instagram':
icon = <Icon.Instagram className="usa-social-link__icon" name={name} />
IconComponent = Icon.Instagram
break
case 'RSS':
icon = <Icon.RssFeed className="usa-social-link__icon" name={name} />
IconComponent = Icon.RssFeed
break
}

return (
<a className="usa-social-link" {...props} title={name}>
{icon}
{IconComponent && (
<IconComponent className="usa-social-link__icon" name={name} />
)}
</a>
)
}
2 changes: 1 addition & 1 deletion src/components/InPageNavigation/InPageNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const InPageNavigation = ({
title = 'On this page',
...divProps
}: InPageNavigationProps &
JSX.IntrinsicElements['div']): React.ReactElement => {
Omit<JSX.IntrinsicElements['div'], 'content'>): React.ReactElement => {
const classes = classnames('usa-in-page-nav', styles.target, className)
const { className: navClassName, ...remainingNavProps } = navProps || {}
const navClasses = classnames('usa-in-page-nav__nav', navClassName)
Expand Down
64 changes: 50 additions & 14 deletions src/components/Modal/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jest.mock('./utils', () => {
}
})

/*
* Modal relies on focus-trap-react, which cannot be reliably tested
* in JSDom. A __mocks__/tabbable.js file ensures that a displayCheck setting
* for the library is set so that tests do not fail due to this
* incompatibility. See: https://github.com/focus-trap/tabbable#testing-in-jsdom
*/
const renderWithModalRoot = (
ui: React.ReactElement,
options: RenderOptions = {}
Expand Down Expand Up @@ -344,12 +350,16 @@ describe('Modal component', () => {

await waitFor(() => handleOpen())

expect(baseElement).toHaveClass('usa-js-modal--active')
await waitFor(() =>
expect(baseElement).toHaveClass('usa-js-modal--active')
)
expect(baseElement).toHaveStyle('padding-right: 15px')

await waitFor(() => handleClose())

expect(baseElement).not.toHaveClass('usa-js-modal--active')
await waitFor(() =>
expect(baseElement).not.toHaveClass('usa-js-modal--active')
)
expect(baseElement).toHaveStyle('padding-right: 0px')
})

Expand All @@ -370,12 +380,16 @@ describe('Modal component', () => {

await waitFor(() => handleOpen())

expect(baseElement).toHaveClass('usa-js-modal--active')
await waitFor(() =>
expect(baseElement).toHaveClass('usa-js-modal--active')
)
expect(baseElement).toHaveStyle('padding-right: 35px')

await waitFor(() => handleClose())

expect(baseElement).not.toHaveClass('usa-js-modal--active')
await waitFor(() =>
expect(baseElement).not.toHaveClass('usa-js-modal--active')
)
expect(baseElement).toHaveStyle('padding-right: 20px')
})

Expand Down Expand Up @@ -411,15 +425,21 @@ describe('Modal component', () => {

await waitFor(() => handleOpen())

expect(screen.getByTestId('nonhidden')).toHaveAttribute('aria-hidden')
await waitFor(() =>
expect(screen.getByTestId('nonhidden')).toHaveAttribute('aria-hidden')
)
expect(screen.getByTestId('nonhidden')).toHaveAttribute(
'data-modal-hidden'
)
expect(screen.getByTestId('hidden')).toHaveAttribute('aria-hidden')

await waitFor(() => handleClose())

expect(screen.getByTestId('nonhidden')).not.toHaveAttribute('aria-hidden')
await waitFor(() =>
expect(screen.getByTestId('nonhidden')).not.toHaveAttribute(
'aria-hidden'
)
)
expect(screen.getByTestId('nonhidden')).not.toHaveAttribute(
'data-modal-hidden'
)
Expand Down Expand Up @@ -462,15 +482,21 @@ describe('Modal component', () => {

await waitFor(() => handleOpen())

expect(screen.getByTestId('nonhidden')).toHaveAttribute('aria-hidden')
await waitFor(() =>
expect(screen.getByTestId('nonhidden')).toHaveAttribute('aria-hidden')
)
expect(screen.getByTestId('nonhidden')).toHaveAttribute(
'data-modal-hidden'
)
expect(screen.getByTestId('hidden')).toHaveAttribute('aria-hidden')

await waitFor(() => handleClose())

expect(screen.getByTestId('nonhidden')).not.toHaveAttribute('aria-hidden')
await waitFor(() =>
expect(screen.getByTestId('nonhidden')).not.toHaveAttribute(
'aria-hidden'
)
)
expect(screen.getByTestId('nonhidden')).not.toHaveAttribute(
'data-modal-hidden'
)
Expand Down Expand Up @@ -636,7 +662,9 @@ describe('Modal component', () => {

await waitFor(() => handleClose())

expect(baseElement).not.toHaveClass('usa-js-no-click')
await waitFor(() =>
expect(baseElement).not.toHaveClass('usa-js-no-click')
)
})

it('cannot click on the overlay to close', async () => {
Expand All @@ -652,7 +680,7 @@ describe('Modal component', () => {
)

await waitFor(() => handleOpen())
expect(modalRef.current?.modalIsOpen).toBe(true)
await waitFor(() => expect(modalRef.current?.modalIsOpen).toBe(true))

const overlay = screen.getByTestId('modalOverlay')
userEvent.click(overlay)
Expand Down Expand Up @@ -699,12 +727,16 @@ describe('Modal component', () => {

await waitFor(() => handleOpen())

expect(baseElement).toHaveClass('usa-js-modal--active')
await waitFor(() =>
expect(baseElement).toHaveClass('usa-js-modal--active')
)
expect(baseElement).toHaveStyle('padding-right: 15px')

await waitFor(() => unmount())

expect(baseElement).not.toHaveClass('usa-js-modal--active')
await waitFor(() =>
expect(baseElement).not.toHaveClass('usa-js-modal--active')
)
expect(baseElement).toHaveStyle('padding-right: 0px')
})

Expand All @@ -731,12 +763,16 @@ describe('Modal component', () => {

await waitFor(() => handleClose())

expect(baseElement).not.toHaveClass('usa-js-modal--active')
await waitFor(() =>
expect(baseElement).not.toHaveClass('usa-js-modal--active')
)
expect(baseElement).toHaveStyle('padding-right: 0px')

await waitFor(() => unmount())

expect(baseElement).not.toHaveClass('usa-js-modal--active')
await waitFor(() =>
expect(baseElement).not.toHaveClass('usa-js-modal--active')
)
expect(baseElement).toHaveStyle('padding-right: 0px')
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/Modal/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderHook, act } from '@testing-library/react-hooks'
import { renderHook, act } from '@testing-library/react'

import { useModal } from './utils'

Expand Down
4 changes: 3 additions & 1 deletion src/components/forms/DatePicker/DatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ describe('DatePicker component', () => {
await userEvent.click(getByTestId('date-picker-button'))
expect(getByTestId('date-picker-calendar')).toBeVisible()
getByTestId('test-external-element').focus()
expect(getByTestId('date-picker-calendar')).not.toBeVisible()
await waitFor(() =>
expect(getByTestId('date-picker-calendar')).not.toBeVisible()
)
expect(mockOnBlur).toHaveBeenCalled()
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/forms/DatePicker/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ export const isDateInvalid = (
export const listToTable = (
list: React.ReactNode[],
rowSize: number
): React.ReactFragment => {
): React.ReactNode => {
const rows = []
let i = 0

Expand Down
Loading

0 comments on commit 03b0236

Please sign in to comment.