-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a component for filtering repositories based on their results #2343
Changes from 1 commit
d30ca71
563720b
18d7c89
049b4c2
72c07a3
0685218
2701cd4
7fb9975
ec35293
a8a84a6
dd630bf
93acb76
2844fed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import { | |||||
defaultFilterSortState, | ||||||
filterAndSortRepositoriesWithResults, | ||||||
filterAndSortRepositoriesWithResultsByName, | ||||||
FilterKey, | ||||||
matchesFilter, | ||||||
SortKey, | ||||||
} from "../../src/pure/variant-analysis-filter-sort"; | ||||||
|
@@ -42,6 +43,60 @@ describe(matchesFilter.name, () => { | |||||
).toBe(matches); | ||||||
}, | ||||||
); | ||||||
|
||||||
it("returns true if filterKey is all and resultCount is positive", () => { | ||||||
expect( | ||||||
matchesFilter( | ||||||
{ repository, resultCount: 1 }, | ||||||
{ ...defaultFilterSortState, filterKey: FilterKey.All }, | ||||||
), | ||||||
).toBe(true); | ||||||
}); | ||||||
|
||||||
it("returns true if filterKey is all and resultCount is zero", () => { | ||||||
expect( | ||||||
matchesFilter( | ||||||
{ repository, resultCount: 0 }, | ||||||
{ ...defaultFilterSortState, filterKey: FilterKey.All }, | ||||||
), | ||||||
).toBe(true); | ||||||
}); | ||||||
|
||||||
it("returns true if filterKey is all and resultCount is undefined", () => { | ||||||
expect( | ||||||
matchesFilter( | ||||||
{ repository }, | ||||||
{ ...defaultFilterSortState, filterKey: FilterKey.All }, | ||||||
), | ||||||
).toBe(true); | ||||||
}); | ||||||
|
||||||
it("returns true if filterKey is withResults and resultCount is positive", () => { | ||||||
expect( | ||||||
matchesFilter( | ||||||
{ repository, resultCount: 1 }, | ||||||
{ ...defaultFilterSortState, filterKey: FilterKey.WithResults }, | ||||||
), | ||||||
).toBe(true); | ||||||
}); | ||||||
|
||||||
it("returns false if filterKey is withResults and resultCount is zero", () => { | ||||||
expect( | ||||||
matchesFilter( | ||||||
{ repository, resultCount: 0 }, | ||||||
{ ...defaultFilterSortState, filterKey: FilterKey.WithResults }, | ||||||
), | ||||||
).toBe(false); | ||||||
}); | ||||||
|
||||||
it("returns false if filterKey is withResults and resultCount is undefined", () => { | ||||||
expect( | ||||||
matchesFilter( | ||||||
{ repository }, | ||||||
{ ...defaultFilterSortState, filterKey: FilterKey.WithResults }, | ||||||
), | ||||||
).toBe(false); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe(compareRepository.name, () => { | ||||||
|
@@ -352,7 +407,7 @@ describe(filterAndSortRepositoriesWithResultsByName.name, () => { | |||||
}, | ||||||
]; | ||||||
|
||||||
describe("when sort key is given without filter", () => { | ||||||
describe("when sort key is given without search or filter", () => { | ||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResultsByName(repositories, { | ||||||
|
@@ -368,7 +423,7 @@ describe(filterAndSortRepositoriesWithResultsByName.name, () => { | |||||
}); | ||||||
}); | ||||||
|
||||||
describe("when sort key and search filter are given", () => { | ||||||
describe("when sort key and search are given without filter", () => { | ||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResultsByName(repositories, { | ||||||
|
@@ -379,6 +434,30 @@ describe(filterAndSortRepositoriesWithResultsByName.name, () => { | |||||
).toEqual([repositories[2], repositories[0]]); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe("when sort key and filter withResults are given without search", () => { | ||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResultsByName(repositories, { | ||||||
...defaultFilterSortState, | ||||||
sortKey: SortKey.ResultsCount, | ||||||
filterKey: FilterKey.WithResults, | ||||||
}), | ||||||
).toEqual([repositories[3], repositories[2], repositories[0]]); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe("when sort key and search and filter withResults are given", () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: I found this a bit difficult to parse 😅 Maybe something like
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Those definitely could be clearer 😅 I've updated the tests that have at least three items in the list to use commas. |
||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResultsByName(repositories, { | ||||||
sortKey: SortKey.ResultsCount, | ||||||
filterKey: FilterKey.WithResults, | ||||||
searchValue: "r", | ||||||
}), | ||||||
).toEqual([repositories[3]]); | ||||||
}); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe(filterAndSortRepositoriesWithResults.name, () => { | ||||||
|
@@ -413,7 +492,7 @@ describe(filterAndSortRepositoriesWithResults.name, () => { | |||||
}, | ||||||
]; | ||||||
|
||||||
describe("when sort key is given without filter", () => { | ||||||
describe("when sort key is given", () => { | ||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResults(repositories, { | ||||||
|
@@ -429,7 +508,7 @@ describe(filterAndSortRepositoriesWithResults.name, () => { | |||||
}); | ||||||
}); | ||||||
|
||||||
describe("when sort key and search filter are given", () => { | ||||||
describe("when sort key and search are given", () => { | ||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResults(repositories, { | ||||||
|
@@ -441,12 +520,49 @@ describe(filterAndSortRepositoriesWithResults.name, () => { | |||||
}); | ||||||
}); | ||||||
|
||||||
describe("when sort key, search filter, and repository ids are given", () => { | ||||||
describe("when sort key and filter withResults are given", () => { | ||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResults(repositories, { | ||||||
...defaultFilterSortState, | ||||||
sortKey: SortKey.ResultsCount, | ||||||
filterKey: FilterKey.WithResults, | ||||||
}), | ||||||
).toEqual([repositories[3], repositories[2], repositories[0]]); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe("when sort key and filter withResults are given", () => { | ||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResults(repositories, { | ||||||
...defaultFilterSortState, | ||||||
sortKey: SortKey.ResultsCount, | ||||||
filterKey: FilterKey.WithResults, | ||||||
}), | ||||||
).toEqual([repositories[3], repositories[2], repositories[0]]); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe("when sort key and search and filter withResults are given", () => { | ||||||
robertbrignull marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResults(repositories, { | ||||||
...defaultFilterSortState, | ||||||
sortKey: SortKey.ResultsCount, | ||||||
filterKey: FilterKey.WithResults, | ||||||
searchValue: "r", | ||||||
}), | ||||||
).toEqual([repositories[3]]); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe("when sort key, search, filter withResults, and repository ids are given", () => { | ||||||
it("returns the correct results", () => { | ||||||
expect( | ||||||
filterAndSortRepositoriesWithResults(repositories, { | ||||||
sortKey: SortKey.ResultsCount, | ||||||
filterKey: FilterKey.WithResults, | ||||||
searchValue: "la", | ||||||
repositoryIds: [ | ||||||
repositories[1].repository.id, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: this test block is quite large, I wonder if it makes sense to chunk it up into
describe
blocks somehow? E.g. the first tests (not the ones you added here) are all about searching, while these new ones describe "when filterKey is all/withResults"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've split it up into two
describe
blocks. Let me know if that wasn't quite what you meant.