-
Notifications
You must be signed in to change notification settings - Fork 27
/
TrackPickerDisplay.test.js
204 lines (168 loc) · 6.55 KB
/
TrackPickerDisplay.test.js
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import React from "react";
import { render, fireEvent, waitFor } from "@testing-library/react";
import { TrackPickerDisplay } from "./TrackPickerDisplay";
import "@testing-library/jest-dom";
import config from "./../config.json";
import { defaultTrackColors } from "../common.mjs";
describe("TrackPickerDisplay", () => {
const tracks = {
1: config.defaultTrackProps,
2: config.defaultTrackProps,
3: config.defaultTrackProps,
};
const availableColors = [
"greys",
"ygreys",
"reds",
"plainColors",
"lightColors",
];
const availableTracks = [
{ trackFile: "fileA1.vg", trackType: "graph" },
{ trackFile: "fileA2.gbwt", trackType: "haplotype" },
{ trackFile: "fileB1.gbwt", trackType: "haplotype" },
{ trackFile: "fileB2.gam", trackType: "read" },
{ trackFile: "fileC1.xg", trackType: "graph" },
];
it("should render without errors", async () => {
const fakeOnChange = jest.fn();
const { queryByTestId } = render(
<TrackPickerDisplay
tracks={tracks}
availableTracks={availableTracks}
availableColors={availableColors}
onChange={fakeOnChange}
/>
);
expect(queryByTestId("file-type-select-component1")).toBeTruthy();
expect(queryByTestId("file-type-select-component2")).toBeTruthy();
expect(queryByTestId("file-select-component1")).toBeTruthy();
expect(queryByTestId("settings-button-component1")).toBeTruthy();
expect(queryByTestId("delete-button-component1")).toBeTruthy();
expect(queryByTestId("track-add-button-component")).toBeTruthy();
});
it("should add track items when the add button is pressed", async () => {
const fakeOnChange = jest.fn();
const { queryByTestId } = render(
<TrackPickerDisplay
tracks={tracks}
availableTracks={availableTracks}
availableColors={availableColors}
onChange={fakeOnChange}
/>
);
expect(queryByTestId("file-type-select-component4")).toBeFalsy();
const addButtonComponent = queryByTestId("track-add-button-component");
fireEvent.click(addButtonComponent);
const newTrackItem = queryByTestId("file-type-select-component4");
expect(queryByTestId("file-type-select-component4")).toBeTruthy();
expect(queryByTestId("file-select-component4")).toBeTruthy();
expect(queryByTestId("settings-button-component4")).toBeTruthy();
fireEvent.click(addButtonComponent);
expect(queryByTestId("file-type-select-component5")).toBeTruthy();
expect(queryByTestId("file-select-component5")).toBeTruthy();
expect(queryByTestId("settings-button-component5")).toBeTruthy();
});
it("should call onChange when all files are selected", async () => {
const fakeOnChange = jest.fn();
const { queryByTestId, getByText, rerender } = render(
<TrackPickerDisplay
tracks={tracks}
availableTracks={availableTracks}
availableColors={availableColors}
onChange={fakeOnChange}
/>
);
expect(fakeOnChange).toHaveBeenCalledTimes(0);
// select a file for all three track items
// first track item
fireEvent.keyDown(queryByTestId("file-select-component1").firstChild, {
key: "ArrowDown",
});
await waitFor(() => getByText("fileA1.vg"));
fireEvent.click(getByText("fileA1.vg"));
// onChange should not be called
expect(fakeOnChange).toHaveBeenCalledTimes(0);
// second track item
fireEvent.keyDown(queryByTestId("file-type-select-component2").firstChild, {
key: "ArrowDown",
});
await waitFor(() => getByText("haplotype"));
fireEvent.click(getByText("haplotype"));
fireEvent.keyDown(queryByTestId("file-select-component2").firstChild, {
key: "ArrowDown",
});
await waitFor(() => getByText("fileB1.gbwt"));
fireEvent.click(getByText("fileB1.gbwt"));
expect(fakeOnChange).toHaveBeenCalledTimes(0);
// third track item
fireEvent.keyDown(queryByTestId("file-select-component3").firstChild, {
key: "ArrowDown",
});
await waitFor(() => getByText("fileC1.xg"));
fireEvent.click(getByText("fileC1.xg"));
let newTracks = JSON.parse(JSON.stringify(tracks));
newTracks[1].trackFile = "fileA1.vg";
newTracks[1].trackType = "graph";
newTracks[1].trackColorSettings = defaultTrackColors("graph");
newTracks[2].trackFile = "fileB1.gbwt";
newTracks[2].trackType = "haplotype";
newTracks[2].trackColorSettings = defaultTrackColors("haplotype");
newTracks[3].trackFile = "fileC1.xg";
newTracks[3].trackType = "graph";
newTracks[3].trackColorSettings = defaultTrackColors("graph");
expect(fakeOnChange).toHaveBeenCalledTimes(1);
//expect(fakeOnChange).toHaveBeenCalledWith(newTracks);
// add a track item and select a file
const addButtonComponent = queryByTestId("track-add-button-component");
fireEvent.click(addButtonComponent);
newTracks[4] = config.defaultTrackProps;
rerender(
<TrackPickerDisplay
tracks={newTracks}
availableTracks={availableTracks}
availableColors={availableColors}
onChange={fakeOnChange}
/>
);
fireEvent.keyDown(queryByTestId("file-type-select-component4").firstChild, {
key: "ArrowDown",
});
await waitFor(() => getByText("read"));
fireEvent.click(getByText("read"));
fireEvent.keyDown(queryByTestId("file-select-component4").firstChild, {
key: "ArrowDown",
});
await waitFor(() => getByText("fileB2.gam"));
fireEvent.click(getByText("fileB2.gam"));
newTracks[4] = {
trackFile: "fileB2.gam",
trackType: "read",
trackColorSettings: {
mainPalette: "blues",
auxPalette: "reds",
colorReadsByMappingQuality: false,
},
};
expect(fakeOnChange).toHaveBeenCalledTimes(2);
expect(fakeOnChange).toHaveBeenCalledWith(newTracks);
});
it("should delete a trackitem when the delete button is pressed", async () => {
const fakeOnChange = jest.fn();
const { queryByTestId } = render(
<TrackPickerDisplay
tracks={tracks}
availableTracks={availableTracks}
availableColors={availableColors}
onChange={fakeOnChange}
/>
);
// pressing the delete button should delete that row
fireEvent.click(queryByTestId("delete-button-component1"));
expect(queryByTestId("file-type-select-component1")).toBeFalsy();
expect(queryByTestId("file-select-component1")).toBeFalsy();
fireEvent.click(queryByTestId("delete-button-component3"));
expect(queryByTestId("file-type-select-component3")).toBeFalsy();
expect(queryByTestId("file-select-component3")).toBeFalsy();
});
});