Open History to see the last commit
1import type { ReactNode } from "react";
2import { act } from "react";
3import { createRoot } from "react-dom/client";
4import { expect, it, vi } from "vite-plus/test";
5
6const { Children, harness } = vi.hoisted(() => ({
7 Children: ({ children }: { children?: ReactNode }) => <>{children}</>,
8 harness: {
9 // The app-wide error slot other features (composer sends, branch refreshes) write to.
10 pendingConnectionError: null as string | null,
11 connectPress: vi.fn(),
12 },
13}));
14
15vi.mock("react-native", () => ({
16 View: Children,
17 Pressable: Children,
18 Linking: { openSettings: vi.fn() },
19 StyleSheet: { absoluteFill: {} },
20}));
21vi.mock("react-native-svg", () => ({
22 default: Children,
23 Defs: Children,
24 RadialGradient: Children,
25 Rect: () => null,
26 Stop: () => null,
27}));
28vi.mock("react-native-safe-area-context", () => ({ useSafeAreaInsets: () => ({ bottom: 0 }) }));
29vi.mock("@react-navigation/native", () => ({
30 StackActions: { replace: vi.fn() },
31 useIsFocused: () => true,
32 useNavigation: () => ({ canGoBack: () => true, goBack: vi.fn(), dispatch: vi.fn() }),
33 useRoute: () => ({ name: "ConnectionsNew" }),
34}));
35vi.mock("@effect/atom-react", () => ({ useAtomValue: () => null }));
36vi.mock("@clerk/expo", () => ({ useAuth: () => ({ isLoaded: false, isSignedIn: false }) }));
37vi.mock("expo-camera", () => ({
38 CameraView: () => null,
39 useCameraPermissions: () => [null, vi.fn()],
40}));
41vi.mock("expo-haptics", () => ({
42 notificationAsync: vi.fn(async () => {}),
43 NotificationFeedbackType: { Success: "success", Error: "error" },
44}));
45vi.mock("../../components/ui/ListRow", () => ({ ListRow: () => null }));
46vi.mock("../../components/ui/Dialog", () => ({ alert: vi.fn() }));
47vi.mock("../../components/ui/ScreenScrollView", () => ({ ScreenScrollView: Children }));
48vi.mock("../../components/ui/AppText", () => ({
49 AppText: ({ children }: { children?: ReactNode }) => <span>{children}</span>,
50 AppTextInput: () => null,
51}));
52vi.mock("../../components/ui/FrostedCutout", () => ({ FrostedCutout: () => null }));
53vi.mock("../../components/ui/AppSymbol", () => ({ SymbolView: () => null }));
54vi.mock("../../lib/useUniwindTheme", () => ({ useUniwindTheme: () => ({}) }));
55vi.mock("../settings/appearance/AppearancePreferencesProvider", () => ({
56 useAppearancePreferences: () => ({ themeAppearance: "dark" }),
57}));
58vi.mock("../settings/components/SettingsScreen", () => ({ SettingsScreen: Children }));
59vi.mock("../settings/settings-navigation", () => ({
60 leaveSettingsPage: vi.fn(),
61 openSettings: vi.fn(),
62}));
63vi.mock("../workspace/workspace-selection-store", () => ({ workspaceHasColumns: () => false }));
64vi.mock("../cloud/publicConfig", () => ({ hasCloudPublicConfig: () => false }));
65vi.mock("./CloudEnvironmentRows", () => ({ CloudEnvironmentRows: () => null }));
66vi.mock("./environmentSections", () => ({
67 splitEnvironmentSections: () => ({ connectedCloudEnvironments: [] }),
68}));
69vi.mock("./devAutoConnect", () => ({
70 autoConnectReport: () => ({ connecting: false, error: null }),
71 devAutoConnectAttemptAtom: {},
72}));
73vi.mock("../../state/use-remote-environment-registry", () => ({
74 setPendingConnectionError: (message: string | null) => {
75 harness.pendingConnectionError = message;
76 },
77 useRemoteConnections: () => ({
78 connectionPairingUrl: "",
79 connectedEnvironments: [],
80 pairingConnectionError: harness.pendingConnectionError,
81 onChangeConnectionPairingUrl: vi.fn(),
82 onConnectPress: harness.connectPress,
83 onSetEnvironmentEnabled: vi.fn(),
84 onRemoveEnvironmentPress: vi.fn(),
85 }),
86}));
87
88import { ConnectionsNewRouteScreen } from "./ConnectionsNewRouteScreen";
89
90it("does not show another feature's error as a pairing failure", () => {
91 (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
92 vi.stubGlobal("__DEV__", false);
93 harness.pendingConnectionError = "Could not send the message.";
94 const container = document.createElement("div");
95 const root = createRoot(container);
96 act(() => root.render(<ConnectionsNewRouteScreen route={{ params: undefined }} />));
97
98 expect(container.textContent).not.toContain("Could not send the message.");
99 expect(container.textContent).toContain("For machines on your local network or tailnet.");
100
101 act(() => root.unmount());
102 // Leaving the form must not wipe an error that belongs to another screen.
103 expect(harness.pendingConnectionError).toBe("Could not send the message.");
104});