From e586c951c14d1bac4cabc1f582aca4d12045f179 Mon Sep 17 00:00:00 2001
From: Joe Banks <joe@jb3.dev>
Date: Tue, 9 Jul 2024 21:55:42 +0100
Subject: Add new test suite for testing authorization splash

---
 src/tests/components/AuthorizationSplash.test.tsx | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 src/tests/components/AuthorizationSplash.test.tsx

(limited to 'src/tests/components/AuthorizationSplash.test.tsx')

diff --git a/src/tests/components/AuthorizationSplash.test.tsx b/src/tests/components/AuthorizationSplash.test.tsx
new file mode 100644
index 0000000..7f44ba4
--- /dev/null
+++ b/src/tests/components/AuthorizationSplash.test.tsx
@@ -0,0 +1,62 @@
+/** @jsx jsx */
+import { jsx } from "@emotion/react";
+import { renderWithProviders } from "../utils";
+import AuthorizationSplash from "../../components/AuthorizationSplash";
+import { finishAuthorizing } from "../../slices/authorization";
+import { act } from "@testing-library/react";
+
+test("authorization splash is hidden when not authorizing", () => {
+    const { container } = renderWithProviders(<AuthorizationSplash />);
+    const splash = container.firstElementChild;
+
+    expect(splash).not.toBe(null);
+
+    if (splash) {
+        const style = window.getComputedStyle(splash);
+        expect(style.opacity).toBe("0");
+    }
+});
+
+test("authorization splash is visible when authorizing state is set", () => {
+    const { container } = renderWithProviders(<AuthorizationSplash />, {
+        preloadedState: {
+            authorization: {
+                authorizing: true
+            }
+        }
+    });
+    const splash = container.firstElementChild;
+
+    expect(splash).not.toBe(null);
+
+    if (splash) {
+        const style = window.getComputedStyle(splash);
+        expect(style.opacity).toBe("1");
+    }
+});
+
+test("test state transitions when authorization completes", () => {
+    const { store, container } = renderWithProviders(<AuthorizationSplash />, {
+        preloadedState: {
+            authorization: {
+                authorizing: true
+            }
+        }
+    });
+
+    const splash = container.firstElementChild;
+
+    expect(splash).not.toBe(null);
+
+    if (splash) {
+        let style = window.getComputedStyle(splash);
+        expect(style.opacity).toBe("1");
+
+        act(() => {
+            store.dispatch(finishAuthorizing());
+        });
+
+        style = window.getComputedStyle(splash);
+        expect(style.opacity).toBe("0");
+    }
+});
-- 
cgit v1.2.3

