Skip to content

Commit 78dd068

Browse files
committed
✅ [#4871] Storybook tests for variableMapping and evaluate DMN with errors
1 parent 7691adf commit 78dd068

File tree

2 files changed

+135
-2
lines changed

2 files changed

+135
-2
lines changed

src/openforms/js/components/admin/form_design/logic/actions/Action.stories.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {useArgs} from '@storybook/preview-api';
2+
import {expect, userEvent, waitFor, within} from '@storybook/test';
23
import {produce} from 'immer';
34
import set from 'lodash/set';
45

@@ -197,3 +198,96 @@ export const EvaluateDMN = {
197198
},
198199
},
199200
};
201+
202+
export const EvaluateDMNWithInitialErrors = {
203+
render,
204+
name: 'Evaluate DMN with initial errors',
205+
args: {
206+
prefixText: 'Action',
207+
208+
action: {
209+
component: '',
210+
variable: 'bar',
211+
formStep: '',
212+
formStepUuid: '',
213+
214+
action: {
215+
config: {
216+
pluginId: '',
217+
decisionDefinitionId: '',
218+
},
219+
type: 'evaluate-dmn',
220+
value: '',
221+
},
222+
},
223+
errors: {
224+
action: {
225+
config: {
226+
pluginId: 'This field is required.',
227+
decisionDefinitionId: 'This field is required.',
228+
},
229+
},
230+
},
231+
availableDMNPlugins: [
232+
{id: 'camunda7', label: 'Camunda 7'},
233+
{id: 'some-other-engine', label: 'Some other engine'},
234+
],
235+
availableFormVariables: [
236+
{type: 'textfield', key: 'name', name: 'Name'},
237+
{type: 'textfield', key: 'surname', name: 'Surname'},
238+
{type: 'number', key: 'income', name: 'Income'},
239+
{type: 'checkbox', key: 'canApply', name: 'Can apply?'},
240+
],
241+
},
242+
decorators: [FormDecorator],
243+
244+
parameters: {
245+
msw: {
246+
handlers: [
247+
mockDMNDecisionDefinitionsGet({
248+
camunda7: [
249+
{
250+
id: 'approve-payment',
251+
label: 'Approve payment',
252+
},
253+
{
254+
id: 'invoiceClassification',
255+
label: 'Invoice Classification',
256+
},
257+
],
258+
'some-other-engine': [{id: 'some-definition-id', label: 'Some definition id'}],
259+
}),
260+
mockDMNDecisionDefinitionVersionsGet,
261+
],
262+
},
263+
},
264+
play: async ({canvasElement, step}) => {
265+
const canvas = within(canvasElement);
266+
267+
step('Verify that global DMN config error is shown', () => {
268+
expect(
269+
canvas.getByRole('listitem', {text: 'De DMN-instellingen zijn niet geldig.'})
270+
).toBeVisible();
271+
});
272+
273+
step('Open configuration modal', async () => {
274+
await userEvent.click(canvas.getByRole('button', {name: 'Instellen'}));
275+
276+
const dialog = within(canvas.getByRole('dialog'));
277+
278+
const pluginDropdown = dialog.getByLabelText('Plugin');
279+
const decisionDefDropdown = dialog.getByLabelText('Beslisdefinitie-ID');
280+
281+
// Mark dropdowns as touched
282+
await userEvent.click(pluginDropdown);
283+
await userEvent.click(decisionDefDropdown);
284+
await userEvent.tab();
285+
286+
await waitFor(async () => {
287+
const errorMessages = await dialog.getAllByRole('listitem');
288+
289+
await expect(errorMessages.length).toBe(2);
290+
});
291+
});
292+
},
293+
};

src/openforms/js/components/admin/forms/VariableMapping.stories.js

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import {expect, fn, userEvent, within} from '@storybook/test';
22
import selectEvent from 'react-select-event';
33

4-
import {FormDecorator, FormikDecorator} from 'components/admin/form_design/story-decorators';
4+
import {
5+
FormDecorator,
6+
FormikDecorator,
7+
ValidationErrorsDecorator,
8+
} from 'components/admin/form_design/story-decorators';
59
import {VARIABLE_SOURCES} from 'components/admin/form_design/variables/constants';
610
import {findReactSelectMenu} from 'utils/storybookTestHelpers';
711

@@ -10,7 +14,7 @@ import VariableMapping, {serializeValue} from './VariableMapping';
1014
export default {
1115
title: 'Form design/VariableMapping',
1216
component: VariableMapping,
13-
decorators: [FormikDecorator, FormDecorator],
17+
decorators: [FormikDecorator, ValidationErrorsDecorator, FormDecorator],
1418

1519
parameters: {
1620
formik: {
@@ -224,3 +228,38 @@ export const OmitAlreadyMappedValues = {
224228
});
225229
},
226230
};
231+
232+
export const WithValidationErrors = {
233+
render: args => (
234+
<>
235+
<VariableMapping {...args} />
236+
<button type="submit">Submit</button>
237+
</>
238+
),
239+
240+
args: {
241+
propertyChoices: [
242+
[['nested', 'property'], 'Nested > property'],
243+
[['otherProperty'], 'Other property'],
244+
],
245+
},
246+
247+
parameters: {
248+
formik: {
249+
initialValues: {
250+
mapping: [{formVariable: 'key2'}, {formVariable: 'key2', property: ['otherProperty']}, {}],
251+
},
252+
onSubmit: fn(),
253+
},
254+
validationErrors: [
255+
[
256+
'mapping',
257+
[
258+
{property: 'This field may not be blank.'},
259+
undefined,
260+
{formVariable: 'This field may not be blank.', property: 'This field may not be blank.'},
261+
],
262+
],
263+
],
264+
},
265+
};

0 commit comments

Comments
 (0)