Files
paseo/packages/app/src/screens/new-workspace-picker-state.test.ts
T
Mohamed Boudra fedf155efd refactor(app): replace screen test slop batch 2 with proper coverage (#725)
Deletes four screen-level .test.tsx files (2600+ lines of vi.mock + JSDOM
slop) and replaces each with verified coverage:

- sessions-screen.test.tsx: covered by archive-tab.spec.ts which exercises
  the sessions screen via openSessions() with real agents
- workspace-draft-agent-tab.test.tsx: covered by new-workspace.spec.ts
  "redirects to optimistic draft tab before agent creation resolves"
- new-workspace-screen.test.tsx: covered by new-workspace.spec.ts (main
  submit, branch selection, PR selection, optimistic draft tab) plus
  new-workspace-picker-item.test.ts (pickerItemToCheckoutRequest)
- project-settings-screen.test.tsx: covered by project-config-form.test.ts
  (all round-trip string/array lifecycle semantics) and projects-settings.spec.ts
  (save flow with passthrough field preservation)

Extracts syncPickerPrAttachment from new-workspace-screen.tsx into a new
pure module new-workspace-picker-state.ts with 5 zero-mock unit tests
covering: initial PR selection, branch selection without change, PR
replacement, PR removal on branch switch, and no-duplicate guard.
2026-05-05 19:58:55 +07:00

97 lines
3.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { UserComposerAttachment } from "@/attachments/types";
import type { GitHubSearchItem } from "@server/shared/messages";
import { syncPickerPrAttachment } from "./new-workspace-picker-state";
function makePrItem(number: number, title: string, headRefName = "feature/x"): GitHubSearchItem {
return {
kind: "pr",
number,
title,
url: `https://example.com/pull/${number}`,
state: "open",
body: null,
labels: [],
baseRefName: "main",
headRefName,
};
}
function prAttachment(item: GitHubSearchItem): UserComposerAttachment {
return { kind: "github_pr", item };
}
function issueAttachment(number: number): UserComposerAttachment {
return {
kind: "github_issue",
item: {
kind: "issue",
number,
title: `Issue ${number}`,
url: `https://example.com/issues/${number}`,
state: "open",
body: null,
labels: [],
},
};
}
describe("syncPickerPrAttachment", () => {
it("selects a PR when no previous picker PR is set", () => {
const pr = makePrItem(202, "Refactor picker");
const result = syncPickerPrAttachment({
attachments: [],
previousPickerPrNumber: null,
item: { kind: "github-pr", item: pr },
});
expect(result.attachedPrNumber).toBe(202);
expect(result.attachments).toEqual([prAttachment(pr)]);
});
it("selects a branch without modifying attachments when no previous picker PR", () => {
const issue = issueAttachment(44);
const result = syncPickerPrAttachment({
attachments: [issue],
previousPickerPrNumber: null,
item: { kind: "branch", name: "dev" },
});
expect(result.attachedPrNumber).toBeNull();
expect(result.attachments).toEqual([issue]);
});
it("replaces the previous picker PR when a different PR is selected", () => {
const prA = makePrItem(202, "Refactor picker", "feature/picker");
const prB = makePrItem(303, "Polish chip", "feature/chip");
const result = syncPickerPrAttachment({
attachments: [prAttachment(prA)],
previousPickerPrNumber: 202,
item: { kind: "github-pr", item: prB },
});
expect(result.attachedPrNumber).toBe(303);
expect(result.attachments).toEqual([prAttachment(prB)]);
});
it("removes the previous picker PR and adds no new attachment when a branch is selected", () => {
const pr = makePrItem(202, "Refactor picker");
const issue = issueAttachment(44);
const result = syncPickerPrAttachment({
attachments: [issue, prAttachment(pr)],
previousPickerPrNumber: 202,
item: { kind: "branch", name: "dev" },
});
expect(result.attachedPrNumber).toBeNull();
expect(result.attachments).toEqual([issue]);
});
it("does not duplicate a PR that was already manually attached by the user", () => {
const pr = makePrItem(202, "Refactor picker");
const result = syncPickerPrAttachment({
attachments: [prAttachment(pr)],
previousPickerPrNumber: null,
item: { kind: "github-pr", item: pr },
});
expect(result.attachedPrNumber).toBeNull();
expect(result.attachments).toHaveLength(1);
});
});