aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/atoms/layout/time/time.test.tsx
blob: 910285d074534ec148688848c96562d495924330 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)
    );
  });
});