forked from Liquifact/Liquifact-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilters.a11y.test.tsx
More file actions
61 lines (51 loc) · 2.21 KB
/
Copy pathfilters.a11y.test.tsx
File metadata and controls
61 lines (51 loc) · 2.21 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
import React from "react";
import { render, screen } from "@testing-library/react";
import { axe, toHaveNoViolations } from "jest-axe";
import { InvestMarketplace } from "./page";
import { WalletProvider } from "@/components/WalletProvider";
import { ToastProvider } from "@/components/ToastProvider";
expect.extend(toHaveNoViolations);
// Mock next/navigation hooks to prevent Next.js router errors
jest.mock("next/navigation", () => ({
usePathname: () => "/invest",
useSearchParams: () => new URLSearchParams(),
useRouter: () => ({
replace: jest.fn(),
}),
}));
describe("InvestMarketplace - Coming Soon Filters A11y", () => {
const mockLoadInvoices = jest.fn(() => Promise.resolve([]));
it("should render the filters wrapped in a fieldset with coming soon semantics", () => {
render(
<ToastProvider>
<WalletProvider>
<InvestMarketplace loadInvoices={mockLoadInvoices} />
</WalletProvider>
</ToastProvider>
);
// Check for the fieldset acting as the accessible wrapper
const fieldset = screen.getByRole("group", { name: /Marketplace Filters/i });
expect(fieldset).toBeInTheDocument();
// Ensure aria-disabled is present and set to true
expect(fieldset).toHaveAttribute("aria-disabled", "true");
// Ensure aria-describedby connects the fieldset to the Soon badge
const descriptionId = fieldset.getAttribute("aria-describedby");
expect(descriptionId).toBe("filters-coming-soon");
// Ensure the description element actually exists and has the correct text
const descriptionElement = document.getElementById(descriptionId);
expect(descriptionElement).toBeInTheDocument();
expect(descriptionElement).toHaveTextContent(/Soon:/i);
});
it("should have no accessibility violations with the coming soon semantics applied", async () => {
const { container } = render(
<ToastProvider>
<WalletProvider>
<InvestMarketplace loadInvoices={mockLoadInvoices} />
</WalletProvider>
</ToastProvider>
);
// Run jest-axe to ensure our 'coming soon' opacity and wrapper do not violate contrast or structural rules
const results = await axe(container);
expect(results).toHaveNoViolations();
});
});