1import { parseNewThreadLink } from "@t3tools/shared/promptLinks";
2import { describe, expect, it } from "vite-plus/test";
3
4import {
5 promptLinkSearchFromParams,
6 stepPendingPromptLink,
7 withoutPromptLinkParams,
8} from "./prompt-link-model";
9
10describe("promptLinkSearchFromParams", () => {
11 it("round-trips decoded route params into the shared parser", () => {
12 const search = promptLinkSearchFromParams({
13 prompt: "Fix the bug & add tests = done?",
14 repo: ["pingdotgg/t3code", "ignored/second"],
15 provider: "codex",
16 screen: "NewTask",
17 });
18
19 expect(parseNewThreadLink(search ?? "")).toEqual({
20 ok: true,
21 value: {
22 kind: "new",
23 prompt: { text: "Fix the bug & add tests = done?", hiddenCharacters: 0 },
24 repository: { owner: "pingdotgg", name: "t3code" },
25 provider: "codex",
26 model: null,
27 },
28 });
29 });
30});
31
32describe("stepPendingPromptLink", () => {
33 const waiting = "repo=t3tools%2Ft3code";
34
35 it("drops a link whose screen is missing from the first state after it was parsed", () => {
36 expect(stepPendingPromptLink(waiting, { screenOnStack: false, ready: true })).toEqual({
37 pending: null,
38 resolve: null,
39 });
40 });
41
42 it("holds a link on its screen until its target is ready, then resolves it once", () => {
43 expect(stepPendingPromptLink(waiting, { screenOnStack: true, ready: false })).toEqual({
44 pending: waiting,
45 resolve: null,
46 });
47 expect(stepPendingPromptLink(waiting, { screenOnStack: true, ready: true })).toEqual({
48 pending: null,
49 resolve: waiting,
50 });
51 });
52
53 it("drops a link whose screen was left before its target was ready", () => {
54 expect(stepPendingPromptLink(waiting, { screenOnStack: false, ready: false })).toEqual({
55 pending: null,
56 resolve: null,
57 });
58 });
59});
60
61describe("withoutPromptLinkParams", () => {
62 it("keeps the route's other params", () => {
63 expect(withoutPromptLinkParams({ prompt: "hi", repo: "a/b", incomingShareId: "1" })).toEqual({
64 incomingShareId: "1",
65 });
66 });
67});