forked from Liquifact/Liquifact-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobals.reduced-motion.test.tsx
More file actions
161 lines (138 loc) · 7.42 KB
/
Copy pathglobals.reduced-motion.test.tsx
File metadata and controls
161 lines (138 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**
* Reduced-motion accessibility tests for issue #92.
*
* CSS animations are mocked in Jest/jsdom (moduleNameMapper maps *.css → style.js),
* so we assert on DOM structure and Tailwind class names rather than computed styles.
* The @media (prefers-reduced-motion: reduce) block in app/globals.css handles
* the actual animation suppression at the browser layer.
*
* Manual verification matrix (DevTools → Rendering → prefers-reduced-motion: reduce):
* ┌──────────────────────────┬──────────────────────────────────────────────────────┐
* │ Component │ Expected with motion OFF │
* ├──────────────────────────┼──────────────────────────────────────────────────────┤
* │ InvoiceListSkeleton │ Skeleton rows visible, opacity ~0.7, no shimmer │
* │ InvestLoading (page) │ All skeleton divs visible, no shimmer │
* │ InvoicesLoading (page) │ All skeleton divs visible, no shimmer │
* │ Spinner SVG │ SVG shape visible, no rotation │
* └──────────────────────────┴──────────────────────────────────────────────────────┘
*/
import React from "react";
import { render } from "@testing-library/react";
import { axe } from "jest-axe";
import InvoiceListSkeleton from "../components/InvoiceListSkeleton";
import InvestLoading from "./invest/loading";
import InvoicesLoading from "./invoices/loading";
// ---------------------------------------------------------------------------
// Inline Spinner — mirrors the implementation in UploadZone exactly.
// Uses role="img" + aria-label so screen readers announce
// the loading state directly from the SVG.
// ---------------------------------------------------------------------------
function Spinner({ className = "" }: { className?: string }) {
return (
<svg
className={`animate-spin -ml-1 mr-2 h-4 w-4 inline ${className}`}
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
role="img"
aria-label="Loading"
>
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
/>
</svg>
);
}
// ── InvoiceListSkeleton ─────────────────────────────────────────────────────
describe("InvoiceListSkeleton – reduced-motion", () => {
it("renders skeleton rows with animate-pulse class (CSS layer disables motion)", () => {
const { container } = render(<InvoiceListSkeleton rows={3} />);
const items = container.querySelectorAll("li");
expect(items.length).toBe(3);
items.forEach((item) => {
expect(item.className).toContain("animate-pulse");
});
});
it('keeps aria-busy="true" so screen readers announce loading state', () => {
const { container } = render(<InvoiceListSkeleton />);
expect(container.querySelector("ul")?.getAttribute("aria-busy")).toBe("true");
});
it("keeps aria-label on the list", () => {
const { container } = render(<InvoiceListSkeleton />);
expect(container.querySelector("ul")?.getAttribute("aria-label")).toBeTruthy();
});
it("skeleton rows remain in the DOM (visible without motion)", () => {
const { container } = render(<InvoiceListSkeleton rows={2} />);
expect(container.querySelectorAll("li").length).toBe(2);
});
it("passes axe accessibility check", async () => {
const { container } = render(<InvoiceListSkeleton />);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
});
// ── Spinner ─────────────────────────────────────────────────────────────────
describe("Spinner – reduced-motion", () => {
it("renders SVG with animate-spin class (CSS layer stops rotation)", () => {
const { container } = render(<Spinner />);
const svg = container.querySelector("svg");
expect(svg).toBeTruthy();
// SVG className is an SVGAnimatedString; baseVal holds the string value
const cls = svg?.className?.baseVal ?? svg?.getAttribute("class") ?? "";
expect(cls).toContain("animate-spin");
});
it("has role=img and aria-label so screen readers announce the loading state", () => {
const { container } = render(<Spinner />);
const svg = container.querySelector("svg");
expect(svg).toHaveAttribute("role", "img");
expect(svg).toHaveAttribute("aria-label", "Loading");
});
it("passes axe accessibility check", async () => {
const { container } = render(<Spinner />);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
});
// ── InvestLoading ────────────────────────────────────────────────────────────
describe("InvestLoading – reduced-motion", () => {
it("renders animate-pulse skeleton elements", () => {
const { container } = render(<InvestLoading />);
expect(container.querySelectorAll(".animate-pulse").length).toBeGreaterThan(0);
});
it('root element has aria-busy="true"', () => {
const { container } = render(<InvestLoading />);
expect(container.firstElementChild?.getAttribute("aria-busy")).toBe("true");
});
it("skeleton elements stay in DOM with motion disabled", () => {
const { container } = render(<InvestLoading />);
expect(container.querySelector("main")).toBeTruthy();
});
it("passes axe accessibility check", async () => {
const { container } = render(<InvestLoading />);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
});
// ── InvoicesLoading ──────────────────────────────────────────────────────────
describe("InvoicesLoading – reduced-motion", () => {
it("renders animate-pulse skeleton elements", () => {
const { container } = render(<InvoicesLoading />);
expect(container.querySelectorAll(".animate-pulse").length).toBeGreaterThan(0);
});
it('root element has aria-busy="true"', () => {
const { container } = render(<InvoicesLoading />);
expect(container.firstElementChild?.getAttribute("aria-busy")).toBe("true");
});
it("skeleton elements stay in DOM with motion disabled", () => {
const { container } = render(<InvoicesLoading />);
expect(container.querySelector("main")).toBeTruthy();
});
it("passes axe accessibility check", async () => {
const { container } = render(<InvoicesLoading />);
const results = await axe(container);
expect(results).toHaveNoViolations();
});
});