Skip to content

Commit 8a4d96a

Browse files
committed
test: wait for diagnostics install output subscription
1 parent 6ad96fd commit 8a4d96a

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

packages/web/src/features/diagnostics/index.test.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,14 @@ describe("DiagnosticsPage", () => {
388388
let installGetCalls = 0;
389389
let submitted = false;
390390
let subscriptionHandler: ((topic: string, payload: unknown) => void) | undefined;
391+
const subscribe = vi.fn(
392+
(_topics: string[], handler: (topic: string, payload: unknown) => void) => {
393+
subscriptionHandler = handler;
394+
return () => {
395+
subscriptionHandler = undefined;
396+
};
397+
}
398+
);
391399
const sendCommand = vi.fn(async (op: string, args?: Record<string, unknown>) => {
392400
if (op === "diagnostics.get" || op === "diagnostics.recheck") {
393401
diagnosticsCallCount += 1;
@@ -483,12 +491,7 @@ describe("DiagnosticsPage", () => {
483491
const store = createStoreWithClient(sendCommand);
484492
store.set(wsClientAtom, {
485493
sendCommand,
486-
subscribe: vi.fn((_topics: string[], handler: (topic: string, payload: unknown) => void) => {
487-
subscriptionHandler = handler;
488-
return () => {
489-
subscriptionHandler = undefined;
490-
};
491-
}),
494+
subscribe,
492495
} as never);
493496

494497
render(
@@ -506,6 +509,12 @@ describe("DiagnosticsPage", () => {
506509
fireEvent.click(screen.getByRole("button", { name: "Install Git" }));
507510
expect(await screen.findByText("Package manager: apt-get")).toBeInTheDocument();
508511
expect(screen.getByLabelText("Administrator password")).toHaveAttribute("type", "password");
512+
await waitFor(() => {
513+
expect(subscribe).toHaveBeenCalledWith(
514+
["systemDeps.install.job-1.output"],
515+
expect.any(Function)
516+
);
517+
});
509518

510519
act(() => {
511520
subscriptionHandler?.("systemDeps.install.job-1.output", {

0 commit comments

Comments
 (0)