2022-05-29 21:32:34 +03:00
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import { TimeProps, Time } from '../../src/utils/Time';
|
2021-06-25 21:05:06 +03:00
|
|
|
import { parseDate } from '../../src/utils/helpers/date';
|
|
|
|
|
|
|
|
describe('<Time />', () => {
|
2022-05-29 21:32:34 +03:00
|
|
|
const setUp = (props: TimeProps) => render(<Time {...props} />);
|
2021-06-25 21:05:06 +03:00
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[{ date: parseDate('2020-05-05', 'yyyy-MM-dd') }, '1588636800000', '2020-05-05 00:00'],
|
|
|
|
[{ date: parseDate('2021-03-20', 'yyyy-MM-dd'), format: 'dd/MM/yyyy' }, '1616198400000', '20/03/2021'],
|
2021-06-25 21:05:06 +03:00
|
|
|
])('includes expected dateTime and format', (props, expectedDateTime, expectedFormatted) => {
|
2022-05-29 21:32:34 +03:00
|
|
|
const { container } = setUp(props);
|
2021-06-25 21:05:06 +03:00
|
|
|
|
2022-05-29 21:32:34 +03:00
|
|
|
expect(container.firstChild).toHaveAttribute('datetime', expectedDateTime);
|
|
|
|
expect(container.firstChild).toHaveTextContent(expectedFormatted);
|
2021-06-25 21:05:06 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders relative times when requested', () => {
|
2022-05-29 21:32:34 +03:00
|
|
|
const { container } = setUp({ date: new Date(), relative: true });
|
|
|
|
expect(container.firstChild).toHaveTextContent(' ago');
|
2021-06-25 21:05:06 +03:00
|
|
|
});
|
|
|
|
});
|