Skip to content

Commit

Permalink
Fix other tests affected by the upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gnapse authored and Bloomca committed Jan 17, 2024
1 parent c956ed1 commit 0ee2ff4
Showing 1 changed file with 7 additions and 46 deletions.
53 changes: 7 additions & 46 deletions src/components/time/time.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { axe } from 'jest-axe'
import { Time } from './time'
import userEvent from '@testing-library/user-event'

import { SHOW_DELAY } from '../../tooltip/tooltip'

describe('Time', () => {
beforeAll(() => {
jest.useFakeTimers()
Expand Down Expand Up @@ -69,78 +67,41 @@ describe('Time', () => {
})

it('renders wrapped in tooltip when tooltipOnHover is set', async () => {
jest.useRealTimers()
render(<Time time={testDate} tooltipOnHover />)

userEvent.hover(screen.getByText('March 22, 1991'))
await waitFor(
() => {
expect(
screen.getByRole('tooltip', { name: 'March 22, 1991, 1:37 PM' }),
).toBeVisible()
},
{ timeout: SHOW_DELAY + 10 },
)

userEvent.unhover(screen.getByText('March 22, 1991'))
await waitFor(() => {
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
expect(screen.getByRole('tooltip', { name: 'March 22, 1991, 1:37 PM' })).toBeVisible()
})
})

it('renders with custom tooltip when supplied', async () => {
render(<Time time={testDate} tooltipOnHover tooltip="Test" />)

userEvent.hover(screen.getByText('March 22, 1991'))
await waitFor(
() => {
expect(screen.getByRole('tooltip', { name: 'Test' })).toBeVisible()
},
{ timeout: SHOW_DELAY + 10 },
)

userEvent.unhover(screen.getByText('March 22, 1991'))
await waitFor(() => {
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
expect(screen.getByRole('tooltip', { name: 'Test' })).toBeVisible()
})
})

it('does not render short absolute time on hover when tooltipOnHover is set', async () => {
render(<Time time={dayjs().unix()} tooltipOnHover expandOnHover />)
userEvent.hover(screen.getByText('moments ago'))

await waitFor(
() => {
expect(
screen.getByRole('tooltip', { name: dayjs().format('LL, LT') }),
).toBeVisible()
expect(screen.getByText('moments ago')).toBeVisible()
},
{ timeout: SHOW_DELAY + 10 },
)

userEvent.unhover(screen.getByText('moments ago'))
await waitFor(() => {
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
expect(screen.getByRole('tooltip', { name: dayjs().format('LL, LT') })).toBeVisible()
expect(screen.getByText('moments ago')).toBeVisible()
})
})

it('does not render full absolute time on hover when tooltipOnHover is set', async () => {
render(<Time time={dayjs().unix()} tooltipOnHover expandFullyOnHover />)
userEvent.hover(screen.getByText('moments ago'))

await waitFor(
() => {
expect(
screen.getByRole('tooltip', { name: dayjs().format('LL, LT') }),
).toBeVisible()
expect(screen.getByText('moments ago')).toBeVisible()
},
{ timeout: SHOW_DELAY + 10 },
)

userEvent.unhover(screen.getByText('moments ago'))
await waitFor(() => {
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument()
expect(screen.getByRole('tooltip', { name: dayjs().format('LL, LT') })).toBeVisible()
expect(screen.getByText('moments ago')).toBeVisible()
})
})

Expand Down

0 comments on commit 0ee2ff4

Please sign in to comment.