Skip to content

Commit

Permalink
[Cases] Add e2e test for assigning users when creating a case (#142939)
Browse files Browse the repository at this point in the history
* Add assign users while creating page  e2e test

* Fix tests

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
cnasikas and kibanamachine authored Oct 11, 2022
1 parent 2b0cde2 commit 193a37d
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 32 deletions.
9 changes: 9 additions & 0 deletions x-pack/test/functional/services/cases/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,14 @@ export function CasesCommonServiceProvider({ getService, getPageObject }: FtrPro
await (await find.byClassName('euiSelectableListItem__content')).click();
await header.waitUntilLoadingHasFinished();
},

async selectAllRowsInAssigneesPopover() {
const rows = await find.allByCssSelector('.euiSelectableListItem__content');
for (const row of rows) {
await row.click();
}

await header.waitUntilLoadingHasFinished();
},
};
}
47 changes: 30 additions & 17 deletions x-pack/test/functional/services/cases/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CreateCaseParams {
tag?: string;
severity?: CaseSeverity;
owner?: string;
assignees?: [];
}

export function CasesCreateViewServiceProvider(
Expand Down Expand Up @@ -55,38 +56,50 @@ export function CasesCreateViewServiceProvider(
severity = CaseSeverity.LOW,
owner,
}: CreateCaseParams) {
await this.setCaseTitle(title);

await this.setCaseTags(tag);

// case description
const descriptionArea = await find.byCssSelector('textarea.euiMarkdownEditorTextArea');
await descriptionArea.focus();
await descriptionArea.type(description);
await this.setTitle(title);
await this.setDescription(description);
await this.setTags(tag);

if (severity !== CaseSeverity.LOW) {
await common.clickAndValidate(
'case-severity-selection',
`case-severity-selection-${severity}`
);
await this.setSeverity(severity);
}

if (owner) {
await testSubjects.click(`${owner}RadioButton`);
await this.setSolution(owner);
}

// save
await testSubjects.click('create-case-submit');
await this.submitCase();
},

async setCaseTitle(title: string) {
async setTitle(title: string) {
await testSubjects.setValue('input', title);
},

async setCaseTags(tag: string) {
async setDescription(description: string) {
const descriptionArea = await find.byCssSelector('textarea.euiMarkdownEditorTextArea');
await descriptionArea.focus();
await descriptionArea.type(description);
},

async setTags(tag: string) {
await comboBox.setCustom('caseTags', tag);
},

async setSolution(owner: string) {
await testSubjects.click(`${owner}RadioButton`);
},

async setSeverity(severity: CaseSeverity) {
await common.clickAndValidate(
'case-severity-selection',
`case-severity-selection-${severity}`
);
},

async submitCase() {
await testSubjects.click('create-case-submit');
},

async assertCreateCaseFlyoutVisible(expectVisible = true) {
await retry.tryForTime(5000, async () => {
if (expectVisible) {
Expand Down
8 changes: 6 additions & 2 deletions x-pack/test/functional/services/cases/single_case_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ export function CasesSingleViewServiceProvider({ getService, getPageObject }: Ft
},

async closeAssigneesPopover() {
await testSubjects.click('case-refresh');
await header.waitUntilLoadingHasFinished();
await retry.try(async () => {
// Click somewhere outside the popover
await testSubjects.click('header-page-title');
await header.waitUntilLoadingHasFinished();
await testSubjects.missingOrFail('euiSelectableList');
});
},
};
}
39 changes: 37 additions & 2 deletions x-pack/test/functional_with_es_ssl/apps/cases/create_case_form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@ import expect from '@kbn/expect';
import uuid from 'uuid';
import { CaseSeverity } from '@kbn/cases-plugin/common/api';
import { FtrProviderContext } from '../../ftr_provider_context';
import {
createUsersAndRoles,
deleteUsersAndRoles,
} from '../../../cases_api_integration/common/lib/authentication';
import { users, roles, casesAllUser, casesAllUser2 } from './common';

export default ({ getService }: FtrProviderContext) => {
export default ({ getService, getPageObject }: FtrProviderContext) => {
describe('Create case', function () {
const find = getService('find');
const cases = getService('cases');
const testSubjects = getService('testSubjects');
const config = getService('config');
const comboBox = getService('comboBox');
const header = getPageObject('header');

before(async () => {
beforeEach(async () => {
await cases.navigation.navigateToApp();
});

Expand Down Expand Up @@ -54,5 +61,33 @@ export default ({ getService }: FtrProviderContext) => {
const button = await find.byCssSelector('[data-test-subj*="case-callout"] button');
expect(await button.getVisibleText()).equal('Add connector');
});

describe('Assignees', function () {
before(async () => {
await createUsersAndRoles(getService, users, roles);
await cases.api.activateUserProfiles([casesAllUser, casesAllUser2]);
});

after(async () => {
await deleteUsersAndRoles(getService, users, roles);
});

it('creates a case with assignees', async () => {
const caseTitle = 'test-' + uuid.v4();
await cases.create.openCreateCasePage();

await cases.create.setTitle(caseTitle);
await comboBox.set('createCaseAssigneesComboBox', 'cases_all_user');
await comboBox.set('createCaseAssigneesComboBox', 'cases_all_user2');
await cases.create.setDescription('my description');

await cases.create.submitCase();

await header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('case-view-title');
await testSubjects.existOrFail('user-profile-assigned-user-group-cases_all_user');
await testSubjects.existOrFail('user-profile-assigned-user-group-cases_all_user2');
});
});
});
};
18 changes: 11 additions & 7 deletions x-pack/test/functional_with_es_ssl/apps/cases/list_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,18 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
await cases.casesTable.validateCasesTableHasNthRows(1);
});

it('filters cases by the first cases all user assignee', async () => {
await cases.casesTable.filterByAssignee('all');
await cases.casesTable.validateCasesTableHasNthRows(1);
});
describe('assignees filtering', () => {
it('filters cases by the first cases all user assignee', async () => {
await cases.casesTable.filterByAssignee('all');
await cases.casesTable.validateCasesTableHasNthRows(1);
await testSubjects.exists('case-user-profile-avatar-cases_all_user');
});

it('filters cases by the casesAllUser2 assignee', async () => {
await cases.casesTable.filterByAssignee('2');
await cases.casesTable.validateCasesTableHasNthRows(1);
it('filters cases by the casesAllUser2 assignee', async () => {
await cases.casesTable.filterByAssignee('2');
await cases.casesTable.validateCasesTableHasNthRows(1);
await testSubjects.exists('case-user-profile-avatar-cases_all_user2');
});
});
});

Expand Down
19 changes: 15 additions & 4 deletions x-pack/test/functional_with_es_ssl/apps/cases/view_case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,27 +256,38 @@ export default ({ getPageObject, getService }: FtrProviderContext) => {
});

describe('logs in with default user', () => {
createOneCaseBeforeDeleteAllAfter(getPageObject, getService);
beforeEach(async () => {
await createAndNavigateToCase(getPageObject, getService);
});

afterEach(async () => {
await cases.singleCase.closeAssigneesPopover();
await cases.api.deleteAllCases();
});

it('shows the assign users popover when clicked', async () => {
await testSubjects.missingOrFail('euiSelectableList');

await cases.singleCase.openAssigneesPopover();
await cases.singleCase.closeAssigneesPopover();
});

it('assigns a user from the popover', async () => {
await cases.singleCase.openAssigneesPopover();
await cases.common.setSearchTextInAssigneesPopover('case');
await cases.common.selectFirstRowInAssigneesPopover();
await cases.singleCase.closeAssigneesPopover();
await header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('user-profile-assigned-user-group-cases_all_user');
});

it('assigns multiple users', async () => {
await cases.singleCase.openAssigneesPopover();
await cases.common.setSearchTextInAssigneesPopover('case');
await cases.common.selectAllRowsInAssigneesPopover();

// navigate out of the modal
await cases.singleCase.closeAssigneesPopover();
await header.waitUntilLoadingHasFinished();
await testSubjects.existOrFail('user-profile-assigned-user-group-cases_all_user');
await testSubjects.existOrFail('user-profile-assigned-user-group-cases_all_user2');
});
});

Expand Down

0 comments on commit 193a37d

Please sign in to comment.