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 } from "vite-plus/test"; |
| 2 | import type { BrowserImportSource } from "@t3tools/contracts"; |
| 3 | |
| 4 | import { |
| 5 | initialWizardStep, |
| 6 | initialTargetSelection, |
| 7 | refreshedSourceProfileDirectory, |
| 8 | resolveWizardTarget, |
| 9 | } from "./browserImportWizard.logic"; |
| 10 | |
| 11 | describe("wizard target selection", () => { |
| 12 | it("treats an existing profile whose id is new as an existing target", () => { |
| 13 | const profiles = [{ id: "new", name: "Existing new" }]; |
| 14 | const selection = initialTargetSelection(false, profiles); |
| 15 | |
| 16 | expect(selection).toEqual({ kind: "existing", profileId: "new" }); |
| 17 | expect(resolveWizardTarget(selection, "generated", profiles)).toEqual({ |
| 18 | kind: "existing", |
| 19 | profileId: "new", |
| 20 | name: "Existing new", |
| 21 | }); |
| 22 | }); |
| 23 | |
| 24 | it("rejects an existing target that is no longer listed", () => { |
| 25 | expect( |
| 26 | resolveWizardTarget({ kind: "existing", profileId: "removed" }, "generated", [ |
| 27 | { id: "default", name: "Default" }, |
| 28 | ]), |
| 29 | ).toBeUndefined(); |
| 30 | }); |
| 31 | }); |
| 32 | |
| 33 | const source = (over: Partial<BrowserImportSource> = {}): BrowserImportSource => ({ |
| 34 | id: "helium", |
| 35 | name: "Helium", |
| 36 | profiles: [{ directory: "Default", name: "You" }], |
| 37 | ...over, |
| 38 | }); |
| 39 | |
| 40 | describe("initialWizardStep", () => { |
| 41 | it("handles source availability before checking its profiles", () => { |
| 42 | expect( |
| 43 | initialWizardStep(source({ profiles: [], unavailable: "needsKeychainApproval" })), |
| 44 | ).toEqual({ step: "blocked", reason: "needsKeychainApproval" }); |
| 45 | }); |
| 46 | }); |
| 47 | |
| 48 | describe("refreshedSourceProfileDirectory", () => { |
| 49 | const refreshed = source({ |
| 50 | profiles: [ |
| 51 | { directory: "Default", name: "Personal" }, |
| 52 | { directory: "Profile 2", name: "Work" }, |
| 53 | ], |
| 54 | }); |
| 55 | |
| 56 | it("preserves a selected non-first profile after the browser quits", () => { |
| 57 | expect(refreshedSourceProfileDirectory("Profile 2", refreshed)).toBe("Profile 2"); |
| 58 | }); |
| 59 | |
| 60 | it("falls back only when the old profile vanished and clears an empty result", () => { |
| 61 | expect(refreshedSourceProfileDirectory("Removed", refreshed)).toBe("Default"); |
| 62 | expect(refreshedSourceProfileDirectory("Removed", source({ profiles: [] }))).toBe(""); |
| 63 | }); |
| 64 | }); |