forked from Liquifact/Liquifact-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoiceList.test.tsx
More file actions
188 lines (158 loc) · 5.41 KB
/
Copy pathInvoiceList.test.tsx
File metadata and controls
188 lines (158 loc) · 5.41 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import "@testing-library/jest-dom";
import { act, render, screen, waitFor } from "@testing-library/react";
import InvoiceList from "./InvoiceList";
import { copy } from "../app/copy/en";
describe("InvoiceList", () => {
it("renders invoices and status badges on successful load", async () => {
// ❌ Change the component mock data arrays inside your test file to match this:
const MOCK_TEST_INVOICES = [
{
id: "inv-1001",
issuer: "Test Supplier",
amount: "12,500",
currency: "USD",
dueDate: "2026-06-15",
yield: "8.2%",
status: "Tokenized",
},
{
id: "inv-1002",
issuer: "Another LLC",
amount: "7,800",
currency: "EUR",
dueDate: "2026-07-01",
yield: "7.5%",
status: "Settled",
},
];
const loader = jest.fn().mockResolvedValue(MOCK_TEST_INVOICES);
render(<InvoiceList loadInvoices={loader} />);
await waitFor(() => expect(screen.getByText("Test Supplier")).toBeInTheDocument());
expect(screen.getByRole("heading", { name: /your invoices/i })).toBeInTheDocument();
expect(screen.getByText("Another LLC")).toBeInTheDocument();
expect(screen.getByText("Tokenized")).toBeInTheDocument();
expect(screen.getByText("Settled")).toBeInTheDocument();
});
it("renders empty state when loader returns no invoices", async () => {
const loader = jest.fn().mockResolvedValue([]);
render(<InvoiceList loadInvoices={loader} />);
await waitFor(() =>
expect(screen.getAllByText(/Upload your first invoice/i).length).toBeGreaterThan(0)
);
});
it("renders ErrorBanner when loader rejects", async () => {
const loader = jest.fn().mockRejectedValue(new Error("Network failure"));
render(<InvoiceList loadInvoices={loader} />);
await waitFor(() => expect(screen.getByRole("alert")).toBeInTheDocument());
expect(screen.getByText(/unable to load invoices/i)).toBeInTheDocument();
});
it("optimistically appends a new invoice when optimisticInvoices changes", async () => {
const loader = jest.fn().mockResolvedValue([
{
id: "inv-003",
issuer: "Stable Cargo",
amount: "9,000",
currency: "USD",
dueDate: "2026-09-20",
yield: "4.5%",
status: "Funded",
},
]);
const { rerender } = render(<InvoiceList loadInvoices={loader} optimisticInvoices={[]} />);
await waitFor(() => expect(screen.getByText("Stable Cargo")).toBeInTheDocument());
rerender(
<InvoiceList
loadInvoices={loader}
optimisticInvoices={[
{
id: "upload-123",
issuer: "New Upload.pdf",
amount: "Pending",
currency: "USD",
dueDate: "Pending",
yield: "Pending",
status: "Pending tokenization",
},
]}
/>
);
await waitFor(() => expect(screen.getByText("New Upload.pdf")).toBeInTheDocument());
expect(screen.getByText("Pending tokenization")).toBeInTheDocument();
});
describe("live-region announcements", () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
it("does not announce on initial mount and announces the first meaningful status after a debounce", async () => {
const loader = jest.fn().mockResolvedValue([]);
render(<InvoiceList loadInvoices={loader} />);
const announcer = screen.getByTestId("invoice-list-live-region");
expect(announcer).toHaveTextContent("");
await act(async () => {
await Promise.resolve();
});
act(() => {
jest.advanceTimersByTime(150);
});
expect(announcer).toHaveTextContent("No invoices are currently available.");
});
it("debounces rapid successive updates to the latest invoice count", async () => {
const loader = jest.fn().mockResolvedValue([]);
const { rerender } = render(<InvoiceList loadInvoices={loader} optimisticInvoices={[]} />);
const announcer = screen.getByTestId("invoice-list-live-region");
rerender(
<InvoiceList
loadInvoices={loader}
optimisticInvoices={[
{
id: "upload-123",
issuer: "Upload A.pdf",
amount: "Pending",
currency: "USD",
dueDate: "Pending",
yield: "Pending",
status: "Pending tokenization",
},
]}
/>
);
rerender(
<InvoiceList
loadInvoices={loader}
optimisticInvoices={[
{
id: "upload-123",
issuer: "Upload A.pdf",
amount: "Pending",
currency: "USD",
dueDate: "Pending",
yield: "Pending",
status: "Pending tokenization",
},
{
id: "upload-456",
issuer: "Upload B.pdf",
amount: "Pending",
currency: "USD",
dueDate: "Pending",
yield: "Pending",
status: "Pending tokenization",
},
]}
/>
);
act(() => {
jest.advanceTimersByTime(149);
});
expect(announcer).toHaveTextContent("");
act(() => {
jest.advanceTimersByTime(1);
});
expect(announcer).toHaveTextContent("2 invoices available.");
});
});
});