1import { beforeEach, describe, expect, it } from "vite-plus/test";
2
3import {
4 completeRelayClientInstallDialogClose,
5 finishRelayClientInstall,
6 readRelayClientInstallDialogState,
7 RelayClientInstallConfirmationConflictError,
8 reportRelayClientInstallProgress,
9 requestRelayClientInstallConfirmation,
10 resetRelayClientInstallDialogForTests,
11 respondToRelayClientInstallConfirmation,
12} from "./relayClientInstallDialog";
13
14describe("relay client install dialog coordinator", () => {
15 beforeEach(() => {
16 resetRelayClientInstallDialogForTests();
17 });
18
19 it("moves a confirmed installation through streamed progress stages", async () => {
20 const confirmation = requestRelayClientInstallConfirmation("2026.10.0");
21 expect(readRelayClientInstallDialogState()).toEqual({
22 status: "confirming",
23 version: "2026.10.0",
24 });
25
26 respondToRelayClientInstallConfirmation(true);
27 await expect(confirmation).resolves.toBe(true);
28 expect(readRelayClientInstallDialogState()).toEqual({
29 status: "installing",
30 version: "2026.10.0",
31 stage: "checking",
32 });
33
34 reportRelayClientInstallProgress({ type: "progress", stage: "downloading" });
35 expect(readRelayClientInstallDialogState()).toEqual({
36 status: "installing",
37 version: "2026.10.0",
38 stage: "downloading",
39 });
40
41 finishRelayClientInstall();
42 expect(readRelayClientInstallDialogState()).toEqual({
43 status: "closing",
44 view: {
45 status: "installing",
46 version: "2026.10.0",
47 stage: "downloading",
48 },
49 });
50
51 completeRelayClientInstallDialogClose();
52 expect(readRelayClientInstallDialogState()).toEqual({ status: "idle" });
53 });
54
55 it("returns to idle when installation is declined", async () => {
56 const confirmation = requestRelayClientInstallConfirmation("2026.10.0");
57 respondToRelayClientInstallConfirmation(false);
58
59 await expect(confirmation).resolves.toBe(false);
60 expect(readRelayClientInstallDialogState()).toEqual({
61 status: "closing",
62 view: {
63 status: "confirming",
64 version: "2026.10.0",
65 },
66 });
67
68 completeRelayClientInstallDialogClose();
69 expect(readRelayClientInstallDialogState()).toEqual({ status: "idle" });
70 });
71
72 it("rejects concurrent confirmation with the active install state", async () => {
73 const confirmation = requestRelayClientInstallConfirmation("2026.10.0");
74 respondToRelayClientInstallConfirmation(true);
75 await expect(confirmation).resolves.toBe(true);
76 reportRelayClientInstallProgress({ type: "progress", stage: "downloading" });
77
78 const error = await requestRelayClientInstallConfirmation("2026.11.0").then(
79 () => undefined,
80 (cause: unknown) => cause,
81 );
82
83 expect(error).toBeInstanceOf(RelayClientInstallConfirmationConflictError);
84 expect(error).toMatchObject({
85 requestedVersion: "2026.11.0",
86 activeVersion: "2026.10.0",
87 activeDialogStatus: "installing",
88 activeInstallStage: "downloading",
89 });
90 expect(error).not.toHaveProperty("cause");
91 expect((error as Error).message).toBe(
92 "Cannot confirm relay client installation 2026.11.0; installation 2026.10.0 has dialog status installing.",
93 );
94 });
95});