-
Notifications
You must be signed in to change notification settings - Fork 226
Add config options for default sorting/filtering values in variant analysis results view #2392
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
Changes from 4 commits
e40cf13
a8b17cf
d6cd73d
e4da4c5
d8d4e43
1970af9
798714c
462eaf4
f120b8e
21f4fbc
db29deb
5ca5593
006dd7e
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 |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| import * as React from "react"; | ||
| import { render as reactRender, screen } from "@testing-library/react"; | ||
| import { act, render as reactRender, screen } from "@testing-library/react"; | ||
| import { | ||
| VariantAnalysisFailureReason, | ||
| VariantAnalysisStatus, | ||
| } from "../../../variant-analysis/shared/variant-analysis"; | ||
| import { VariantAnalysis, VariantAnalysisProps } from "../VariantAnalysis"; | ||
| import { createMockVariantAnalysis } from "../../../../test/factories/variant-analysis/shared/variant-analysis"; | ||
| import { ToVariantAnalysisMessage } from "../../../pure/interface-types"; | ||
| import { FilterKey, SortKey } from "../../../pure/variant-analysis-filter-sort"; | ||
|
|
||
| describe(VariantAnalysis.name, () => { | ||
| const render = (props: Partial<VariantAnalysisProps> = {}) => | ||
|
|
@@ -16,6 +18,23 @@ describe(VariantAnalysis.name, () => { | |
| />, | ||
| ); | ||
|
|
||
| const postMessage = async (msg: ToVariantAnalysisMessage) => { | ||
| await act(async () => { | ||
| // window.postMessage doesn't set the origin correctly, see | ||
| // https://github.com/jsdom/jsdom/issues/2745 | ||
| window.dispatchEvent( | ||
| new MessageEvent("message", { | ||
| source: window, | ||
| origin: window.location.origin, | ||
| data: msg, | ||
| }), | ||
| ); | ||
|
|
||
| // The event is dispatched asynchronously, so we need to wait for it to be handled. | ||
| await new Promise((resolve) => setTimeout(resolve, 0)); | ||
| }); | ||
| }; | ||
|
Member
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. Now that we're using this in at least two tests, do you think it would make sense to move this to a separate file and export the function?
Contributor
Author
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 idea! I wasn't sure where best to put the shared file. Currently in |
||
|
|
||
| it("renders a pending analysis", () => { | ||
| const variantAnalysis = createMockVariantAnalysis({ | ||
| status: VariantAnalysisStatus.InProgress, | ||
|
|
@@ -46,4 +65,33 @@ describe(VariantAnalysis.name, () => { | |
| ), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("renders results view with correct filter and sort state", async () => { | ||
| const variantAnalysis = createMockVariantAnalysis({}); | ||
| render({ variantAnalysis }); | ||
|
|
||
| // Without this await, `getByDisplayValue` could not find any selected dropdown option. | ||
| await new Promise((resolve) => setTimeout(resolve, 0)); | ||
|
|
||
| expect(screen.getByDisplayValue("With results")).toBeInTheDocument(); | ||
| expect(screen.getByDisplayValue("Number of results")).toBeInTheDocument(); | ||
|
Contributor
Author
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. For some reason, Not sure why, but it works 😅 If anyone knows more about this, let us know!
Member
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. I'm not sure why this is happening (it could be that some of the VS Code UI toolkit shadow DOM is only rendered on the next tick or something like that), but a slightly more reliable way to solve this is by waiting for the element to start existing: await waitFor(() => screen.getByText("With results"));This way we don't depend on the exact tick and it will still fail if it doesn't find the element after some time.
Contributor
Author
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. This is perfect! Thanks ✨ |
||
|
|
||
| await postMessage({ | ||
| t: "setVariantAnalysis", | ||
| variantAnalysis, | ||
| filterSortState: { | ||
| searchValue: "", | ||
| filterKey: FilterKey.All, | ||
| sortKey: SortKey.Alphabetically, | ||
| }, | ||
| }); | ||
|
|
||
| expect(screen.getByDisplayValue("All")).toBeInTheDocument(); | ||
| expect(screen.getByDisplayValue("Alphabetically")).toBeInTheDocument(); | ||
|
|
||
| expect(screen.queryByDisplayValue("With results")).not.toBeInTheDocument(); | ||
| expect( | ||
| screen.queryByDisplayValue("Number of results"), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.