Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAT-16776-C554636 #4278

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import Users from '../../../support/fragments/users/users';
import TopMenu from '../../../support/fragments/topMenu';
import getRandomPostfix from '../../../support/utils/stringTools';
import AuthorizationRoles from '../../../support/fragments/settings/authorization-roles/authorizationRoles';
import InteractorsTools from '../../../support/utils/interactorsTools';
import { calloutTypes } from '../../../../interactors';

describe('Eureka', () => {
describe('Settings', () => {
describe('Authorization roles', () => {
const testData = {
roleName: `Original role C554635 ${getRandomPostfix()}`,
calloutText: 'error while duplicating',
};

const capabSetsToAssign = [
{ type: 'Settings', resource: 'UI-Authorization-Roles Settings Admin', action: 'View' },
];

const capabsToAssign = [{ type: 'Settings', resource: 'Settings Enabled', action: 'View' }];

before(() => {
cy.createTempUser([]).then((createdUserProperties) => {
testData.user = createdUserProperties;
cy.assignCapabilitiesToExistingUser(
testData.user.userId,
capabsToAssign,
capabSetsToAssign,
);
if (Cypress.env('runAsAdmin')) cy.updateRolesForUserApi(testData.user.userId, []);
cy.createAuthorizationRoleApi(testData.roleName).then((role) => {
testData.roleId = role.id;
cy.getCapabilitiesApi(2).then((capabs) => {
cy.getCapabilitySetsApi(2).then((capabSets) => {
cy.getUserRoleIdByNameApi(testData.roleName).then((roleId) => {
testData.roleId = roleId;
cy.addCapabilitiesToNewRoleApi(
roleId,
capabs.map((capab) => capab.id),
);
cy.addCapabilitySetsToNewRoleApi(
roleId,
capabSets.map((capab) => capab.id),
);
cy.addRolesToNewUserApi(createdUserProperties.userId, [roleId]);
});
});
});
cy.login(testData.user.username, testData.user.password, {
path: TopMenu.settingsAuthorizationRoles,
waiter: AuthorizationRoles.waitContentLoading,
});
});
});
});

afterEach(() => {
cy.getAdminToken();
Users.deleteViaApi(testData.user.userId);
cy.deleteAuthorizationRoleApi(testData.roleId, true);
});

it(
'C554635 Eureka | User with insufficient capabilities can not duplicate an authorization role (thunderjet)',
{ tags: ['extendedPath', 'thunderjet'] },
() => {
AuthorizationRoles.searchRole(testData.roleName);
AuthorizationRoles.clickOnRoleName(testData.roleName, false);
AuthorizationRoles.clickActionsButton();
// TO DO: uncomment the next line after UIROLES-112 and UIROLES-58 implementation
// AuthorizationRoles.checkDuplicateOptionShown(false);
AuthorizationRoles.clickDuplicateButton();
AuthorizationRoles.confirmDuplicateRole();
InteractorsTools.checkCalloutContainsMessage(testData.calloutText, calloutTypes.error);
},
);
});
});
});
142 changes: 142 additions & 0 deletions cypress/e2e/eureka/authorization-roles/duplicate-role.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import Users from '../../../support/fragments/users/users';
import TopMenu from '../../../support/fragments/topMenu';
import getRandomPostfix from '../../../support/utils/stringTools';
import AuthorizationRoles from '../../../support/fragments/settings/authorization-roles/authorizationRoles';

describe('Eureka', () => {
describe('Settings', () => {
describe('Authorization roles', () => {
const testData = {
roleName: `Original role C554636 ${getRandomPostfix()}`,
application: 'app-platform-full',
capabilitySets: [
{
table: 'Data',
resource: 'Calendar',
action: 'View',
},
],
capabilitiesInSets: [
{
table: 'Data',
resource: 'Calendar Endpoint Calendars',
action: 'View',
},
{
table: 'Data',
resource: 'Calendar Endpoint Calendars CalendarId',
action: 'View',
},
{
table: 'Data',
resource: 'Calendar Endpoint Dates',
action: 'View',
},
],
capabilities: [
{
table: 'Data',
resource: 'Owners Item',
action: 'Create',
},
],
capabIds: [],
capabSetIds: [],
};

testData.capabilitySets.forEach((set) => {
set.application = testData.application;
});
testData.capabilitiesInSets.forEach((capab) => {
capab.application = testData.application;
});
testData.capabilities.forEach((capab) => {
capab.application = testData.application;
});

const capabSetsToAssign = [
{ type: 'Settings', resource: 'UI-Authorization-Roles Settings Admin', action: 'View' },
{ type: 'Data', resource: 'Capabilities', action: 'Manage' },
{ type: 'Data', resource: 'Role-Capability-Sets', action: 'Manage' },
];

const capabsToAssign = [{ type: 'Settings', resource: 'Settings Enabled', action: 'View' }];

before('Create user, data', () => {
cy.createTempUser([]).then((createdUserProperties) => {
testData.user = createdUserProperties;
cy.assignCapabilitiesToExistingUser(
testData.user.userId,
capabsToAssign,
capabSetsToAssign,
);
if (Cypress.env('runAsAdmin')) cy.updateRolesForUserApi(testData.user.userId, []);
cy.createAuthorizationRoleApi(testData.roleName).then((role) => {
testData.roleId = role.id;
testData.capabilities.forEach((capability) => {
capability.type = capability.table;
cy.getCapabilityIdViaApi(capability).then((capabId) => {
testData.capabIds.push(capabId);
});
});
testData.capabilitySets.forEach((capabilitySet) => {
capabilitySet.type = capabilitySet.table;
cy.getCapabilitySetIdViaApi(capabilitySet).then((capabSetId) => {
testData.capabSetIds.push(capabSetId);
});
});
});
});
});

before('Assign capabilities, role, login', () => {
cy.addCapabilitiesToNewRoleApi(testData.roleId, testData.capabIds);
cy.addCapabilitySetsToNewRoleApi(testData.roleId, testData.capabSetIds);
cy.addRolesToNewUserApi(testData.user.userId, [testData.roleId]);
cy.login(testData.user.username, testData.user.password, {
path: TopMenu.settingsAuthorizationRoles,
waiter: AuthorizationRoles.waitContentLoading,
});
});

after('Delete user, data', () => {
cy.getAdminToken();
Users.deleteViaApi(testData.user.userId);
cy.deleteAuthorizationRoleApi(testData.roleId);
});

it(
'C554636 Eureka | Duplicate an authorization role (thunderjet)',
{ tags: ['extendedPath', 'thunderjet'] },
() => {
AuthorizationRoles.searchRole(testData.roleName);
AuthorizationRoles.clickOnRoleName(testData.roleName);
AuthorizationRoles.clickActionsButton();
AuthorizationRoles.checkDuplicateOptionShown();
AuthorizationRoles.clickDuplicateButton();
AuthorizationRoles.cancelDuplicateRole();
AuthorizationRoles.verifyRoleViewPane(testData.roleName);
AuthorizationRoles.duplicateRole(testData.roleName);

AuthorizationRoles.checkCapabilitySetsAccordionCounter(
`${testData.capabilitySets.length}`,
);
AuthorizationRoles.checkCapabilitiesAccordionCounter(
`${testData.capabilities.length + testData.capabilitiesInSets.length}`,
);
AuthorizationRoles.clickOnCapabilitySetsAccordion();
testData.capabilitySets.forEach((capabilitySet) => {
AuthorizationRoles.verifyCapabilitySetCheckboxChecked(capabilitySet);
});
AuthorizationRoles.clickOnCapabilitiesAccordion();
testData.capabilitiesInSets.forEach((capability) => {
AuthorizationRoles.verifyCapabilityCheckboxCheckedAndDisabled(capability);
});
testData.capabilities.forEach((capability) => {
AuthorizationRoles.verifyCapabilityCheckboxCheckedAndDisabled(capability);
});
},
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
matching,
PaneHeader,
} from '../../../../../interactors';
import DateTools from '../../../utils/dateTools';
import InteractorsTools from '../../../utils/interactorsTools';

const rolesPane = Pane('Authorization roles');
const newButton = Button('+ New');
Expand Down Expand Up @@ -51,6 +53,7 @@ const capabilitySetsAccordion = Accordion('Capability sets');
const saveButton = Button('Save & close');
const roleNameInView = KeyValue('Name');
const roleDescriptionInView = KeyValue('Description');
const duplicateButton = Button('Duplicate');

const capabilityTables = {
Data: MultiColumnList({ dataTestId: 'capabilities-data-type' }),
Expand Down Expand Up @@ -82,6 +85,8 @@ const recordLastUpdatedHeader = generalInformationAccordion.find(
Button(including('Record last updated:')),
);
const unassignAllCapabilitiesButton = Button('Unassign all capabilities/sets');
const duplicateModal = Modal('Duplicate role?');
const duplicateCalloutSuccessText = (roleName) => `The role ${roleName} has been successfully duplicated`;

const getResultsListByColumn = (columnIndex) => {
const cells = [];
Expand Down Expand Up @@ -229,15 +234,17 @@ export default {
cy.expect(targetCheckbox.has({ checked: false, disabled: false }));
},

clickOnRoleName: (roleName) => {
clickOnRoleName: (roleName, capabilitiesShown = true) => {
cy.do(rolesPane.find(HTML(roleName, { className: including('root') })).click());
cy.wait(2000);
cy.expect([
Pane(roleName).exists(),
Pane(roleName).find(Spinner()).absent(),
capabilitiesAccordion.has({ open: false }),
capabilitySetsAccordion.has({ open: false }),
]);
cy.expect(Pane(roleName).exists());
if (capabilitiesShown) {
cy.expect([
Pane(roleName).find(Spinner()).absent(),
capabilitiesAccordion.has({ open: false }),
capabilitySetsAccordion.has({ open: false }),
]);
}
},

clickOnCapabilitiesAccordion: (checkOpen = true) => {
Expand Down Expand Up @@ -593,4 +600,51 @@ export default {
cy.do(unassignAllCapabilitiesButton.click());
cy.wait(3000);
},

clickActionsButton: () => {
cy.do(actionsButton.click());
},

checkDuplicateOptionShown: (isShown = true) => {
if (isShown) cy.expect(duplicateButton.exists());
else cy.expect(duplicateButton.absent());
},

clickDuplicateButton: () => {
cy.do(duplicateButton.click());
cy.expect([
duplicateModal.find(duplicateButton).exists(),
duplicateModal.find(cancelButton).exists(),
]);
},

confirmDuplicateRole: () => {
cy.do(duplicateModal.find(duplicateButton).click());
cy.expect(duplicateModal.absent());
},

cancelDuplicateRole: () => {
cy.do(duplicateModal.find(cancelButton).click());
cy.expect(duplicateModal.absent());
},

duplicateRole(roleName, capabilitiesShown = true) {
const currentDate = DateTools.getFormattedDateWithSlashes({ date: new Date() });
const duplicatedTitleRegExp = new RegExp(
`^${roleName} \\(duplicate\\) - ${currentDate.replace('/', '\\/')}, \\d{1,2}:\\d{2}:\\d{2} (A|P)M$`,
);
this.clickActionsButton();
this.clickDuplicateButton();
this.confirmDuplicateRole();
InteractorsTools.checkCalloutMessage(duplicateCalloutSuccessText(roleName));
cy.expect(Pane(matching(duplicatedTitleRegExp)).exists());
if (capabilitiesShown) {
cy.expect([
Spinner().absent(),
capabilitiesAccordion.has({ open: false }),
capabilitySetsAccordion.has({ open: false }),
]);
}
this.checkUsersAccordion(0);
},
};
Loading