diff --git a/components/dashboard/src/data/git-providers/unified-repositories-search-query.test.ts b/components/dashboard/src/data/git-providers/unified-repositories-search-query.test.ts index 930cabf83ff0cc..d56e6a728db82b 100644 --- a/components/dashboard/src/data/git-providers/unified-repositories-search-query.test.ts +++ b/components/dashboard/src/data/git-providers/unified-repositories-search-query.test.ts @@ -40,7 +40,9 @@ test("it should exclude project entries", () => { repo("foo", "project-foo"), ]; const deduplicated = deduplicateAndFilterRepositories("foo", true, suggestedRepos); - expect(deduplicated.length).toEqual(1); + expect(deduplicated.length).toEqual(2); + expect(deduplicated[0].repositoryName).toEqual("foo"); + expect(deduplicated[1].repositoryName).toEqual("foo2"); }); test("it should match entries in url as well as poject name", () => { @@ -75,3 +77,17 @@ test("it keeps the order", () => { expect(deduplicated[2].projectName).toEqual("someFootest"); expect(deduplicated[3].projectName).toEqual("FOOtest"); }); + +test("it should return all repositories without duplicates when excludeProjects is true", () => { + const suggestedRepos: SuggestedRepository[] = [ + repo("foo"), + repo("foo", "project-foo"), + repo("foo", "project-bar"), + repo("bar", "project-foo"), + repo("bar", "project-bar"), + ]; + const deduplicated = deduplicateAndFilterRepositories("foo", true, suggestedRepos); + expect(deduplicated.length).toEqual(2); + expect(deduplicated[0].repositoryName).toEqual("foo"); + expect(deduplicated[1].repositoryName).toEqual("bar"); +}); diff --git a/components/dashboard/src/data/git-providers/unified-repositories-search-query.ts b/components/dashboard/src/data/git-providers/unified-repositories-search-query.ts index 1df558f9c112c7..4ad1c834ff969c 100644 --- a/components/dashboard/src/data/git-providers/unified-repositories-search-query.ts +++ b/components/dashboard/src/data/git-providers/unified-repositories-search-query.ts @@ -53,10 +53,6 @@ export function deduplicateAndFilterRepositories( }); } for (const repo of suggestedRepos) { - // filter out project entries if excludeProjects is true - if (repo.projectId && excludeProjects) { - continue; - } // filter out project-less entries if an entry with a project exists if (!repo.projectId && reposWithProject.has(repo.url)) { continue; @@ -66,7 +62,7 @@ export function deduplicateAndFilterRepositories( continue; } // filter out duplicates - const key = `${repo.url}:${repo.projectId || "no-project"}`; + const key = `${repo.url}:${excludeProjects ? "" : repo.projectId || "no-project"}`; if (collected.has(key)) { continue; }