From 81b1e0e05919eb368a66aef47adcf7738af76f29 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Fri, 29 Sep 2023 11:47:06 +0200
Subject: refactor(components): rewrite Spinner component

* Message should be set as children
* Default message is no longer available (depending on use case, the
consumer might prefer aria-label instead)
* It is now possible to define the message position
---
 .../atoms/loaders/spinner/spinner.test.tsx         | 53 ++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 src/components/atoms/loaders/spinner/spinner.test.tsx

(limited to 'src/components/atoms/loaders/spinner/spinner.test.tsx')

diff --git a/src/components/atoms/loaders/spinner/spinner.test.tsx b/src/components/atoms/loaders/spinner/spinner.test.tsx
new file mode 100644
index 0000000..733648b
--- /dev/null
+++ b/src/components/atoms/loaders/spinner/spinner.test.tsx
@@ -0,0 +1,53 @@
+import { describe, expect, it } from '@jest/globals';
+import { render, screen as rtlScreen } from '@testing-library/react';
+import { Spinner } from './spinner';
+
+describe('Spinner', () => {
+  it('renders a spinner', () => {
+    const { container } = render(<Spinner />);
+    expect(container).toBeInTheDocument();
+  });
+
+  it('can render a spinner with a custom message', () => {
+    const customMsg = 'Submitting';
+
+    render(<Spinner>{customMsg}</Spinner>);
+    expect(rtlScreen.getByText(customMsg)).toBeInTheDocument();
+  });
+
+  it('can render a spinner with a custom message at the bottom', () => {
+    const customMsg = 'necessitatibus';
+
+    render(<Spinner position="bottom">{customMsg}</Spinner>);
+    expect(rtlScreen.getByText(customMsg).parentElement).toHaveClass(
+      'wrapper--bottom'
+    );
+  });
+
+  it('can render a spinner with a custom message on the left', () => {
+    const customMsg = 'eos';
+
+    render(<Spinner position="left">{customMsg}</Spinner>);
+    expect(rtlScreen.getByText(customMsg).parentElement).toHaveClass(
+      'wrapper--left'
+    );
+  });
+
+  it('can render a spinner with a custom message on the right', () => {
+    const customMsg = 'neque';
+
+    render(<Spinner position="right">{customMsg}</Spinner>);
+    expect(rtlScreen.getByText(customMsg).parentElement).toHaveClass(
+      'wrapper--right'
+    );
+  });
+
+  it('can render a spinner with a custom message on the top', () => {
+    const customMsg = 'vero';
+
+    render(<Spinner position="top">{customMsg}</Spinner>);
+    expect(rtlScreen.getByText(customMsg).parentElement).toHaveClass(
+      'wrapper--top'
+    );
+  });
+});
-- 
cgit v1.2.3

