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 { describe, expect, it, vi } from "vite-plus/test"; |
| 2 | import { userEvent } from "vite-plus/test/browser"; |
| 3 | |
| 4 | import { render, type Screen } from "../../../test/render"; |
| 5 | import { SecretInput } from "./SecretInput"; |
| 6 | |
| 7 | const input = (screen: Screen) => screen.container.querySelector("input")!; |
| 8 | |
| 9 | async function edit(screen: Screen, value: string) { |
| 10 | await userEvent.clear(input(screen)); |
| 11 | if (value) await userEvent.type(input(screen), value); |
| 12 | await userEvent.click(document.body); |
| 13 | } |
| 14 | |
| 15 | describe("SecretInput", () => { |
| 16 | it("preserves a configured secret on empty edits and commits a replacement", async () => { |
| 17 | const onCommit = vi.fn(); |
| 18 | await using screen = await render(<SecretInput configured value="" onCommit={onCommit} />); |
| 19 | expect(input(screen).type).toBe("password"); |
| 20 | |
| 21 | await userEvent.click(input(screen)); |
| 22 | await userEvent.click(document.body); |
| 23 | expect(onCommit).not.toHaveBeenCalled(); |
| 24 | |
| 25 | await edit(screen, "replacement"); |
| 26 | expect(onCommit).toHaveBeenCalledExactlyOnceWith("replacement"); |
| 27 | expect(input(screen).value).toBe(""); |
| 28 | }); |
| 29 | |
| 30 | it("keeps an in-progress replacement when settings refresh", async () => { |
| 31 | const onCommit = vi.fn(); |
| 32 | const ui = () => <SecretInput configured value="" onCommit={onCommit} />; |
| 33 | await using screen = await render(ui()); |
| 34 | |
| 35 | await userEvent.type(input(screen), "replacement"); |
| 36 | await screen.rerender(ui()); |
| 37 | expect(input(screen).value).toBe("replacement"); |
| 38 | |
| 39 | await userEvent.keyboard("{Enter}"); |
| 40 | expect(onCommit).toHaveBeenCalledExactlyOnceWith("replacement"); |
| 41 | }); |
| 42 | }); |