-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPilotDiagnosticsSection.test.tsx
More file actions
70 lines (59 loc) · 1.75 KB
/
PilotDiagnosticsSection.test.tsx
File metadata and controls
70 lines (59 loc) · 1.75 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
// @vitest-environment jsdom
import { cleanup, render, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { PilotDiagnosticsSection } from "./PilotDiagnosticsSection";
const invokeMock = vi.fn();
vi.mock("@tauri-apps/api/core", () => ({
invoke: (...args: unknown[]) => invokeMock(...args),
}));
vi.mock("../Pilot", () => ({
PilotDashboard: ({
pilotLoggingEnabled,
}: {
pilotLoggingEnabled: boolean;
}) => (
<div data-testid="pilot-dashboard">
enabled:{String(pilotLoggingEnabled)}
</div>
),
PilotQueryTester: ({
pilotLoggingEnabled,
}: {
pilotLoggingEnabled: boolean;
}) => (
<div data-testid="pilot-query-tester">
enabled:{String(pilotLoggingEnabled)}
</div>
),
}));
describe("PilotDiagnosticsSection", () => {
beforeEach(() => {
invokeMock.mockReset();
});
afterEach(() => cleanup());
it("loads the pilot logging policy and passes enabled=true to children", async () => {
invokeMock.mockResolvedValue({
enabled: true,
retention_days: 14,
max_rows: 500,
});
render(<PilotDiagnosticsSection />);
await waitFor(() => {
expect(invokeMock).toHaveBeenCalledWith("get_pilot_logging_policy");
});
await waitFor(() => {
expect(screen.getByTestId("pilot-query-tester").textContent).toContain(
"enabled:true",
);
});
});
it("falls back to a disabled policy when the invoke call rejects", async () => {
invokeMock.mockRejectedValue(new Error("backend down"));
render(<PilotDiagnosticsSection />);
await waitFor(() => {
expect(screen.getByTestId("pilot-dashboard").textContent).toContain(
"enabled:false",
);
});
});
});