-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathVariantAnalysisActions.spec.tsx
More file actions
139 lines (114 loc) · 4.43 KB
/
VariantAnalysisActions.spec.tsx
File metadata and controls
139 lines (114 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { render as reactRender, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { VariantAnalysisStatus } from "../../../variant-analysis/shared/variant-analysis";
import type { VariantAnalysisActionsProps } from "../VariantAnalysisActions";
import { VariantAnalysisActions } from "../VariantAnalysisActions";
describe(VariantAnalysisActions.name, () => {
const onStopQueryClick = jest.fn();
const onCopyRepositoryListClick = jest.fn();
const onExportResultsClick = jest.fn();
afterEach(() => {
onStopQueryClick.mockReset();
onCopyRepositoryListClick.mockReset();
onExportResultsClick.mockReset();
});
const render = (
props: Pick<VariantAnalysisActionsProps, "variantAnalysisStatus"> &
Partial<VariantAnalysisActionsProps>,
) =>
reactRender(
<VariantAnalysisActions
onStopQueryClick={onStopQueryClick}
onCopyRepositoryListClick={onCopyRepositoryListClick}
onExportResultsClick={onExportResultsClick}
{...props}
/>,
);
it("renders 1 button when in progress", async () => {
const { container } = render({
variantAnalysisStatus: VariantAnalysisStatus.InProgress,
});
expect(container.querySelectorAll("vscode-button").length).toEqual(1);
});
it("renders the stop query button when in progress", async () => {
render({
variantAnalysisStatus: VariantAnalysisStatus.InProgress,
});
await userEvent.click(screen.getByText("Stop query"));
expect(onStopQueryClick).toHaveBeenCalledTimes(1);
});
it("renders the stopping query disabled button when canceling", async () => {
render({
variantAnalysisStatus: VariantAnalysisStatus.Canceling,
});
const button = screen.getByText("Stopping query");
expect(button).toBeInTheDocument();
expect(button.getElementsByTagName("input")[0]).toBeDisabled();
});
it("does not render a stop query button when canceling", async () => {
render({
variantAnalysisStatus: VariantAnalysisStatus.Canceling,
});
expect(screen.queryByText("Stop query")).not.toBeInTheDocument();
});
it("renders 3 buttons when in progress with results", async () => {
const { container } = render({
variantAnalysisStatus: VariantAnalysisStatus.InProgress,
showResultActions: true,
});
expect(container.querySelectorAll("vscode-button").length).toEqual(3);
});
it("renders 2 buttons when succeeded", async () => {
const { container } = render({
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
showResultActions: true,
});
expect(container.querySelectorAll("vscode-button").length).toEqual(2);
});
it("renders the copy repository list button when succeeded", async () => {
render({
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
showResultActions: true,
});
await userEvent.click(screen.getByText("Copy repository list"));
expect(onCopyRepositoryListClick).toHaveBeenCalledTimes(1);
});
it("renders the export results button when succeeded", async () => {
render({
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
showResultActions: true,
});
await userEvent.click(screen.getByText("Export results"));
expect(onExportResultsClick).toHaveBeenCalledTimes(1);
});
it("does not render any buttons when failed", () => {
const { container } = render({
variantAnalysisStatus: VariantAnalysisStatus.Failed,
});
expect(container.querySelectorAll("vscode-button").length).toEqual(0);
});
it("changes the text on the buttons when repositories are selected", async () => {
render({
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
showResultActions: true,
hasSelectedRepositories: true,
hasFilteredRepositories: true,
});
expect(screen.getByText("Export selected results")).toBeInTheDocument();
expect(
screen.getByText("Copy selected repositories as a list"),
).toBeInTheDocument();
});
it("changes the text on the buttons when repositories are filtered", async () => {
render({
variantAnalysisStatus: VariantAnalysisStatus.Succeeded,
showResultActions: true,
hasSelectedRepositories: false,
hasFilteredRepositories: true,
});
expect(screen.getByText("Export filtered results")).toBeInTheDocument();
expect(
screen.getByText("Copy filtered repositories as a list"),
).toBeInTheDocument();
});
});