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

Use correct, custom formatter in Age component #1230

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .changelog/1230.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use correct, custom formatter in Age component
20 changes: 20 additions & 0 deletions src/app/components/Age/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { screen } from '@testing-library/react'
import { renderWithProviders } from '../../../utils/renderWithProviders'
import { Age } from '../'

describe('Age', () => {
beforeEach(() => {
jest.useFakeTimers()
jest.setSystemTime(new Date('2024-02-05T10:14:35.000Z'))
})

afterEach(() => {
jest.useRealTimers()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think afterEach is missing runOnlyPendingTimers call. According to docs here: https://testing-library.com/docs/using-fake-timers/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})

it('should display formatted values', () => {
renderWithProviders(<Age sinceTimestamp={'2024-02-05T10:14:40.000Z'} />)
expect(screen.getByText('5 sec')).toBeInTheDocument()
expect(screen.queryByText('less than a minute')).not.toBeInTheDocument()
})
})
2 changes: 1 addition & 1 deletion src/app/components/Age/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC } from 'react'
import Tooltip from '@mui/material/Tooltip'
import { formatDistanceToNow } from 'date-fns'
import { formatDistanceToNow } from '../../utils/dateFormatter'
import Box from '@mui/material/Box'
import { useFormattedTimestamp } from '../../hooks/useFormattedTimestamp'
import { tooltipDelay } from '../../../styles/theme'
Expand Down
Loading