Skip to content

Commit

Permalink
simplify security pageobject logic
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Jun 11, 2020
1 parent 74cff41 commit e370012
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions x-pack/test/functional/page_objects/security_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,38 +410,32 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider
await comboBox.setCustom('indicesInput0', indexName);
}

await testSubjects.click('restrictDocumentsQuery0');

if (roleObj.elasticsearch.indices[0].query) {
await testSubjects.click('restrictDocumentsQuery0');
await testSubjects.setValue('queryInput0', roleObj.elasticsearch.indices[0].query);
}

const globalPrivileges = (roleObj.kibana as any).global;
if (globalPrivileges) {
for (const privilegeName of globalPrivileges) {
const button = await testSubjects.find('addSpacePrivilegeButton');
await button.click();
await testSubjects.click('addSpacePrivilegeButton');

const spaceSelector = await testSubjects.find('spaceSelectorComboBox');
await spaceSelector.click();
await testSubjects.click('spaceSelectorComboBox');

const globalSpaceOption = await find.byCssSelector(`#spaceOption_\\*`);
await globalSpaceOption.click();

const basePrivilegeSelector = await testSubjects.find('basePrivilegeComboBox');
await basePrivilegeSelector.click();
await testSubjects.click('basePrivilegeComboBox');

const privilegeOption = await find.byCssSelector(`#basePrivilege_${privilegeName}`);
await privilegeOption.click();

const createPrivilegeButton = await testSubjects.find('createSpacePrivilegeButton');
await createPrivilegeButton.click();
await testSubjects.click('createSpacePrivilegeButton');
}
}

function addPrivilege(privileges: string[]) {
return privileges.reduce(function (promise: Promise<any>, privilegeName: string) {
// We have to use non-test-subject selectors because this markup is generated by ui-select.
return promise
.then(() => self.addPrivilegeToRole(privilegeName))
.then(() => PageObjects.common.sleep(250));
Expand All @@ -450,16 +444,10 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider

await addPrivilege(roleObj.elasticsearch.indices[0].privileges);

function addGrantedField(field: string[]) {
return field.reduce(function (promise: Promise<any>, fieldName: string) {
return promise
.then(function () {
return comboBox.setCustom('fieldInput0', fieldName);
})
.then(function () {
return PageObjects.common.sleep(1000);
});
}, Promise.resolve());
async function addGrantedField(fields: string[]) {
for (const entry of fields) {
await comboBox.setCustom('fieldInput0', entry);
}
}

// clicking the Granted fields and removing the asterix
Expand All @@ -468,19 +456,19 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider
await testSubjects.click('restrictFieldsQuery0');

// have to remove the '*'
return find
.clickByCssSelector(
'div[data-test-subj="fieldInput0"] [title="Remove * from selection in this group"] svg.euiIcon'
)
.then(function () {
return addGrantedField(roleObj.elasticsearch.indices[0].field_security!.grant!);
});
await find.clickByCssSelector(
'div[data-test-subj="fieldInput0"] [title="Remove * from selection in this group"] svg.euiIcon'
);

await addGrantedField(roleObj.elasticsearch.indices[0].field_security!.grant!);
}

log.debug('click save button');
await testSubjects.click('roleFormSaveButton');

return PageObjects.common.sleep(5000);
// Signifies that the role managemet page redirected back to the role grid page,
// and successfully refreshed the grid
await testSubjects.existOrFail('roleRow');
}

async selectRole(role: string) {
Expand Down

0 comments on commit e370012

Please sign in to comment.