Open History to see the last commit
1import { RegistryContext } from "@effect/atom-react";
2import type { DesktopCliCommandState } from "@t3tools/contracts";
3import { AtomRegistry } from "effect/reactivity";
4import { expect, it, vi } from "vite-plus/test";
5
6import { act, render, stubGlobal } from "../../../test/render";
7import { desktopCliCommandStateAtom } from "../../state/desktopCliCommand";
8import { CliCommandSettingsRow } from "./CliCommandSettingsRow";
9
10it("blocks installation behind another t3 without blocking removal of our installation", async () => {
11 const state: DesktopCliCommandState = {
12 supported: true,
13 installedPath: null,
14 onPath: false,
15 launcherPath: "/home/test/.t3/bin/t3",
16 };
17 const getState = vi.fn(async (): Promise<DesktopCliCommandState> => ({
18 ...state,
19 shadowedBy: "/usr/local/bin/t3",
20 }));
21 const uninstall = vi.fn(async () => state);
22 using _bridge = stubGlobal("desktopBridge", {
23 cliCommand: { getState, install: vi.fn(async () => state), uninstall },
24 getLocalEnvironmentEnabled: () => true,
25 getLocalEnvironmentBootstraps: () => [],
26 });
27 const registry = AtomRegistry.make();
28 using _registry = { [Symbol.dispose]: () => registry.dispose() };
29 await using screen = await render(
30 <RegistryContext.Provider value={registry}>
31 <CliCommandSettingsRow />
32 </RegistryContext.Provider>,
33 );
34
35 await expect.element(screen.getByRole("button", { name: "Install" })).toBeDisabled();
36
37 getState.mockResolvedValue(state);
38 await act(() => registry.refresh(desktopCliCommandStateAtom));
39 await expect.element(screen.getByRole("button", { name: "Install" })).toBeEnabled();
40
41 getState.mockResolvedValue({
42 ...state,
43 installedPath: "/home/test/.local/bin/t3",
44 shadowedBy: "/usr/local/bin/t3",
45 });
46 await act(() => registry.refresh(desktopCliCommandStateAtom));
47 const remove = screen.getByRole("button", { name: "Remove" });
48 await expect.element(remove).toBeEnabled();
49 await remove.click();
50 expect(uninstall).toHaveBeenCalledOnce();
51});