Skip to content

Commit

Permalink
✅ [open-formulieren/open-forms#4637] Added translation tests to radio…
Browse files Browse the repository at this point in the history
…, select and selectboxes component tests
  • Loading branch information
robinmolen committed Sep 24, 2024
1 parent 1c748fa commit 6d76da5
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/registry/radio/radio-validation.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,30 @@ export const ManualMinimumOneValue: Story = {
});
},
};

export const TranslationsArentRequired: Story = {
name: 'Translations: translations aren\'t required fields',
play: async ({canvasElement, step}) => {
const canvas = within(canvasElement);

await step('Translations aren\'t required fields', async () => {
await userEvent.click(canvas.getByRole('tab', {name: 'Translations'}));
const editForm = within(canvas.getByTestId('componentEditForm'));

// Check that all translations can be filled
const inputs = editForm.getAllByRole('textbox');
for (let input of inputs) {
await userEvent.type(input, 'manualTranslation');
await expect(input).toHaveValue('manualTranslation');
await userEvent.clear(input);
await expect(input).toHaveValue('');
}

// Removing focus from the last input
await userEvent.click(canvas.getByRole('tab', {name: 'Translations'}));

// Check that none of the inputs have a Required error message
await expect(await editForm.queryByText('Required')).toBeNull();
});
},
};
57 changes: 57 additions & 0 deletions src/registry/select/select-validation.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event';

import ComponentEditForm from '@/components/ComponentEditForm';
import {contextRender, screen} from '@/tests/test-utils';
import {expect, within} from '@storybook/test';

beforeAll(() => {
jest.useFakeTimers();
Expand Down Expand Up @@ -96,3 +97,59 @@ test('There is always at least one option', async () => {
const firstValueLabel = await screen.findByTestId('input-data.values[0].label');
expect(firstValueLabel).toBeVisible();
});

test('All translations are optional', async () => {
const user = userEvent.setup({advanceTimers: jest.advanceTimersByTime});
const onSubmit = jest.fn();
const component = {
id: 'wqimsadk',
type: 'select',
key: 'select',
label: 'A select field',
dataSrc: 'values',
openForms: {
dataSrc: 'manual',
translations: {},
},
data: {
values: [],
},
defaultValue: '',
} satisfies SelectComponentSchema;

const builderInfo = {
title: 'Select',
icon: 'th-list',
group: 'basic',
weight: 70,
schema: {},
};
contextRender(
<ComponentEditForm
isNew
component={component}
builderInfo={builderInfo}
onCancel={jest.fn()}
onRemove={jest.fn()}
onSubmit={onSubmit}
/>
);

await user.click(screen.getByRole('tab', {name: 'Translations'}));
const editForm = within(screen.getByTestId('componentEditForm'));

// Check that all translations can be filled
const inputs = editForm.getAllByRole('textbox');
for (let input of inputs) {
await user.type(input, 'manualTranslation');
await expect(input).toHaveValue('manualTranslation');
await user.clear(input);
await expect(input).toHaveValue('');
}

// Removing focus from the last input
await user.click(screen.getByRole('tab', {name: 'Translations'}));

// Check that none of the inputs have a Required error message
await expect(await editForm.queryByText('Required')).toBeNull();
});
27 changes: 27 additions & 0 deletions src/registry/selectboxes/selectboxes-validation.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,33 @@ export const ManualMinimumOneValue: Story = {
},
};

export const TranslationsArentRequired: Story = {
name: 'Translations: translations aren\'t required fields',
play: async ({canvasElement, step}) => {
const canvas = within(canvasElement);

await step('Translations aren\'t required fields', async () => {
await userEvent.click(canvas.getByRole('tab', {name: 'Translations'}));
const editForm = within(canvas.getByTestId('componentEditForm'));

// Check that all translations can be filled
const inputs = editForm.getAllByRole('textbox');
for (let input of inputs) {
await userEvent.type(input, 'manualTranslation');
await expect(input).toHaveValue('manualTranslation');
await userEvent.clear(input);
await expect(input).toHaveValue('');
}

// Removing focus from the last input
await userEvent.click(canvas.getByRole('tab', {name: 'Translations'}));

// Check that none of the inputs have a Required error message
await expect(await editForm.queryByText('Required')).toBeNull();
});
},
};

export const MinAndMaxSelectedInitialValues: Story = {
name: 'Initial min and max count',
args: {
Expand Down

0 comments on commit 6d76da5

Please sign in to comment.