The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { EnvironmentId } from "@t3tools/contracts"; |
| 2 | import * as Cause from "effect/Cause"; |
| 3 | import { AsyncResult } from "effect/reactivity"; |
| 4 | import { expect, it } from "vite-plus/test"; |
| 5 | import { page, userEvent } from "vite-plus/test/browser"; |
| 6 | |
| 7 | import { act, render } from "../../test/render"; |
| 8 | import ProjectScriptsControl, { type ProjectScriptActionResult } from "./ProjectScriptsControl"; |
| 9 | |
| 10 | it.each(["edit", "dismiss", "newer import fails first"] as const)( |
| 11 | "keeps a failed import from replacing a newer action after %s", |
| 12 | async (nextAction) => { |
| 13 | const older = Promise.withResolvers<ProjectScriptActionResult>(); |
| 14 | const newer = Promise.withResolvers<ProjectScriptActionResult>(); |
| 15 | await using screen = await render( |
| 16 | <ProjectScriptsControl |
| 17 | environmentId={EnvironmentId.make("test")} |
| 18 | displayMode="panel" |
| 19 | scripts={[ |
| 20 | { |
| 21 | id: "local-check", |
| 22 | name: "Local check", |
| 23 | command: "echo local", |
| 24 | icon: "play", |
| 25 | runOnWorktreeCreate: false, |
| 26 | }, |
| 27 | ]} |
| 28 | fileScripts={[ |
| 29 | { name: "Shared build", command: "echo build" }, |
| 30 | { name: "Shared lint", command: "echo lint" }, |
| 31 | ]} |
| 32 | onRunScript={() => {}} |
| 33 | onAddScript={({ name }) => (name === "Shared build" ? older.promise : newer.promise)} |
| 34 | onUpdateScript={async () => AsyncResult.success(undefined)} |
| 35 | onDeleteScript={async () => AsyncResult.success(undefined)} |
| 36 | />, |
| 37 | ); |
| 38 | |
| 39 | const actions = screen.getByRole("button", { name: "Script actions" }); |
| 40 | const dialog = page.getByRole("dialog"); |
| 41 | const name = dialog.getByRole("textbox", { name: "Name" }); |
| 42 | const failure = AsyncResult.failure<void, unknown>( |
| 43 | Cause.fail(new Error("Settings write failed")), |
| 44 | ); |
| 45 | |
| 46 | await actions.click(); |
| 47 | await page.getByRole("menuitem", { name: /Shared build/ }).click(); |
| 48 | await actions.click(); |
| 49 | |
| 50 | switch (nextAction) { |
| 51 | case "edit": |
| 52 | await page.getByRole("button", { name: "Edit Local check" }).click(); |
| 53 | await act(async () => older.resolve(failure)); |
| 54 | expect(name.query()).toHaveProperty("value", "Local check"); |
| 55 | break; |
| 56 | case "dismiss": |
| 57 | await page.getByRole("menuitem", { name: "Add project script" }).click(); |
| 58 | await expect.element(dialog).toBeVisible(); |
| 59 | await userEvent.keyboard("{Escape}"); |
| 60 | await expect.element(dialog).not.toBeInTheDocument(); |
| 61 | await act(async () => older.resolve(failure)); |
| 62 | expect(dialog.query() === null).toBe(true); |
| 63 | break; |
| 64 | case "newer import fails first": |
| 65 | await page.getByRole("menuitem", { name: /Shared lint/ }).click(); |
| 66 | await act(async () => newer.resolve(failure)); |
| 67 | await act(async () => older.resolve(failure)); |
| 68 | expect(name.query()).toHaveProperty("value", "Shared lint"); |
| 69 | break; |
| 70 | } |
| 71 | }, |
| 72 | ); |