Skip to content

Commit

Permalink
[Cases] Remove e2e test for trimming fields (#165867)
Browse files Browse the repository at this point in the history
## Summary

This PR removes trim fields tests of create case from functional tests
and add it to unit test

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
js-jankisalvi and kibanamachine authored Sep 7, 2023
1 parent 7e96434 commit eb0317d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,49 @@ describe('Create case', () => {
});
});

it('should trim fields correctly while submit', async () => {
const newTags = ['coke ', ' pepsi'];
const newCategory = 'First ';

appMockRender.render(
<FormContext onSuccess={onFormSubmitSuccess}>
<CreateCaseFormFields {...defaultCreateCaseForm} />
<SubmitCaseButton />
</FormContext>
);

await waitForFormToRender(screen);

const titleInput = within(screen.getByTestId('caseTitle')).getByTestId('input');

userEvent.paste(titleInput, `${sampleDataWithoutTags.title} `);

const descriptionInput = within(screen.getByTestId('caseDescription')).getByTestId(
'euiMarkdownEditorTextArea'
);

userEvent.paste(descriptionInput, `${sampleDataWithoutTags.description} `);

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

for (const tag of newTags) {
const tagsInput = await within(caseTags).findByTestId('comboBoxInput');
userEvent.type(tagsInput, `${tag}{enter}`);
}

const categoryComboBox = within(screen.getByTestId('categories-list')).getByRole('combobox');

userEvent.type(categoryComboBox, `${newCategory}{enter}`);

userEvent.click(screen.getByTestId('create-case-submit'));

await waitFor(() => {
expect(postCase).toHaveBeenCalled();
});

expect(postCase).toBeCalledWith({ request: { ...sampleData, category: 'First' } });
});

it('should toggle sync settings', async () => {
useGetConnectorsMock.mockReturnValue({
...sampleConnectorData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,39 +99,6 @@ export default ({ getService, getPageObject }: FtrProviderContext) => {
);
});

it('trims fields correctly while creating a case', async () => {
const titleWithSpace = 'This is a title with spaces ';
const descriptionWithSpace =
'This is a case description with empty spaces at the end!! ';
const categoryWithSpace = 'security ';
const tagWithSpace = 'coke ';

await cases.create.openCreateCasePage();
await cases.create.createCase({
title: titleWithSpace,
description: descriptionWithSpace,
tag: tagWithSpace,
severity: CaseSeverity.HIGH,
category: categoryWithSpace,
});

// validate title is trimmed
const title = await find.byCssSelector('[data-test-subj="editable-title-header-value"]');
expect(await title.getVisibleText()).equal(titleWithSpace.trim());

// validate description is trimmed
const description = await testSubjects.find('scrollable-markdown');
expect(await description.getVisibleText()).equal(descriptionWithSpace.trim());

// validate tag exists and is trimmed
const tag = await testSubjects.find(`tag-${tagWithSpace.trim()}`);
expect(await tag.getVisibleText()).equal(tagWithSpace.trim());

// validate category exists and is trimmed
const category = await testSubjects.find(`category-viewer-${categoryWithSpace.trim()}`);
expect(await category.getVisibleText()).equal(categoryWithSpace.trim());
});

describe('Assignees', function () {
before(async () => {
await createUsersAndRoles(getService, users, roles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,75 +64,5 @@ export default ({ getService, getPageObject }: FtrProviderContext) => {
const button = await find.byCssSelector('[data-test-subj*="case-callout"] button');
expect(await button.getVisibleText()).equal('Add connector');
});

it('displays errors correctly while creating a case', async () => {
const caseTitle = Array(161).fill('x').toString();
const longTag = Array(256).fill('a').toString();
const longCategory = Array(51).fill('x').toString();

await cases.create.openCreateCasePage();
await cases.create.createCase({
title: caseTitle,
description: '',
tag: longTag,
severity: CaseSeverity.HIGH,
category: longCategory,
});

await testSubjects.click('create-case-submit');

const title = await find.byCssSelector('[data-test-subj="caseTitle"]');
expect(await title.getVisibleText()).contain(
'The length of the name is too long. The maximum length is 160 characters.'
);

const description = await testSubjects.find('caseDescription');
expect(await description.getVisibleText()).contain('A description is required.');

const tags = await testSubjects.find('caseTags');
expect(await tags.getVisibleText()).contain(
'The length of the tag is too long. The maximum length is 256 characters.'
);

const category = await testSubjects.find('case-create-form-category');
expect(await category.getVisibleText()).contain(
'The length of the category is too long. The maximum length is 50 characters.'
);
});

it('trims fields correctly while creating a case', async () => {
const titleWithSpace = 'This is a title with spaces ';
const descriptionWithSpace =
'This is a case description with empty spaces at the end!! ';
const categoryWithSpace = 'security ';
const tagWithSpace = 'coke ';

await cases.create.openCreateCasePage();
await cases.create.createCase({
title: titleWithSpace,
description: descriptionWithSpace,
tag: tagWithSpace,
severity: CaseSeverity.HIGH,
category: categoryWithSpace,
});

await testSubjects.click('create-case-submit');

// validate title is trimmed
const title = await find.byCssSelector('[data-test-subj="editable-title-header-value"]');
expect(await title.getVisibleText()).equal(titleWithSpace.trim());

// validate description is trimmed
const description = await testSubjects.find('scrollable-markdown');
expect(await description.getVisibleText()).equal(descriptionWithSpace.trim());

// validate tag exists and is trimmed
const tag = await testSubjects.find(`tag-${tagWithSpace.trim()}`);
expect(await tag.getVisibleText()).equal(tagWithSpace.trim());

// validate category exists and is trimmed
const category = await testSubjects.find(`category-viewer-${categoryWithSpace.trim()}`);
expect(await category.getVisibleText()).equal(categoryWithSpace.trim());
});
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -64,75 +64,5 @@ export default ({ getService, getPageObject }: FtrProviderContext) => {
const button = await find.byCssSelector('[data-test-subj*="case-callout"] button');
expect(await button.getVisibleText()).equal('Add connector');
});

it('displays errors correctly while creating a case', async () => {
const caseTitle = Array(161).fill('x').toString();
const longTag = Array(256).fill('a').toString();
const longCategory = Array(51).fill('x').toString();

await cases.create.openCreateCasePage();
await cases.create.createCase({
title: caseTitle,
description: '',
tag: longTag,
severity: CaseSeverity.HIGH,
category: longCategory,
});

await testSubjects.click('create-case-submit');

const title = await find.byCssSelector('[data-test-subj="caseTitle"]');
expect(await title.getVisibleText()).contain(
'The length of the name is too long. The maximum length is 160 characters.'
);

const description = await testSubjects.find('caseDescription');
expect(await description.getVisibleText()).contain('A description is required.');

const tags = await testSubjects.find('caseTags');
expect(await tags.getVisibleText()).contain(
'The length of the tag is too long. The maximum length is 256 characters.'
);

const category = await testSubjects.find('case-create-form-category');
expect(await category.getVisibleText()).contain(
'The length of the category is too long. The maximum length is 50 characters.'
);
});

it('trims fields correctly while creating a case', async () => {
const titleWithSpace = 'This is a title with spaces ';
const descriptionWithSpace =
'This is a case description with empty spaces at the end!! ';
const categoryWithSpace = 'security ';
const tagWithSpace = 'coke ';

await cases.create.openCreateCasePage();
await cases.create.createCase({
title: titleWithSpace,
description: descriptionWithSpace,
tag: tagWithSpace,
severity: CaseSeverity.HIGH,
category: categoryWithSpace,
});

await testSubjects.click('create-case-submit');

// validate title is trimmed
const title = await find.byCssSelector('[data-test-subj="editable-title-header-value"]');
expect(await title.getVisibleText()).equal(titleWithSpace.trim());

// validate description is trimmed
const description = await testSubjects.find('scrollable-markdown');
expect(await description.getVisibleText()).equal(descriptionWithSpace.trim());

// validate tag exists and is trimmed
const tag = await testSubjects.find(`tag-${tagWithSpace.trim()}`);
expect(await tag.getVisibleText()).equal(tagWithSpace.trim());

// validate category exists and is trimmed
const category = await testSubjects.find(`category-viewer-${categoryWithSpace.trim()}`);
expect(await category.getVisibleText()).equal(categoryWithSpace.trim());
});
});
};

0 comments on commit eb0317d

Please sign in to comment.