From 00f147a7a687d5772bcc538bc606cfff972178cd Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Thu, 12 Oct 2023 17:24:13 +0200
Subject: 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.
---
 src/components/atoms/layout/time/time.test.tsx | 39 ++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 src/components/atoms/layout/time/time.test.tsx

(limited to 'src/components/atoms/layout/time/time.test.tsx')

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)
+    );
+  });
+});
-- 
cgit v1.2.3

