Skip to content

Commit fc9588a

Browse files
Add tests for buttons
1 parent 08522f9 commit fc9588a

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

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

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,111 @@ describe(MethodRow.name, () => {
251251
expect(screen.queryByRole("combobox")).not.toBeInTheDocument();
252252
expect(screen.getByText("Method already modeled")).toBeInTheDocument();
253253
});
254+
255+
it("Doesn't show add/remove buttons when multiple methods feature flag is disabled", async () => {
256+
render({
257+
modeledMethods: [modeledMethod],
258+
viewState: {
259+
...viewState,
260+
showMultipleModels: false,
261+
},
262+
});
263+
264+
expect(screen.queryByLabelText("Add new model")).not.toBeInTheDocument();
265+
expect(screen.queryByLabelText("Remove model")).not.toBeInTheDocument();
266+
});
267+
268+
it("Button to add new model is disabled when there are no modeled methods", async () => {
269+
render({
270+
modeledMethods: [],
271+
viewState: {
272+
...viewState,
273+
showMultipleModels: true,
274+
},
275+
});
276+
277+
const addButton = screen.queryByLabelText("Add new model");
278+
expect(addButton).toBeInTheDocument();
279+
expect(addButton).toBeDisabled();
280+
281+
expect(screen.queryByLabelText("Remove model")).not.toBeInTheDocument();
282+
});
283+
284+
it("Button to add new model is disabled when there is one unmodeled method", async () => {
285+
render({
286+
modeledMethods: [{ ...modeledMethod, type: "none" }],
287+
viewState: {
288+
...viewState,
289+
showMultipleModels: true,
290+
},
291+
});
292+
293+
const addButton = screen.queryByLabelText("Add new model");
294+
expect(addButton).toBeInTheDocument();
295+
expect(addButton).toBeDisabled();
296+
297+
expect(screen.queryByLabelText("Remove model")).not.toBeInTheDocument();
298+
});
299+
300+
it("Add button is shown and enabed when there is one modeled methods", async () => {
301+
render({
302+
modeledMethods: [modeledMethod],
303+
viewState: {
304+
...viewState,
305+
showMultipleModels: true,
306+
},
307+
});
308+
309+
const addButton = screen.queryByLabelText("Add new model");
310+
expect(addButton).toBeInTheDocument();
311+
expect(addButton).toBeEnabled();
312+
313+
expect(screen.queryByLabelText("Remove model")).not.toBeInTheDocument();
314+
});
315+
316+
it("Add and remove buttons are shown and enabed when there are multiple modeled methods", async () => {
317+
render({
318+
modeledMethods: [
319+
{ ...modeledMethod, type: "source" },
320+
{ ...modeledMethod, type: "none" },
321+
],
322+
viewState: {
323+
...viewState,
324+
showMultipleModels: true,
325+
},
326+
});
327+
328+
const addButton = screen.queryByLabelText("Add new model");
329+
expect(addButton).toBeInTheDocument();
330+
expect(addButton).toBeEnabled();
331+
332+
const removeButton = screen.queryByLabelText("Remove model");
333+
expect(removeButton).toBeInTheDocument();
334+
expect(removeButton).toBeEnabled();
335+
});
336+
337+
it("Shows add button on last row and remove button on all other rows", async () => {
338+
render({
339+
modeledMethods: [
340+
{ ...modeledMethod, type: "source" },
341+
{ ...modeledMethod, type: "sink" },
342+
{ ...modeledMethod, type: "summary" },
343+
{ ...modeledMethod, type: "none" },
344+
],
345+
viewState: {
346+
...viewState,
347+
showMultipleModels: true,
348+
},
349+
});
350+
351+
const addButtons = screen.queryAllByLabelText("Add new model");
352+
expect(addButtons.length).toBe(1);
353+
expect(addButtons[0]).toBeEnabled();
354+
355+
const removeButtons = screen.queryAllByLabelText("Remove model");
356+
expect(removeButtons.length).toBe(3);
357+
for (const removeButton of removeButtons) {
358+
expect(removeButton).toBeEnabled();
359+
}
360+
});
254361
});

0 commit comments

Comments
 (0)