Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Create Tooltip component #871

Merged
merged 38 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
9e83e45
create tooltip using css usilities
noelledusahel Feb 10, 2021
bddd6df
additional styles
noelledusahel Feb 11, 2021
e7614a7
add useState hooks to tooltip component
noelledusahel Feb 11, 2021
69f46d8
add correct styles according to position
noelledusahel Feb 17, 2021
378d9ce
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel Feb 17, 2021
f2e4cb4
additional edits to positioning tooltip body, add element ID to locat…
noelledusahel Feb 19, 2021
41c6529
move all positioning login into a useEffect, register TooltipBodyWidt…
noelledusahel Feb 23, 2021
ff163b5
add tooltip ID and remove comments
noelledusahel Feb 23, 2021
7da70f6
remove styles file
noelledusahel Feb 23, 2021
86ed906
add tests to tooltip component
noelledusahel Feb 23, 2021
3d04526
export tooltip component in index.ts
noelledusahel Feb 23, 2021
05455d8
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel Feb 23, 2021
54d7527
replace reference to tooltipBodyRef.current with variable tooltipBody…
noelledusahel Feb 23, 2021
7a34626
Merge branch 'main' into nb-react-uswds-tooltip
ahobson Feb 23, 2021
3f1e33e
remove package lock file
noelledusahel Feb 23, 2021
112fcd8
create a default tooltip trigger button and create tests for tooltip …
noelledusahel Feb 25, 2021
3034608
begin writing up custom component based off of Link component example
noelledusahel Feb 25, 2021
f1128d6
put custom component render in a conditional statement
noelledusahel Feb 26, 2021
40eb2ab
utilize forward ref in customComponent
noelledusahel Feb 26, 2021
559028b
abstract useEffect into a fn, useTooltip
noelledusahel Feb 26, 2021
977604b
move html element role, move event listeners to custom component props
noelledusahel Mar 1, 2021
490e060
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel Mar 1, 2021
f433a51
move isElementInViewport to a utils file
noelledusahel Mar 1, 2021
8139294
correct tests and add test id to tooltip trigger element
noelledusahel Mar 1, 2021
702ebbf
add display name
noelledusahel Mar 1, 2021
b672777
add story displayname
noelledusahel Mar 1, 2021
ec2525f
corect var name CustomLinkProps
noelledusahel Mar 2, 2021
e5ad8f6
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel Mar 2, 2021
a104900
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel Mar 9, 2021
ea89aa0
update tests
noelledusahel Mar 9, 2021
dce0062
add data classes prop for css utility classes
noelledusahel Mar 9, 2021
5353144
add keyboard events to tests
noelledusahel Mar 9, 2021
ac29ad6
change dataclasses to wrapperclasses and move to trigger element, mov…
noelledusahel Mar 16, 2021
f261e00
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel Mar 16, 2021
a0fbe6e
remove className for wrapperclasses from tooltipComponent
noelledusahel Mar 16, 2021
92763d1
apply classname to tooltipTrigger element
noelledusahel Mar 16, 2021
a50949c
reformat for storybook addon
noelledusahel Mar 18, 2021
e11b26e
Merge remote-tracking branch 'origin/main' into nb-react-uswds-tooltip
noelledusahel Mar 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/components/Tooltip/Tooltip.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { ReactNode } from 'react'
import { fireEvent, render } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

import { Tooltip } from './Tooltip'

describe('Tooltip component', () => {
haworku marked this conversation as resolved.
Show resolved Hide resolved
it('renders without errors', () => {
const { queryByTestId } = render(
<Tooltip label="Click me">My Tooltip</Tooltip>
)
expect(queryByTestId('tooltipWrapper')).toBeInTheDocument()
expect(queryByTestId('triggerElement')).toBeInTheDocument()
expect(queryByTestId('tooltipBody')).toBeInTheDocument()
})

it('hides tooltip by default', () => {
const { getByTestId } = render(
<Tooltip label="Click me">My Tooltip</Tooltip>
)
expect(getByTestId('tooltipBody')).not.toHaveClass('is-visible')
})

it('shows tooltip with mouse event', () => {
const { getByTestId } = render(
<Tooltip label="Click me">My Tooltip</Tooltip>
)
fireEvent.mouseEnter(getByTestId('triggerElement'))
expect(getByTestId('tooltipBody')).toHaveClass('is-visible')
})

it('hides tooltip with mouse event', () => {
const { getByTestId } = render(
<Tooltip label="Click me">My Tooltip</Tooltip>
)
fireEvent.mouseLeave(getByTestId('triggerElement'))
expect(getByTestId('tooltipBody')).not.toHaveClass('is-visible')
})

it('shows tooltip with keyboard event', () => {
const { getByTestId } = render(
<Tooltip label="Click me">My Tooltip</Tooltip>
)
fireEvent.focus(getByTestId('triggerElement'))
expect(getByTestId('tooltipBody')).toHaveClass('is-visible')
})

it('hides tooltip with keyboard event', () => {
const { getByTestId } = render(
<Tooltip label="Click me">My Tooltip</Tooltip>
)
fireEvent.blur(getByTestId('triggerElement'))
expect(getByTestId('tooltipBody')).not.toHaveClass('is-visible')
})

describe('with a position prop', () => {
it('applies the default tooltip position', () => {
const { getByTestId } = render(
<Tooltip label="Click me">My Tooltip</Tooltip>
)
expect(getByTestId('tooltipBody')).toHaveClass(
`usa-tooltip__body usa-tooltip__body--top`
)
})

it('applies the correct tooltip position when position prop is defined', () => {
const { getByTestId } = render(
<Tooltip position="bottom" label="Click me">
My Tooltip
</Tooltip>
)
expect(getByTestId('tooltipBody')).toHaveClass(
`usa-tooltip__body usa-tooltip__body--bottom`
)
})
})

describe('with a className prop', () => {
it('applies the className', () => {
const customClass = 'custom-class'
const { getByTestId } = render(
<Tooltip className={customClass} position="left" label="Click me">
My Tooltip
</Tooltip>
)
expect(getByTestId('tooltipWrapper')).toHaveClass(`${customClass}`)
})
})
})
Loading