Skip to content

Commit

Permalink
Improve speed of test
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Nov 15, 2022
1 parent 6a883c4 commit 4a4b9e5
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions x-pack/plugins/cases/public/components/create/form_context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ const defaultPostPushToService = {
const fillFormReactTestingLib = async (renderResult: RenderResult) => {
const titleInput = within(renderResult.getByTestId('caseTitle')).getByTestId('input');

userEvent.type(titleInput, sampleData.title);
userEvent.paste(titleInput, sampleData.title);

const descriptionInput = renderResult.container.querySelector(
`[data-test-subj="caseDescription"] textarea`
const descriptionInput = within(renderResult.getByTestId('caseDescription')).getByTestId(
'textarea'
);

if (descriptionInput) {
userEvent.type(descriptionInput, sampleData.description);
userEvent.paste(descriptionInput, sampleData.description);
}

const caseTags = renderResult.getByTestId('caseTags');

for (let i = 0; i < sampleTags.length; i++) {
const tagsInput = await within(caseTags).findByTestId('comboBoxInput');
userEvent.type(tagsInput, `${sampleTags[i]}{enter}`);
userEvent.paste(tagsInput, `${sampleTags[i]}{enter}`);
}
};

Expand Down Expand Up @@ -262,15 +262,14 @@ describe('Create case', () => {
await waitForFormToRender(renderResult);

const titleInput = within(renderResult.getByTestId('caseTitle')).getByTestId('input');
await userEvent.type(titleInput, longTitle, { delay: 1 });
userEvent.paste(titleInput, longTitle);

userEvent.click(renderResult.getByTestId('create-case-submit'));
await waitForComponentToUpdate();

await waitFor(() => {
expect(
renderResult.getByText('The length of the title is too long. The maximum length is 160.')
).toBeInTheDocument();
});
expect(
renderResult.getByText('The length of the title is too long. The maximum length is 160.')
).toBeInTheDocument();

await waitForComponentToUpdate();
expect(postCase).not.toHaveBeenCalled();
Expand Down Expand Up @@ -531,9 +530,7 @@ describe('Create case', () => {
'comboBoxSearchInput'
);

await userEvent.type(checkbox, 'Denial of Service{enter}', {
delay: 1,
});
userEvent.paste(checkbox, 'Denial of Service{enter}');

userEvent.selectOptions(renderResult.getByTestId('severitySelect'), ['4']);
userEvent.click(renderResult.getByTestId('create-case-submit'));
Expand Down Expand Up @@ -955,7 +952,7 @@ describe('Create case', () => {
expect(assigneesComboBox.getByTestId('comboBoxSearchInput')).not.toBeDisabled();
});

userEvent.type(assigneesComboBox.getByTestId('comboBoxSearchInput'), 'dr');
userEvent.paste(assigneesComboBox.getByTestId('comboBoxSearchInput'), 'dr');

await waitFor(() => {
expect(
Expand Down

0 comments on commit 4a4b9e5

Please sign in to comment.