t3-code-android-nightly/packages/shared/src/composerPullRequestMatches.test.ts
Chris Deeming 4fed6cfb35
feat: add inline file previews and attachment chips across surfaces (#11265)
Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>
2026-09-11 23:58:12 -07:00

48 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vite-plus/test";
import { filterComposerPullRequestMatches } from "./composerPullRequestMatches.ts";
const entry = (number: number, updatedAt: string) => ({
number,
projectId: "p1",
repository: "owner/repo",
updatedAt,
});
describe("filterComposerPullRequestMatches", () => {
it("ranks the exact number above newer substring matches", () => {
const result = filterComposerPullRequestMatches({
entries: [entry(1234, "2026-01-03"), entry(123, "2026-01-01"), entry(1230, "2026-01-02")],
projectId: "p1",
repository: "owner/repo",
query: "123",
limit: 10,
});
expect(result.map((match) => match.number)).toEqual([123, 1234, 1230]);
});
it("leaves the caller's array untouched", () => {
// The sort runs on a copy; mutating the input would reorder whatever the caller holds.
const entries = [entry(2, "2026-01-01"), entry(1, "2026-01-02")];
const snapshot = entries.map((match) => match.number);
filterComposerPullRequestMatches({
entries,
projectId: "p1",
repository: "owner/repo",
query: "",
limit: 10,
});
expect(entries.map((match) => match.number)).toEqual(snapshot);
});
it("de-duplicates and honours the limit", () => {
const result = filterComposerPullRequestMatches({
entries: [entry(7, "2026-01-02"), entry(7, "2026-01-01"), entry(8, "2026-01-03")],
projectId: "p1",
repository: "owner/repo",
query: "",
limit: 1,
});
expect(result).toHaveLength(1);
});
});