From c87c615b5866b8a8f361eeb0764bfdea85740e90 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Tue, 10 Oct 2023 19:37:51 +0200
Subject: refactor(components): replace Meta component with MetaList

It removes items complexity by allowing consumers to use any label/value
association. Translations should also be defined by the consumer.
Each item can now be configured separately (borders, layout...).
---
 .../meta-list/meta-item/meta-item.test.tsx         | 97 ++++++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 src/components/molecules/meta-list/meta-item/meta-item.test.tsx

(limited to 'src/components/molecules/meta-list/meta-item/meta-item.test.tsx')

diff --git a/src/components/molecules/meta-list/meta-item/meta-item.test.tsx b/src/components/molecules/meta-list/meta-item/meta-item.test.tsx
new file mode 100644
index 0000000..629c4b2
--- /dev/null
+++ b/src/components/molecules/meta-list/meta-item/meta-item.test.tsx
@@ -0,0 +1,97 @@
+import { describe, expect, it } from '@jest/globals';
+import { render, screen as rtlScreen } from '@testing-library/react';
+import { MetaItem } from './meta-item';
+
+describe('MetaItem', () => {
+  it('renders a label and a value', () => {
+    const label = 'iusto';
+    const value = 'autem';
+
+    render(
+      <dl>
+        <MetaItem label={label} value={value} />
+      </dl>
+    );
+
+    expect(rtlScreen.getByRole('term')).toHaveTextContent(label);
+    expect(rtlScreen.getByRole('definition')).toHaveTextContent(value);
+  });
+
+  it('can render a label with multiple values', () => {
+    const label = 'iusto';
+    const values = [
+      { id: 'autem', value: 'autem' },
+      { id: 'quisquam', value: 'aut' },
+      { id: 'molestias', value: 'voluptatem' },
+    ];
+
+    render(
+      <dl>
+        <MetaItem label={label} value={values} />
+      </dl>
+    );
+
+    expect(rtlScreen.getByRole('term')).toHaveTextContent(label);
+    expect(rtlScreen.getAllByRole('definition')).toHaveLength(values.length);
+  });
+
+  it('can render a centered group of label and values', () => {
+    const label = 'iusto';
+    const value = 'autem';
+
+    render(
+      <dl>
+        <MetaItem isCentered label={label} value={value} />
+      </dl>
+    );
+
+    expect(rtlScreen.getByRole('term').parentElement).toHaveClass(
+      'item--centered'
+    );
+  });
+
+  it('can render an inlined group of label and values', () => {
+    const label = 'iusto';
+    const value = 'autem';
+
+    render(
+      <dl>
+        <MetaItem isInline label={label} value={value} />
+      </dl>
+    );
+
+    expect(rtlScreen.getByRole('term').parentElement).toHaveClass(
+      'item--inlined'
+    );
+  });
+
+  it('can render a group of label and bordered values', () => {
+    const label = 'iusto';
+    const value = 'autem';
+
+    render(
+      <dl>
+        <MetaItem hasBorderedValues label={label} value={value} />
+      </dl>
+    );
+
+    expect(rtlScreen.getByRole('term').parentElement).toHaveClass(
+      'item--bordered-values'
+    );
+  });
+
+  it('can render a group of label and inlined values', () => {
+    const label = 'iusto';
+    const value = 'autem';
+
+    render(
+      <dl>
+        <MetaItem hasInlinedValues label={label} value={value} />
+      </dl>
+    );
+
+    expect(rtlScreen.getByRole('term').parentElement).toHaveClass(
+      'item--inlined-values'
+    );
+  });
+});
-- 
cgit v1.2.3

