Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

targetEnvironment.logic.test.ts

51 lines1.7 KB

1import { EnvironmentId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3​
4import { resolveOnboardingSetup } from "./targetEnvironment.logic";
5​
6describe("resolveOnboardingSetup", () => {
7 const computer = (id: string, phase: string) => ({
8 environmentId: EnvironmentId.make(id),
9 connection: { phase },
10 });
11 const local = computer("local", "connected");
12​
13 it("skips selected computers that will not connect on their own", () => {
14 const environments = [
15 local,
16 computer("switched-off", "available"),
17 computer("offline", "offline"),
18 computer("failing", "reconnecting"),
19 computer("old-client", "unsupported"),
20 ];
21 expect(
22 resolveOnboardingSetup(
23 environments,
24 new Set(environments.map((environment) => environment.environmentId)),
25 ),
26 ).toEqual({
27 ready: true,
28 environmentIds: [local.environmentId],
29 skippedIds: environments.slice(1).map((environment) => environment.environmentId),
30 });
31 });
32​
33 it("waits for a first connection attempt to settle", () => {
34 const connecting = computer("new", "connecting");
35 expect(
36 resolveOnboardingSetup(
37 [local, connecting],
38 new Set([local.environmentId, connecting.environmentId]),
39 ).ready,
40 ).toBe(false);
41 });
42​
43 // regression: #16887 onboarding Continue locked up on computers that won't connect
44 it("is not ready without a connected selection", () => {
45 expect(resolveOnboardingSetup([local], new Set()).ready).toBe(false);
46 expect(
47 resolveOnboardingSetup([computer("off", "available")], new Set([EnvironmentId.make("off")]))
48 .ready,
49 ).toBe(false);
50 });
51});