Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/4637 optional translations act as required #180

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

robinmolen
Copy link
Contributor

The translations of the option values where required because of a small issue in the zog validation configuration. This is now fixed

I've also added some tests to the componentConfigurations story, and to the stories of the individual components. Each story now has tests for the translation inputs. Ensuring that all translation inputs can be targeted, filled in, cleared and result in no errors.

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to see extensive testing being applied!

My general theme of feedback is about the existing tests and sync/async behaviours, which unfortunately is quite tied to exactly how one holds Storybook...

Another thing that caught my attention was the amount of commit messages - once the PR is ready for check-in, could you rebase the commits to be a bit more self-contained? E.g. commits for prettier can easily be squashed in their respective commits that do the bugfix/add the (regression) test/implement a feature.

In Open Forms we rely on the commit history really hard to debug and understand code, so it's important that we see "the useful" information in a git blame.

const inputs = editForm.getAllByRole('textbox');
for (let input of inputs) {
await userEvent.type(input, 'manualTranslation');
await expect(input).toHaveValue('manualTranslation');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect should not necessarily be await-ed. It shouldn't break anything, but it is a bit confusing. Typically it should be something like expect(await canvas.findByRole(...)).toBeVisible() to account for some rendering delays etc.

these existing tests are littered with bad examples, so I can hardly blame you for this.

await userEvent.type(input, 'manualTranslation');
await expect(input).toHaveValue('manualTranslation');
await userEvent.clear(input);
await expect(input).toHaveValue('');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await expect(input).toHaveValue('');
expect(input).toHaveValue('');

const inputs = editForm.getAllByRole('textbox');
for (let input of inputs) {
await userEvent.type(input, 'manualTranslation');
await expect(input).toHaveValue('manualTranslation');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await expect(input).toHaveValue('manualTranslation');
expect(input).toHaveValue('manualTranslation');

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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await expect(await editForm.queryByText('Required')).toBeNull();
expect(await editForm.queryByText('Required')).toBeNull();

expect(await canvas.findByText('EN')).toBeVisible();
expect(await canvas.findByText('Error code')).toBeVisible();

await waitFor(async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a bit strange that here the waitFor is needed, since the await canvas.findByLabelText(...) is already async and uses waitFor under the hood 🤔

I'd like to better understand if/what is going wrong in these interaction tests - often an actual root cause can be found.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the waitFor they keep failing locally..

Maybe this is again one of those situations that only fail locally, and that the CI will work fine..

Comment on lines 56 to 58
await waitFor(async () => {
await expect(
await canvas.findByText('The option label is a required field.')
).toBeVisible();
await expect(
await canvas.findByText('The option value is a required field.')
).toBeVisible();
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these often fail locally in storybook when you don't have focus on the browser window. could you check if they're really necessary? I can't really remember these tests failing in CI, while the file size validation tests are notable sources of flakiness

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a bit weird/scary that some tests (only) fail locally.. I'll check them out and remove the await's and waitFor's that aren't necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah... time for my weekly rant about the state of testing in JS-land I guess 😅

@robinmolen robinmolen force-pushed the issue/4637-optional-translations-act-as-required branch 4 times, most recently from 6623aa9 to 883f5a6 Compare September 24, 2024 15:14
@robinmolen robinmolen force-pushed the issue/4637-optional-translations-act-as-required branch from 883f5a6 to 3a98100 Compare September 24, 2024 15:28
@robinmolen robinmolen merged commit c768a2d into main Oct 2, 2024
13 checks passed
@robinmolen robinmolen deleted the issue/4637-optional-translations-act-as-required branch October 2, 2024 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Translations of checkboxes, radio & choice answers show as required when removed
3 participants