test: adapt role-conditions tests to new permission types
This commit is contained in:
@@ -14,98 +14,22 @@ export class AdminCreateRolePage extends AuthenticatedPage {
|
||||
this.nameInput = page.getByTestId('name-input');
|
||||
this.descriptionInput = page.getByTestId('description-input');
|
||||
this.createButton = page.getByTestId('create-button');
|
||||
this.connectionRow = page.getByTestId('Connection-permission-row');
|
||||
this.executionRow = page.getByTestId('Execution-permission-row');
|
||||
this.flowRow = page.getByTestId('Flow-permission-row');
|
||||
this.pageTitle = page.getByTestId('create-role-title');
|
||||
this.permissionsCatalog = page.getByTestId('permissions-catalog');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {('Connection'|'Execution'|'Flow')} subject
|
||||
*/
|
||||
getRoleConditionsModal(subject) {
|
||||
return new RoleConditionsModal(this.page, subject);
|
||||
}
|
||||
|
||||
async getPermissionConfigs() {
|
||||
const subjects = ['Connection', 'Flow', 'Execution'];
|
||||
const permissionConfigs = [];
|
||||
for (let subject of subjects) {
|
||||
const row = this.getSubjectRow(subject);
|
||||
const actionInputs = await this.getRowInputs(row);
|
||||
Object.keys(actionInputs).forEach((action) => {
|
||||
permissionConfigs.push({
|
||||
action,
|
||||
locator: actionInputs[action],
|
||||
subject,
|
||||
row,
|
||||
});
|
||||
});
|
||||
}
|
||||
return permissionConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {(
|
||||
* 'Connection' | 'Flow' | 'Execution'
|
||||
* )} subject
|
||||
*/
|
||||
getSubjectRow(subject) {
|
||||
const k = `${subject.toLowerCase()}Row`;
|
||||
if (this[k]) {
|
||||
return this[k];
|
||||
} else {
|
||||
throw 'Unknown row';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('@playwright/test').Locator} row
|
||||
*/
|
||||
async getRowInputs(row) {
|
||||
const inputs = {
|
||||
// settingsButton: row.getByTestId('permission-settings-button')
|
||||
};
|
||||
for (let input of ['create', 'read', 'update', 'delete', 'publish']) {
|
||||
const testId = `${input}-checkbox`;
|
||||
if ((await row.getByTestId(testId).count()) > 0) {
|
||||
inputs[input] = row.getByTestId(testId).locator('input');
|
||||
}
|
||||
}
|
||||
return inputs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('@playwright/test').Locator} row
|
||||
*/
|
||||
async clickPermissionSettings(row) {
|
||||
await row.getByTestId('permission-settings-button').click();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} subject
|
||||
* @param {'create'|'read'|'update'|'delete'|'publish'} action
|
||||
* @param {boolean} val
|
||||
*/
|
||||
async updateAction(subject, action, val) {
|
||||
const row = await this.getSubjectRow(subject);
|
||||
const inputs = await this.getRowInputs(row);
|
||||
if (inputs[action]) {
|
||||
if (await inputs[action].isChecked()) {
|
||||
if (!val) {
|
||||
await inputs[action].click();
|
||||
}
|
||||
} else {
|
||||
if (val) {
|
||||
await inputs[action].click();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new Error(`${subject} does not have action ${action}`);
|
||||
}
|
||||
this.connectionPermissionRow = page.getByTestId(
|
||||
'Connection-permission-row'
|
||||
);
|
||||
this.flowPermissionRow = page.getByTestId('Flow-permission-row');
|
||||
this.executionPermissionRow = page.getByTestId('Execution-permission-row');
|
||||
this.isCreatorReadCheckbox = page
|
||||
.getByTestId('isCreator-read-checkbox')
|
||||
.locator('input');
|
||||
this.readCheckbox = page.getByTestId('read-checkbox').locator('input');
|
||||
this.isCreatorManageCheckbox = page
|
||||
.getByTestId('isCreator-manage-checkbox')
|
||||
.locator('input');
|
||||
this.manageCheckbox = page.getByTestId('manage-checkbox').locator('input');
|
||||
}
|
||||
|
||||
async waitForPermissionsCatalogToVisible() {
|
||||
|
||||
@@ -1,69 +1,55 @@
|
||||
const { test, expect } = require('../../fixtures/index');
|
||||
|
||||
test(
|
||||
'Role permissions conform with role conditions ',
|
||||
async({ adminRolesPage, adminCreateRolePage }) => {
|
||||
await adminRolesPage.navigateTo();
|
||||
await adminRolesPage.createRoleButton.click();
|
||||
|
||||
/*
|
||||
example config: {
|
||||
action: 'read',
|
||||
subject: 'connection',
|
||||
row: page.getByTestId('connection-permission-row'),
|
||||
locator: row.getByTestId('read-checkbox')
|
||||
}
|
||||
*/
|
||||
const permissionConfigs =
|
||||
await adminCreateRolePage.getPermissionConfigs();
|
||||
test('Check Own permissions when All are checked', async ({
|
||||
adminRolesPage,
|
||||
adminCreateRolePage,
|
||||
}) => {
|
||||
await adminRolesPage.navigateTo();
|
||||
await adminRolesPage.createRoleButton.click();
|
||||
await adminCreateRolePage.waitForPermissionsCatalogToVisible();
|
||||
|
||||
await test.step(
|
||||
'Iterate over each permission config and make sure role conditions conform',
|
||||
async () => {
|
||||
for (let config of permissionConfigs) {
|
||||
await config.locator.click();
|
||||
await adminCreateRolePage.clickPermissionSettings(config.row);
|
||||
const modal = adminCreateRolePage.getRoleConditionsModal(
|
||||
config.subject
|
||||
);
|
||||
await expect(modal.modal).toBeVisible();
|
||||
const conditions = await modal.getAvailableConditions();
|
||||
for (let conditionAction of Object.keys(conditions)) {
|
||||
if (conditionAction === config.action) {
|
||||
await expect(conditions[conditionAction]).not.toBeDisabled();
|
||||
} else {
|
||||
await expect(conditions[conditionAction]).toBeDisabled();
|
||||
}
|
||||
}
|
||||
await modal.close();
|
||||
await config.locator.click();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
await adminCreateRolePage.connectionPermissionRow
|
||||
.locator(adminCreateRolePage.readCheckbox)
|
||||
.check();
|
||||
await expect(
|
||||
adminCreateRolePage.connectionPermissionRow.locator(
|
||||
adminCreateRolePage.isCreatorReadCheckbox
|
||||
)
|
||||
).toBeChecked();
|
||||
|
||||
test(
|
||||
'Default role permissions conforms with role conditions',
|
||||
async({ adminRolesPage, adminCreateRolePage }) => {
|
||||
await adminRolesPage.navigateTo();
|
||||
await adminRolesPage.createRoleButton.click();
|
||||
await adminCreateRolePage.flowPermissionRow
|
||||
.locator(adminCreateRolePage.readCheckbox)
|
||||
.check();
|
||||
await expect(
|
||||
adminCreateRolePage.flowPermissionRow.locator(
|
||||
adminCreateRolePage.isCreatorReadCheckbox
|
||||
)
|
||||
).toBeChecked();
|
||||
|
||||
const subjects = ['Connection', 'Execution', 'Flow'];
|
||||
for (let subject of subjects) {
|
||||
const row = adminCreateRolePage.getSubjectRow(subject);
|
||||
const modal = adminCreateRolePage.getRoleConditionsModal(subject);
|
||||
await adminCreateRolePage.clickPermissionSettings(row);
|
||||
await expect(modal.modal).toBeVisible();
|
||||
const availableConditions = await modal.getAvailableConditions();
|
||||
const conditions = ['create', 'read', 'update', 'delete', 'publish'];
|
||||
for (let condition of conditions) {
|
||||
if (availableConditions[condition]) {
|
||||
await expect(availableConditions[condition]).toBeDisabled();
|
||||
}
|
||||
}
|
||||
await modal.close();
|
||||
}
|
||||
await adminCreateRolePage.executionPermissionRow
|
||||
.locator(adminCreateRolePage.readCheckbox)
|
||||
.check();
|
||||
await expect(
|
||||
adminCreateRolePage.executionPermissionRow.locator(
|
||||
adminCreateRolePage.isCreatorReadCheckbox
|
||||
)
|
||||
).toBeChecked();
|
||||
|
||||
}
|
||||
);
|
||||
await adminCreateRolePage.connectionPermissionRow
|
||||
.locator(adminCreateRolePage.manageCheckbox)
|
||||
.check();
|
||||
await expect(
|
||||
adminCreateRolePage.connectionPermissionRow.locator(
|
||||
adminCreateRolePage.isCreatorManageCheckbox
|
||||
)
|
||||
).toBeChecked();
|
||||
|
||||
await adminCreateRolePage.flowPermissionRow
|
||||
.locator(adminCreateRolePage.manageCheckbox)
|
||||
.check();
|
||||
await expect(
|
||||
adminCreateRolePage.flowPermissionRow.locator(
|
||||
adminCreateRolePage.isCreatorManageCheckbox
|
||||
)
|
||||
).toBeChecked();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user