feat(parsers+api+ui+db): 999 ACK transaction set end-to-end (SP3 P3)

This commit is contained in:
Tyler
2026-06-20 08:03:37 -06:00
parent 7a20f732f2
commit fb2a98fc7a
24 changed files with 2618 additions and 1 deletions
+90
View File
@@ -0,0 +1,90 @@
// @vitest-environment happy-dom
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT =
true;
import React, { act } from "react";
import { createRoot, type Root } from "react-dom/client";
import { describe, expect, it, vi, beforeEach } from "vitest";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Acks } from "./Acks";
import { api } from "@/lib/api";
vi.mock("@/lib/api", () => ({
api: {
isConfigured: true,
listAcks: vi.fn(),
getAck: vi.fn(),
},
}));
function renderIntoContainer(element: React.ReactElement): {
container: HTMLDivElement;
unmount: () => void;
} {
const container = document.createElement("div");
document.body.appendChild(container);
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const root: Root = createRoot(container);
act(() => {
root.render(
React.createElement(QueryClientProvider, { client: qc }, element),
);
});
return {
container,
unmount: () => {
act(() => root.unmount());
container.remove();
},
};
}
async function waitForText(text: string, timeoutMs = 2000): Promise<void> {
const start = Date.now();
while (!document.body.textContent?.includes(text)) {
if (Date.now() - start > timeoutMs) {
throw new Error(`waitForText: "${text}" did not appear within ${timeoutMs}ms`);
}
await act(async () => {
await Promise.resolve();
});
}
}
describe("Acks", () => {
beforeEach(() => {
vi.clearAllMocks();
});
it("renders a single ack row with counts and ack code", async () => {
(api.listAcks as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
items: [
{
id: 42,
sourceBatchId: "b-uuid-1",
acceptedCount: 3,
rejectedCount: 1,
receivedCount: 4,
ackCode: "P",
parsedAt: "2026-06-20T12:00:00Z",
},
],
total: 1,
returned: 1,
has_more: false,
});
const { unmount } = renderIntoContainer(React.createElement(Acks));
await waitForText("42");
// The row's ack code badge must be visible.
expect(document.body.textContent).toContain("P");
// Counts must be visible (3 accepted, 1 rejected, 4 received).
expect(document.body.textContent).toContain("3");
expect(document.body.textContent).toContain("1");
expect(document.body.textContent).toContain("4");
// The source batch id must be visible.
expect(document.body.textContent).toContain("b-uuid-1");
unmount();
});
});