Skip to content

Commit

Permalink
✅ [#4798] Added confirm modal handling to storybook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmolen committed Nov 12, 2024
1 parent e19b84a commit 6004e0d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect, findByRole, fireEvent, fn, userEvent, waitFor, within} from '@storybook/test';
import {expect, fireEvent, fn, screen, userEvent, waitFor, within} from '@storybook/test';
import selectEvent from 'react-select-event';

import {
Expand Down Expand Up @@ -189,8 +189,6 @@ export const Empty = {
},
play: async ({canvasElement, step, args}) => {
const canvas = within(canvasElement);
const originalConfirm = window.confirm;
window.confirm = () => true;

const pluginDropdown = canvas.getByLabelText('Plugin');
const decisionDefDropdown = canvas.getByLabelText('Beslisdefinitie-ID');
Expand Down Expand Up @@ -271,6 +269,12 @@ export const Empty = {
const button = canvas.getByTitle('Verwijderen');

await userEvent.click(button);
await waitFor(async () => {
// Close the confirmation modal
const confirmModal = await screen.findByRole('dialog');
const confirmButton = within(confirmModal).getByRole('button', {name: 'Accepteren'});
await userEvent.click(confirmButton);
});

const varsDropdowns = within(
document.querySelector('.logic-dmn__mapping-config')
Expand All @@ -282,8 +286,6 @@ export const Empty = {
await expect(varsDropdowns.length).toBe(0);
await expect(textInput.length).toBe(0);
});

window.confirm = originalConfirm;
},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect, fn, userEvent, waitFor, within} from '@storybook/test';
import {expect, fn, screen, userEvent, waitFor, within} from '@storybook/test';
import {Form, Formik} from 'formik';
import selectEvent from 'react-select-event';

Expand Down Expand Up @@ -74,12 +74,21 @@ export const Default = {};

export const SwitchToV2Empty = {
play: async ({canvasElement}) => {
window.confirm = fn(() => true);
const canvas = within(canvasElement);

const v2Tab = canvas.getByRole('tab', {name: 'Variabelekoppelingen'});
await userEvent.click(v2Tab);

await waitFor(async () => {
// Close the confirmation modal
const confirmModal = await screen.findByRole('dialog');
const confirmButton = within(confirmModal).getByRole('button', {name: 'Accepteren'});
await userEvent.click(confirmButton);

// Expect v2Tab to be the selected tab
expect(v2Tab).toHaveAttribute('aria-selected', 'true');
});

const groupSelect = canvas.getByLabelText('API-groep');
await selectEvent.select(groupSelect, 'Objects API group 1');

Expand Down Expand Up @@ -113,12 +122,21 @@ export const SwitchToV2Existing = {
},
},
play: async ({canvasElement}) => {
window.confirm = fn(() => true);
const canvas = within(canvasElement);

const v2Tab = canvas.getByRole('tab', {name: 'Variabelekoppelingen'});
await userEvent.click(v2Tab);

await waitFor(async () => {
// Close the confirmation modal
const confirmModal = await screen.findByRole('dialog');
const confirmButton = within(confirmModal).getByRole('button', {name: 'Accepteren'});
await userEvent.click(confirmButton);

// Expect v2Tab to be the selected tab
expect(v2Tab).toHaveAttribute('aria-selected', 'true');
});

const testForm = await canvas.findByTestId('test-form');

await waitFor(() => {
Expand Down Expand Up @@ -152,12 +170,21 @@ export const SwitchToV2NonExisting = {
},
},
play: async ({canvasElement}) => {
window.confirm = fn(() => true);
const canvas = within(canvasElement);

const v2Tab = canvas.getByRole('tab', {name: 'Variabelekoppelingen'});
await userEvent.click(v2Tab);

await waitFor(async () => {
// Close the confirmation modal
const confirmModal = await screen.findByRole('dialog');
const confirmButton = within(confirmModal).getByRole('button', {name: 'Accepteren'});
await userEvent.click(confirmButton);

// Expect v2Tab to be the selected tab
expect(v2Tab).toHaveAttribute('aria-selected', 'true');
});

const testForm = await canvas.findByTestId('test-form');
await waitFor(() => {
expect(testForm).toHaveFormValues({
Expand Down Expand Up @@ -189,12 +216,21 @@ export const APIFetchError = {
},
},
play: async ({canvasElement, step}) => {
window.confirm = fn(() => true);
const canvas = within(canvasElement);

const v2Tab = canvas.getByRole('tab', {name: 'Variabelekoppelingen'});
await userEvent.click(v2Tab);

await waitFor(async () => {
// Close the confirmation modal
const confirmModal = await screen.findByRole('dialog');
const confirmButton = within(confirmModal).getByRole('button', {name: 'Accepteren'});
await userEvent.click(confirmButton);

// Expect v2Tab to be the selected tab
expect(v2Tab).toHaveAttribute('aria-selected', 'true');
});

await step('Retrieving object types', async () => {
const groupSelect = canvas.getByLabelText('API-groep');
await selectEvent.select(groupSelect, 'Objects API group 1');
Expand Down

0 comments on commit 6004e0d

Please sign in to comment.