Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { resolveThreadReferenceCopyTarget } from "./threadReference.ts";
4
5describe("resolveThreadReferenceCopyTarget", () => {
6 it("does not copy another reference while the open panel URL is unavailable", () => {
7 expect(
8 resolveThreadReferenceCopyTarget({
9 threadId: "thread-1",
10 openPanelPullRequestUrl: null,
11 linkedPullRequestUrl: "https://github.com/t3/pr/12",
12 detectedPullRequestUrl: "https://github.com/t3/pr/13",
13 }),
14 ).toBeNull();
15 });
16
17 it("prefers the open panel pull request over linked and detected pull requests", () => {
18 expect(
19 resolveThreadReferenceCopyTarget({
20 threadId: "thread-1",
21 openPanelPullRequestUrl: "https://github.com/t3/pr/14",
22 linkedPullRequestUrl: "https://github.com/t3/pr/12",
23 detectedPullRequestUrl: "https://github.com/t3/pr/13",
24 }),
25 ).toMatchObject({
26 kind: "pull-request",
27 value: "https://github.com/t3/pr/14",
28 successTitle: "PR link copied",
29 });
30 });
31
32 it("prefers a durable linked pull request", () => {
33 expect(
34 resolveThreadReferenceCopyTarget({
35 threadId: "thread-1",
36 linkedPullRequestUrl: "https://github.com/t3/pr/12",
37 detectedPullRequestUrl: "https://github.com/t3/pr/13",
38 }),
39 ).toMatchObject({
40 kind: "pull-request",
41 value: "https://github.com/t3/pr/12",
42 successTitle: "PR link copied",
43 });
44 });
45
46 it("uses a pull request detected from the active branch", () => {
47 expect(
48 resolveThreadReferenceCopyTarget({
49 threadId: "thread-1",
50 detectedPullRequestUrl: "https://github.com/t3/pr/13",
51 }),
52 ).toMatchObject({
53 kind: "pull-request",
54 value: "https://github.com/t3/pr/13",
55 });
56 });
57
58 it("falls back to the thread ID", () => {
59 expect(resolveThreadReferenceCopyTarget({ threadId: "thread-1" })).toEqual({
60 kind: "thread",
61 value: "thread-1",
62 clipboardTarget: "thread ID",
63 successTitle: "Thread ID copied",
64 failureTitle: "Failed to copy thread ID",
65 });
66 });
67});