diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-12 17:24:13 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:14:41 +0100 |
| commit | 00f147a7a687d5772bcc538bc606cfff972178cd (patch) | |
| tree | 27eabeb83c05e14162c51b69d4a6f36d461947fc /src/components/atoms/layout/time/time.test.tsx | |
| parent | c87c615b5866b8a8f361eeb0764bfdea85740e90 (diff) | |
feat(components): add a Time component
Instead of using helpers functions to format the date each time we need
to use a time element, it makes more sense to create a new component
dedicated to this task.
Diffstat (limited to 'src/components/atoms/layout/time/time.test.tsx')
| -rw-r--r-- | src/components/atoms/layout/time/time.test.tsx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/components/atoms/layout/time/time.test.tsx b/src/components/atoms/layout/time/time.test.tsx new file mode 100644 index 0000000..910285d --- /dev/null +++ b/src/components/atoms/layout/time/time.test.tsx @@ -0,0 +1,39 @@ +import { describe, expect, it } from '@jest/globals'; +import { render, screen as rtlScreen } from '../../../../../tests/utils'; +import { settings } from '../../../../utils/config'; +import { Time } from './time'; + +describe('Time', () => { + it('renders a date wrapped in a time element', () => { + const date = '2022'; + + render(<Time date={date} />); + + expect(rtlScreen.getByText(new RegExp(date))).toHaveAttribute( + 'datetime', + new Date(date).toISOString() + ); + }); + + it('can show the time in addition to the date', () => { + const date = '2022'; + + render(<Time date={date} showTime />); + + expect(rtlScreen.getByText(new RegExp(date))).toHaveTextContent(/\sat\s/); + }); + + it('can show the week day in front of the date', () => { + const date = new Date(); + + render(<Time date={date.toDateString()} showWeekDay />); + + expect( + rtlScreen.getByText(new RegExp(`${date.getFullYear()}`)) + ).toHaveTextContent( + new Intl.DateTimeFormat(settings.locales.defaultLocale, { + weekday: 'long', + }).format(date) + ); + }); +}); |
