-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add url query parameters for filters in job table (#466)
- Loading branch information
1 parent
5f68ad1
commit 0a6bc90
Showing
7 changed files
with
342 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
internal/lookout/ui/src/containers/JobsContainer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
import { JobFilters, makeFiltersFromQueryString, makeQueryStringFromFilters } from "./JobsContainer"; | ||
|
||
function assertStringHasQueryParams(expected: string[], actual: string) { | ||
const actualQueryParams = actual.split("&") | ||
expect(expected.sort()).toStrictEqual(actualQueryParams.sort()) | ||
} | ||
|
||
describe("makeQueryStringFromFilters", () => { | ||
test("makes string with queue", () => { | ||
const filters: JobFilters = { | ||
queue: "test", | ||
jobSet: "", | ||
jobStates: [], | ||
newestFirst: false, | ||
} | ||
const queryString = makeQueryStringFromFilters(filters) | ||
assertStringHasQueryParams(["queue=test", "newest_first=false"], queryString) | ||
}) | ||
|
||
test("makes string with job set", () => { | ||
const filters: JobFilters = { | ||
queue: "", | ||
jobSet: "job-set", | ||
jobStates: [], | ||
newestFirst: false, | ||
} | ||
const queryString = makeQueryStringFromFilters(filters) | ||
assertStringHasQueryParams(["job_set=job-set", "newest_first=false"], queryString) | ||
}) | ||
|
||
test("makes string with single job state", () => { | ||
const filters: JobFilters = { | ||
queue: "", | ||
jobSet: "", | ||
jobStates: ["Queued"], | ||
newestFirst: false, | ||
} | ||
const queryString = makeQueryStringFromFilters(filters) | ||
assertStringHasQueryParams(["job_states=Queued", "newest_first=false"], queryString) | ||
}) | ||
|
||
test("makes string with multiple job states", () => { | ||
const filters: JobFilters = { | ||
queue: "", | ||
jobSet: "", | ||
jobStates: ["Queued", "Running", "Cancelled"], | ||
newestFirst: false, | ||
} | ||
const queryString = makeQueryStringFromFilters(filters) | ||
assertStringHasQueryParams(["job_states=Queued,Running,Cancelled", "newest_first=false"], queryString) | ||
}) | ||
|
||
test("makes string with ordering", () => { | ||
const filters: JobFilters = { | ||
queue: "", | ||
jobSet: "", | ||
jobStates: [], | ||
newestFirst: true, | ||
} | ||
const queryString = makeQueryStringFromFilters(filters) | ||
assertStringHasQueryParams(["newest_first=true"], queryString) | ||
}) | ||
|
||
test("makes string with all filters", () => { | ||
const filters: JobFilters = { | ||
queue: "other-test", | ||
jobSet: "other-job-set", | ||
jobStates: ["Pending", "Succeeded", "Failed"], | ||
newestFirst: true, | ||
} | ||
const queryString = makeQueryStringFromFilters(filters) | ||
assertStringHasQueryParams([ | ||
"queue=other-test", | ||
"job_set=other-job-set", | ||
"job_states=Pending,Succeeded,Failed", | ||
"newest_first=true", | ||
], queryString) | ||
}) | ||
}) | ||
|
||
describe("makeFiltersFromQueryString", () => { | ||
test("empty string returns default filters", () => { | ||
const query = "" | ||
const filters = makeFiltersFromQueryString(query) | ||
expect(filters).toStrictEqual({ | ||
queue: "", | ||
jobSet: "", | ||
jobStates: [], | ||
newestFirst: true, | ||
}) | ||
}) | ||
|
||
test("makes filter with queue", () => { | ||
const query = "queue=test" | ||
const filters = makeFiltersFromQueryString(query) | ||
expect(filters).toStrictEqual({ | ||
queue: "test", | ||
jobSet: "", | ||
jobStates: [], | ||
newestFirst: true, | ||
}) | ||
}) | ||
|
||
test("makes filter with job set", () => { | ||
const query = "job_set=job-set" | ||
const filters = makeFiltersFromQueryString(query) | ||
expect(filters).toStrictEqual({ | ||
queue: "", | ||
jobSet: "job-set", | ||
jobStates: [], | ||
newestFirst: true, | ||
}) | ||
}) | ||
|
||
test("makes filter with single job state", () => { | ||
const query = "job_states=Queued" | ||
const filters = makeFiltersFromQueryString(query) | ||
expect(filters).toStrictEqual({ | ||
queue: "", | ||
jobSet: "", | ||
jobStates: ["Queued"], | ||
newestFirst: true, | ||
}) | ||
}) | ||
|
||
test("makes filter with multiple job states", () => { | ||
const query = "job_states=Queued,Pending,Running" | ||
const filters = makeFiltersFromQueryString(query) | ||
expect(filters).toStrictEqual({ | ||
queue: "", | ||
jobSet: "", | ||
jobStates: ["Queued", "Pending", "Running"], | ||
newestFirst: true, | ||
}) | ||
}) | ||
|
||
const orderingsCases = [["newest_first=true", true], ["newest_first=false", false]] | ||
test.each(orderingsCases)("makes filter with ordering %p", (query, expectedOrdering) => { | ||
const filters = makeFiltersFromQueryString(query as string) | ||
expect(filters).toStrictEqual({ | ||
queue: "", | ||
jobSet: "", | ||
jobStates: [], | ||
newestFirst: expectedOrdering as boolean, | ||
}) | ||
}) | ||
|
||
test("makes filter with everything", () => { | ||
const query = "queue=test&job_set=job-set-1&job_states=Queued,Succeeded,Pending&newest_first=false" | ||
const filters = makeFiltersFromQueryString(query) | ||
expect(filters).toStrictEqual({ | ||
queue: "test", | ||
jobSet: "job-set-1", | ||
jobStates: ["Queued", "Succeeded", "Pending"], | ||
newestFirst: false, | ||
}) | ||
}) | ||
|
||
const nonExistentJobStatesCases = [ | ||
["job_states=SomethingElse", []], | ||
["job_states=Cancelled,SomethingElse,Succeeded,Failed", ["Cancelled", "Succeeded", "Failed"]], | ||
] | ||
test.each(nonExistentJobStatesCases)("non existent job states are ignored %p", (query, expectedJobStates) => { | ||
const filters = makeFiltersFromQueryString(query as string) | ||
expect(filters).toStrictEqual({ | ||
queue: "", | ||
jobSet: "", | ||
jobStates: expectedJobStates, | ||
newestFirst: true, | ||
}) | ||
}) | ||
|
||
test("other query parameters are ignored", () => { | ||
const query = "something=else" | ||
const filters = makeFiltersFromQueryString(query) | ||
expect(filters).toStrictEqual({ | ||
queue: "", | ||
jobSet: "", | ||
jobStates: [], | ||
newestFirst: true, | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.