Skip to content

Commit 4fb6931

Browse files
committed
test(web): assert the refreshed endpoint list reaches the Connections snapshot
1 parent b8fe36e commit 4fb6931

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎apps/web/src/state/desktopNetworkAccess.test.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ const serverExposureState: DesktopServerExposureState = {
1515
};
1616

1717
const advertisedEndpoints: ReadonlyArray<AdvertisedEndpoint> = [];
18+
const tailscaleEndpoint: AdvertisedEndpoint = {
19+
id: "tailscale-ip:37737",
20+
label: "Tailscale IP",
21+
provider: { id: "tailscale", label: "Tailscale", kind: "private-network", isAddon: true },
22+
httpBaseUrl: "http://100.64.0.10:37737",
23+
wsBaseUrl: "ws://100.64.0.10:37737",
24+
reachability: "private-network",
25+
compatibility: { hostedHttpsApp: "unknown", desktopApp: "compatible" },
26+
source: "desktop-addon",
27+
status: "available",
28+
};
1829
const serverExposureLoadCause = new Error("exposure failed");
1930
const advertisedEndpointsLoadCause = new Error("endpoints failed");
2031

@@ -55,7 +66,11 @@ describe("desktopNetworkAccessState", () => {
5566
vi.useFakeTimers({ toFake: ["Date"] });
5667
try {
5768
const getServerExposureState = vi.fn(async () => serverExposureState);
58-
const getAdvertisedEndpoints = vi.fn(async () => advertisedEndpoints);
69+
// A Tailscale address appears after the first load.
70+
const getAdvertisedEndpoints = vi
71+
.fn<() => Promise<ReadonlyArray<AdvertisedEndpoint>>>()
72+
.mockResolvedValueOnce(advertisedEndpoints)
73+
.mockResolvedValue([tailscaleEndpoint]);
5974
const atom = createDesktopNetworkAccessStateAtom(() => ({
6075
getAdvertisedEndpoints,
6176
getServerExposureState,
@@ -84,6 +99,12 @@ describe("desktopNetworkAccessState", () => {
8499
await vi.waitFor(() => {
85100
expect(getServerExposureState).toHaveBeenCalledTimes(2);
86101
expect(getAdvertisedEndpoints).toHaveBeenCalledTimes(2);
102+
expect(AsyncResult.value(registry.get(atom))).toEqual(
103+
expect.objectContaining({
104+
_tag: "Some",
105+
value: { advertisedEndpoints: [tailscaleEndpoint], serverExposureState },
106+
}),
107+
);
87108
});
88109

89110
remount();

0 commit comments

Comments
 (0)