Skip to content

Commit 79a2a60

Browse files
authored
test(core): parameterise findGroupFolder cases with it.each
Addresses Greptile review feedback on #3222 — the four cases share fixtures and shape, matching the repo's it.each convention. Generated-By: PostHog Code Task-Id: 783b5974-b3ee-4b5e-9ff6-fbc93a6794c5
1 parent e815d38 commit 79a2a60

1 file changed

Lines changed: 43 additions & 23 deletions

File tree

packages/core/src/sidebar/groupTasks.test.ts

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -354,40 +354,60 @@ describe("groupByRepository", () => {
354354
});
355355

356356
describe("findGroupFolder", () => {
357-
const mainClone = {
357+
interface GroupFolder {
358+
path: string;
359+
remoteUrl: string | null;
360+
mainRepoPath?: string | null;
361+
}
362+
363+
const mainClone: GroupFolder = {
358364
path: "/repos/code",
359365
remoteUrl: "posthog/code",
360366
mainRepoPath: null,
361367
};
362-
const worktree = {
368+
const worktree: GroupFolder = {
363369
path: "/repos/code-wt",
364370
remoteUrl: "posthog/code",
365371
mainRepoPath: "/repos/code",
366372
};
367-
const unrelated = {
373+
const unrelated: GroupFolder = {
368374
path: "/repos/other",
369375
remoteUrl: "acme/other",
370376
mainRepoPath: null,
371377
};
372-
373-
it("prefers the main clone when a worktree of the same repo was added first", () => {
374-
expect(
375-
findGroupFolder([worktree, mainClone, unrelated], "posthog/code"),
376-
).toBe(mainClone);
377-
});
378-
379-
it("falls back to the worktree when only it is registered", () => {
380-
expect(findGroupFolder([worktree, unrelated], "posthog/code")).toBe(
381-
worktree,
382-
);
383-
});
384-
385-
it("matches folders without a remote by path", () => {
386-
const local = { path: "/repos/local", remoteUrl: null };
387-
expect(findGroupFolder([local], "/repos/local")).toBe(local);
388-
});
389-
390-
it("returns undefined when nothing matches", () => {
391-
expect(findGroupFolder([unrelated], "posthog/code")).toBeUndefined();
378+
const local: GroupFolder = { path: "/repos/local", remoteUrl: null };
379+
380+
it.each<{
381+
name: string;
382+
folders: GroupFolder[];
383+
groupId: string;
384+
expected: GroupFolder | undefined;
385+
}>([
386+
{
387+
name: "prefers the main clone when a worktree of the same repo was added first",
388+
folders: [worktree, mainClone, unrelated],
389+
groupId: "posthog/code",
390+
expected: mainClone,
391+
},
392+
{
393+
name: "falls back to the worktree when only it is registered",
394+
folders: [worktree, unrelated],
395+
groupId: "posthog/code",
396+
expected: worktree,
397+
},
398+
{
399+
name: "matches folders without a remote by path",
400+
folders: [local],
401+
groupId: "/repos/local",
402+
expected: local,
403+
},
404+
{
405+
name: "returns undefined when nothing matches",
406+
folders: [unrelated],
407+
groupId: "posthog/code",
408+
expected: undefined,
409+
},
410+
])("$name", ({ folders, groupId, expected }) => {
411+
expect(findGroupFolder(folders, groupId)).toBe(expected);
392412
});
393413
});

0 commit comments

Comments
 (0)