Skip to content

Commit 73c38ae

Browse files
committed
Fix tests
1 parent 5336388 commit 73c38ae

File tree

5 files changed

+93
-147
lines changed

5 files changed

+93
-147
lines changed

extensions/ql-vscode/src/view/method-modeling/__tests__/MultipleModeledMethodsPanel.spec.tsx

Lines changed: 50 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,26 @@ describe(MultipleModeledMethodsPanel.name, () => {
5252
).toHaveValue("none");
5353
});
5454

55-
it("disables all pagination", () => {
55+
it("disables all pagination", async () => {
5656
render();
5757

58-
expect(
59-
screen
60-
.getByLabelText("Previous modeling")
61-
.getElementsByTagName("input")[0],
62-
).toBeDisabled();
63-
expect(
64-
screen.getByLabelText("Next modeling").getElementsByTagName("input")[0],
65-
).toBeDisabled();
58+
const prevButton = await screen.findByLabelText("Previous modeling");
59+
const nextButton = await screen.findByLabelText("Next modeling");
60+
61+
expect(prevButton).toBeDisabled();
62+
expect(nextButton).toBeDisabled();
6663
expect(screen.queryByText("0/0")).not.toBeInTheDocument();
6764
expect(screen.queryByText("1/0")).not.toBeInTheDocument();
6865
});
6966

70-
it("cannot add or delete modeling", () => {
67+
it("cannot add or delete modeling", async () => {
7168
render();
7269

73-
expect(
74-
screen
75-
.getByLabelText("Delete modeling")
76-
.getElementsByTagName("input")[0],
77-
).toBeDisabled();
78-
expect(
79-
screen.getByLabelText("Add modeling").getElementsByTagName("input")[0],
80-
).toBeDisabled();
70+
const deleteButton = await screen.findByLabelText("Delete modeling");
71+
const addButton = await screen.findByLabelText("Add modeling");
72+
73+
expect(deleteButton).toBeDisabled();
74+
expect(addButton).toBeDisabled();
8175
});
8276
});
8377

@@ -104,28 +98,22 @@ describe(MultipleModeledMethodsPanel.name, () => {
10498
).toHaveValue("sink");
10599
});
106100

107-
it("disables all pagination", () => {
101+
it("disables all pagination", async () => {
108102
render();
109103

110-
expect(
111-
screen
112-
.getByLabelText("Previous modeling")
113-
.getElementsByTagName("input")[0],
114-
).toBeDisabled();
115-
expect(
116-
screen.getByLabelText("Next modeling").getElementsByTagName("input")[0],
117-
).toBeDisabled();
104+
const prevButton = await screen.findByLabelText("Previous modeling");
105+
const nextButton = await screen.findByLabelText("Next modeling");
106+
107+
expect(prevButton).toBeDisabled();
108+
expect(nextButton).toBeDisabled();
118109
expect(screen.queryByText("1/1")).not.toBeInTheDocument();
119110
});
120111

121-
it("cannot delete modeling", () => {
112+
it("cannot delete modeling", async () => {
122113
render();
123114

124-
expect(
125-
screen
126-
.getByLabelText("Delete modeling")
127-
.getElementsByTagName("input")[0],
128-
).toBeDisabled();
115+
const deleteButton = await screen.findByLabelText("Delete modeling");
116+
expect(deleteButton).toBeDisabled();
129117
});
130118

131119
it("can add modeling", async () => {
@@ -199,37 +187,26 @@ describe(MultipleModeledMethodsPanel.name, () => {
199187
it("disables the correct pagination", async () => {
200188
render();
201189

202-
expect(
203-
screen
204-
.getByLabelText("Previous modeling")
205-
.getElementsByTagName("input")[0],
206-
).toBeDisabled();
207-
expect(
208-
screen.getByLabelText("Next modeling").getElementsByTagName("input")[0],
209-
).toBeEnabled();
190+
const prevButton = await screen.findByLabelText("Previous modeling");
191+
const nextButton = await screen.findByLabelText("Next modeling");
192+
193+
expect(prevButton).toBeDisabled();
194+
expect(nextButton).toBeEnabled();
210195
});
211196

212197
it("can use the pagination", async () => {
213198
render();
214199

215-
await userEvent.click(screen.getByLabelText("Next modeling"));
200+
const prevButton = await screen.findByLabelText("Previous modeling");
201+
const nextButton = await screen.findByLabelText("Next modeling");
216202

203+
await userEvent.click(nextButton);
217204
await waitFor(() => {
218-
expect(
219-
screen
220-
.getByLabelText("Previous modeling")
221-
.getElementsByTagName("input")[0],
222-
).toBeEnabled();
205+
expect(prevButton).toBeEnabled();
223206
});
224207

225-
expect(
226-
screen
227-
.getByLabelText("Previous modeling")
228-
.getElementsByTagName("input")[0],
229-
).toBeEnabled();
230-
expect(
231-
screen.getByLabelText("Next modeling").getElementsByTagName("input")[0],
232-
).toBeDisabled();
208+
expect(prevButton).toBeEnabled();
209+
expect(nextButton).toBeDisabled();
233210
expect(screen.getByText("2/2")).toBeInTheDocument();
234211

235212
expect(
@@ -445,34 +422,20 @@ describe(MultipleModeledMethodsPanel.name, () => {
445422
it("can use the pagination", async () => {
446423
render();
447424

448-
expect(
449-
screen
450-
.getByLabelText("Previous modeling")
451-
.getElementsByTagName("input")[0],
452-
).toBeDisabled();
453-
expect(
454-
screen.getByLabelText("Next modeling").getElementsByTagName("input")[0],
455-
).toBeEnabled();
425+
const prevButton = await screen.findByLabelText("Previous modeling");
426+
const nextButton = await screen.findByLabelText("Next modeling");
427+
expect(prevButton).toBeDisabled();
428+
expect(nextButton).toBeEnabled();
456429
expect(screen.getByText("1/3")).toBeInTheDocument();
457430

458-
await userEvent.click(screen.getByLabelText("Next modeling"));
431+
await userEvent.click(nextButton);
459432

460433
await waitFor(() => {
461-
expect(
462-
screen
463-
.getByLabelText("Previous modeling")
464-
.getElementsByTagName("input")[0],
465-
).toBeEnabled();
434+
expect(prevButton).toBeEnabled();
466435
});
467436

468-
expect(
469-
screen
470-
.getByLabelText("Previous modeling")
471-
.getElementsByTagName("input")[0],
472-
).toBeEnabled();
473-
expect(
474-
screen.getByLabelText("Next modeling").getElementsByTagName("input")[0],
475-
).toBeEnabled();
437+
expect(prevButton).toBeEnabled();
438+
expect(nextButton).toBeEnabled();
476439
expect(screen.getByText("2/3")).toBeInTheDocument();
477440

478441
expect(
@@ -481,16 +444,10 @@ describe(MultipleModeledMethodsPanel.name, () => {
481444
}),
482445
).toHaveValue("source");
483446

484-
await userEvent.click(screen.getByLabelText("Next modeling"));
447+
await userEvent.click(nextButton);
485448

486-
expect(
487-
screen
488-
.getByLabelText("Previous modeling")
489-
.getElementsByTagName("input")[0],
490-
).toBeEnabled();
491-
expect(
492-
screen.getByLabelText("Next modeling").getElementsByTagName("input")[0],
493-
).toBeDisabled();
449+
expect(prevButton).toBeEnabled();
450+
expect(nextButton).toBeDisabled();
494451
expect(screen.getByText("3/3")).toBeInTheDocument();
495452

496453
expect(
@@ -499,24 +456,14 @@ describe(MultipleModeledMethodsPanel.name, () => {
499456
}),
500457
).toHaveValue("local");
501458

502-
await userEvent.click(screen.getByLabelText("Previous modeling"));
459+
await userEvent.click(prevButton);
503460

504461
await waitFor(() => {
505-
expect(
506-
screen
507-
.getByLabelText("Next modeling")
508-
.getElementsByTagName("input")[0],
509-
).toBeEnabled();
462+
expect(nextButton).toBeEnabled();
510463
});
511464

512-
expect(
513-
screen
514-
.getByLabelText("Previous modeling")
515-
.getElementsByTagName("input")[0],
516-
).toBeEnabled();
517-
expect(
518-
screen.getByLabelText("Next modeling").getElementsByTagName("input")[0],
519-
).toBeEnabled();
465+
expect(prevButton).toBeEnabled();
466+
expect(nextButton).toBeEnabled();
520467
expect(screen.getByText("2/3")).toBeInTheDocument();
521468

522469
expect(
@@ -574,12 +521,11 @@ describe(MultipleModeledMethodsPanel.name, () => {
574521

575522
const render = createRender(modeledMethods);
576523

577-
it("can add modeling", () => {
524+
it("can add modeling", async () => {
578525
render();
579526

580-
expect(
581-
screen.getByLabelText("Add modeling").getElementsByTagName("input")[0],
582-
).toBeEnabled();
527+
const addButton = await screen.findByLabelText("Add modeling");
528+
expect(addButton).toBeEnabled();
583529
});
584530

585531
it("can delete first modeling", async () => {

extensions/ql-vscode/src/view/model-editor/__tests__/MethodRow.spec.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ describe(MethodRow.name, () => {
243243
modeledMethods: [],
244244
});
245245

246-
const addButton = screen.queryByLabelText("Add new model");
246+
const addButton = await screen.findByLabelText("Add new model");
247247
expect(addButton).toBeInTheDocument();
248-
expect(addButton?.getElementsByTagName("input")[0]).toBeDisabled();
248+
expect(addButton).toBeDisabled();
249249

250250
expect(screen.queryByLabelText("Remove model")).not.toBeInTheDocument();
251251
});
@@ -255,9 +255,9 @@ describe(MethodRow.name, () => {
255255
modeledMethods: [{ ...modeledMethod, type: "none" }],
256256
});
257257

258-
const addButton = screen.queryByLabelText("Add new model");
258+
const addButton = await screen.findByLabelText("Add new model");
259259
expect(addButton).toBeInTheDocument();
260-
expect(addButton?.getElementsByTagName("input")[0]).toBeDisabled();
260+
expect(addButton).toBeDisabled();
261261

262262
expect(screen.queryByLabelText("Remove model")).not.toBeInTheDocument();
263263
});
@@ -267,9 +267,9 @@ describe(MethodRow.name, () => {
267267
modeledMethods: [modeledMethod],
268268
});
269269

270-
const addButton = screen.queryByLabelText("Add new model");
270+
const addButton = await screen.findByLabelText("Add new model");
271271
expect(addButton).toBeInTheDocument();
272-
expect(addButton?.getElementsByTagName("input")[0]).toBeEnabled();
272+
expect(addButton).toBeEnabled();
273273

274274
expect(screen.queryByLabelText("Remove model")).not.toBeInTheDocument();
275275
});
@@ -282,16 +282,16 @@ describe(MethodRow.name, () => {
282282
],
283283
});
284284

285-
const addButton = screen.queryByLabelText("Add new model");
285+
const addButton = await screen.findByLabelText("Add new model");
286286
expect(addButton).toBeInTheDocument();
287-
expect(addButton?.getElementsByTagName("input")[0]).toBeEnabled();
287+
expect(addButton).toBeEnabled();
288288

289-
const removeButton = screen.queryByLabelText("Remove model");
289+
const removeButton = await screen.findByLabelText("Remove model");
290290
expect(removeButton).toBeInTheDocument();
291-
expect(removeButton?.getElementsByTagName("input")[0]).toBeEnabled();
291+
expect(removeButton).toBeEnabled();
292292
});
293293

294-
it("shows add model button on first row and remove model button on all other rows", async () => {
294+
it("shows add model button on first row and remove model button on all other rows", () => {
295295
render({
296296
modeledMethods: [
297297
{ ...modeledMethod, type: "source" },
@@ -303,12 +303,12 @@ describe(MethodRow.name, () => {
303303

304304
const addButtons = screen.queryAllByLabelText("Add new model");
305305
expect(addButtons.length).toBe(1);
306-
expect(addButtons[0]?.getElementsByTagName("input")[0]).toBeEnabled();
306+
expect(addButtons[0]).toBeEnabled();
307307

308308
const removeButtons = screen.queryAllByLabelText("Remove model");
309309
expect(removeButtons.length).toBe(3);
310310
for (const removeButton of removeButtons) {
311-
expect(removeButton?.getElementsByTagName("input")[0]).toBeEnabled();
311+
expect(removeButton).toBeEnabled();
312312
}
313313
});
314314

0 commit comments

Comments
 (0)