-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathErrorNotificationBar.test.tsx
More file actions
88 lines (75 loc) · 3.05 KB
/
ErrorNotificationBar.test.tsx
File metadata and controls
88 lines (75 loc) · 3.05 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
import type { ServerProviderStatus } from "@okcode/contracts";
import type { ComponentProps, ReactElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { act, create, type ReactTestRenderer } from "react-test-renderer";
import { afterEach, describe, expect, it, vi } from "vitest";
import { ErrorNotificationBar } from "./ErrorNotificationBar";
function makeProviderStatus(overrides: Partial<ServerProviderStatus> = {}): ServerProviderStatus {
return {
provider: "codex",
status: "warning",
available: true,
authStatus: "authenticated",
checkedAt: "2026-04-10T12:00:00.000Z",
message: "Provider is checking state.",
...overrides,
};
}
const THREAD_ERROR =
"Git command failed in GitCore.createWorktree: OPENAI_API_KEY=sk-proj-secret (/repo) - Base branch 'main' does not resolve to a commit yet.";
function renderBar(
overrides: Partial<ComponentProps<typeof ErrorNotificationBar>> = {},
): ReactElement {
const { onDismissThreadError, transportState, ...restOverrides } = overrides;
return (
<ErrorNotificationBar
threadError={THREAD_ERROR}
showAuthFailuresAsErrors
showNotificationDetails={false}
includeDiagnosticsTipsInCopy={true}
providerStatus={makeProviderStatus()}
isMobileCompanion={false}
{...restOverrides}
{...(onDismissThreadError ? { onDismissThreadError } : {})}
{...(transportState ? { transportState } : {})}
/>
);
}
afterEach(() => {
vi.restoreAllMocks();
});
describe("ErrorNotificationBar", () => {
it("keeps raw error text out of the collapsed bar and shows the aggregate count", () => {
const markup = renderToStaticMarkup(renderBar());
expect(markup).toContain("Show 2 notifications");
expect(markup).not.toContain("OPENAI_API_KEY=sk-proj-secret");
expect(markup).not.toContain("Base branch 'main' does not resolve to a commit yet.");
});
it("expands to show redacted error text and diagnostics copy", async () => {
let renderer: ReactTestRenderer | null = null;
await act(async () => {
renderer = create(renderBar());
});
const root = renderer!.root;
const toggle = root.findByProps({ "aria-label": "Show 2 notifications" });
await act(async () => {
toggle.props.onClick();
});
expect(root.findByProps({ "aria-label": "Hide 2 notifications" })).toBeTruthy();
expect(root.findByProps({ "aria-label": "Copy diagnostics" })).toBeTruthy();
expect(JSON.stringify(renderer!.toJSON())).toContain("Worktree thread could not start");
expect(JSON.stringify(renderer!.toJSON())).toContain(
"Base branch 'main' does not resolve to a commit yet.",
);
});
it("starts expanded when notification details are enabled", () => {
const markup = renderToStaticMarkup(
renderBar({
showNotificationDetails: true,
}),
);
expect(markup).toContain("Hide 2 notifications");
expect(markup).toContain("Worktree thread could not start");
expect(markup).toContain("Base branch 'main' does not resolve to a commit yet.");
});
});