Skip to content

Commit

Permalink
C404390 (#3077)
Browse files Browse the repository at this point in the history
* C404390
  • Loading branch information
nayimovag authored Jan 15, 2024
1 parent 162b08f commit fa89cc3
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import uuid from 'uuid';
import permissions from '../../../../support/dictionary/permissions';
import Users from '../../../../support/fragments/users/users';
import TopMenu from '../../../../support/fragments/topMenu';
import { getTestEntityValue } from '../../../../support/utils/stringTools';
import Affiliations, { tenantNames } from '../../../../support/dictionary/affiliations';
import Departments from '../../../../support/fragments/settings/users/departments';
import ConsortiumManagerApp, { settingsItems, usersItems } from '../../../../support/fragments/consortium-manager/consortiumManagerApp';
import DepartmentsConsortiumManager from '../../../../support/fragments/consortium-manager/departmentsConsortiumManager';

const testData = {
centralSharedDepartment: {
payload: {
code: getTestEntityValue('centralSharedDepartment_name'),
name: getTestEntityValue('centralSharedDepartment_name'),
}
},
centralLocalDepartment: {
code: getTestEntityValue('centralLocalDepartment_code'),
id: uuid(),
name: getTestEntityValue('centralLocalDepartment_name'),
},
collegeLocalDepartment: {
code: getTestEntityValue('collegeLocalDepartment_code'),
id: uuid(),
name: getTestEntityValue('collegeLocalDepartment_name'),
},
universityLocalDepartment: {
code: getTestEntityValue('universityLocalDepartment_code'),
id: uuid(),
name: getTestEntityValue('universityLocalDepartment_name'),
}
};
const testUsers = [];

describe('Consortium manager', () => {
describe('View settings', () => {
describe('View Departments', () => {
before('create test data', () => {
cy.getAdminToken();
DepartmentsConsortiumManager.createViaApi(testData.centralSharedDepartment)
.then((newDepartment) => {
testData.centralSharedDepartment = newDepartment;
});
Departments.createViaApi(testData.centralLocalDepartment);

cy.createTempUser([
permissions.consortiaSettingsConsortiumManagerView.gui,
permissions.createEditViewDepartments.gui,
]).then((userProperties) => {
testData.user = userProperties;

for (let i = 0; i < 6; i++) {
cy.resetTenant();
if (i === 3 || i === 4) {
cy.setTenant(Affiliations.College);
} else if (i === 5) {
cy.setTenant(Affiliations.University);
}
cy.createTempUser([]).then((testUserProperties) => {
testUsers.push(testUserProperties);
});
}
}).then(() => {
cy.resetTenant();
cy.assignAffiliationToUser(Affiliations.College, testData.user.userId);
cy.setTenant(Affiliations.College);
cy.assignPermissionsToExistingUser(testData.user.userId, [
permissions.createEditViewDepartments.gui,
]);
Departments.createViaApi(testData.collegeLocalDepartment);

cy.resetTenant();
cy.assignAffiliationToUser(Affiliations.University, testData.user.userId);
cy.setTenant(Affiliations.University);
cy.assignPermissionsToExistingUser(testData.user.userId, [
permissions.departmentsAll.gui,
]);
Departments.createViaApi(testData.universityLocalDepartment);
cy.resetTenant();
[
testUsers[0],
testUsers[1],
testUsers[2],
].forEach((element) => {
cy.getUsers({ limit: 1, query: `"username"="${element.username}"` }).then((users) => {
cy.updateUser({
...users[0],
departments: [testData.centralSharedDepartment.id, testData.centralLocalDepartment.id],
});
});
});
cy.setTenant(Affiliations.College);
[
testUsers[3],
testUsers[4],
]
.forEach((element) => {
cy.getUsers({ limit: 1, query: `"username"=$"${element.username}"` }).then((result) => {
cy.updateUser({
...result[0],
departments: [testData.centralSharedDepartment.id, testData.collegeLocalDepartment.id]
});
});
});
cy.setTenant(Affiliations.University);
cy.getUsers({ limit: 1, query: `"username"="${testUsers[5].username}"` }).then((result) => {
cy.updateUser({
...result[0],
departments: [testData.centralSharedDepartment.id],
});
});

cy.resetTenant();
cy.login(testData.user.username, testData.user.password, {
path: TopMenu.consortiumManagerPath,
waiter: ConsortiumManagerApp.waitLoading
});
});
});

after('delete test data', () => {
cy.setTenant(Affiliations.University);
cy.getUniversityAdminToken();
Users.deleteViaApi(testUsers[5].userId);
Departments.deleteViaApi(testData.universityLocalDepartment.id);

cy.resetTenant();
cy.getAdminToken();

cy.setTenant(Affiliations.College);
cy.getCollegeAdminToken();
Users.deleteViaApi(testUsers[3].userId);
Users.deleteViaApi(testUsers[4].userId);
Departments.deleteViaApi(testData.collegeLocalDepartment.id);

cy.setTenant(Affiliations.Consortia);
cy.getAdminToken();
Users.deleteViaApi(testUsers[0].userId);
Users.deleteViaApi(testUsers[1].userId);
Users.deleteViaApi(testUsers[2].userId);
Departments.deleteViaApi(testData.centralLocalDepartment.id);
DepartmentsConsortiumManager.deleteViaApi(testData.centralSharedDepartment);
});

it(
'C404390 User with "Consortium manager: Can view existing settings" permission is able to view the list of departments of affiliated tenants in "Consortium manager" app (consortia) (thunderjet)',
{ tags: ['criticalPath', 'thunderjet'] },
() => {
ConsortiumManagerApp.selectAllMembers();
ConsortiumManagerApp.verifyPageAfterSelectingMembers(3);
ConsortiumManagerApp.chooseSettingsItem(settingsItems.users);
ConsortiumManagerApp.chooseUsersItem(usersItems.departments);
DepartmentsConsortiumManager.verifyDepartmentInTheList(testData.centralSharedDepartment.payload.name, testData.centralSharedDepartment.payload.code, '6', 'All');
DepartmentsConsortiumManager.verifyDepartmentInTheList(testData.centralLocalDepartment.name, testData.centralLocalDepartment.code, '3', 'Central Office', 'edit');

DepartmentsConsortiumManager.verifyDepartmentInTheList(testData.collegeLocalDepartment.name, testData.collegeLocalDepartment.code, '2', 'College', 'edit');
DepartmentsConsortiumManager.verifyDepartmentInTheList(testData.universityLocalDepartment.name, testData.universityLocalDepartment.code, 'No value set-', 'University', 'edit', 'trash');

ConsortiumManagerApp.clickSelectMembers();
ConsortiumManagerApp.verifySelectMembersModal(3);
ConsortiumManagerApp.selectMembers(tenantNames.central);
DepartmentsConsortiumManager.verifyDepartmentInTheList(testData.centralSharedDepartment.payload.name, testData.centralSharedDepartment.payload.code, '3', 'All');
DepartmentsConsortiumManager.verifyNoDepartmentInTheList(testData.centralLocalDepartment.name);

DepartmentsConsortiumManager.verifyDepartmentInTheList(testData.collegeLocalDepartment.name, testData.collegeLocalDepartment.code, '2', 'College', 'edit');
DepartmentsConsortiumManager.verifyDepartmentInTheList(testData.universityLocalDepartment.name, testData.universityLocalDepartment.code, 'No value set-', 'University', 'edit', 'trash');
}
);
});
});
});
4 changes: 4 additions & 0 deletions cypress/support/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Cypress.Commands.add('getCollegeAdminToken', () => {
cy.getToken('ECS0001Admin', Cypress.env('diku_password'));
});

Cypress.Commands.add('getUniversityAdminToken', () => {
cy.getToken('ECS0005Admin', Cypress.env('diku_password'));
});

Cypress.Commands.add('getUserToken', (username, password) => {
let pathToSet = 'bl-users/login-with-expiry';
if (!Cypress.env('rtrAuth')) {
Expand Down
9 changes: 9 additions & 0 deletions cypress/support/dictionary/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,4 +1000,13 @@ export default {
internal: 'ui-courses.read-all',
gui: 'Courses: Read all',
},
// Departments
createEditViewDepartments: {
internal: 'ui-users.settings.departments.create.edit.view',
gui: 'Settings (Users): Can create, edit, and view departments'
},
departmentsAll: {
internal: 'ui-users.settings.departments.all',
gui: 'Settings (Users): Can create, edit, view, and delete departments'
},
};
124 changes: 124 additions & 0 deletions cypress/support/fragments/consortium-manager/consortiumManagerApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import {
PaneHeader,
Button,
Modal,
Checkbox,
HTML,
NavListItem,
Pane,
MultiColumnListHeader,
including,
Warning,
ListRow,
Spinner
} from '../../../../interactors';

const selectMembersButton = Button('Select members');
const selectMembersModal = Modal('Select members');
const searchAndFilterPane = Pane('Search & filter');
const membersPane = Pane('Members');
const searchButton = Button('Search');
const resetAll = Button('Reset all');
const saveAndClose = Button('Save & close');

export const settingsItems = {
users: 'Users'
};

export const usersItems = {
departments: 'Departments'
};

export default {
waitLoading() {
cy.expect([
PaneHeader({ title: 'Settings for selected members can be modified at the same time' }).exists(),
]);
},

clickSelectMembers() {
cy.expect(Spinner().absent());
cy.do(selectMembersButton.click());
},

verifySelectMembersModal(count) {
cy.expect([
selectMembersModal.find(searchAndFilterPane).exists(),
selectMembersModal.find(membersPane).exists(),
searchAndFilterPane.find(searchButton).has({ disabled: true }),
searchAndFilterPane.find(resetAll).has({ disabled: true }),
membersPane.find(HTML(`${count} members found`)).exists(),
membersPane.find(Warning('Settings for the following selected members can be modified at the same time.')).exists(),
membersPane.find(Checkbox({ ariaLabel: 'Select all members' })).has({ checked: true }),
membersPane.find(HTML('End of list')).exists(),
selectMembersModal.find(HTML(`Total selected: ${count}`)).exists(),
selectMembersModal.find(Button({ icon: 'times' })).has({ disabled: false }),
selectMembersModal.find(Button('Cancel')).has({ disabled: false }),
selectMembersModal.find(saveAndClose).has({ disabled: false })
]);
},

selectAllMembers() {
this.clickSelectMembers();
cy.wait(2000);
cy.get('[aria-label="Select all members"]')
.invoke('is', ':checked')
.then((checked) => {
if (!checked) {
cy.do([
selectMembersModal.find(Checkbox({ ariaLabel: 'Select all members' })).click(),
]);
}
});
cy.wait(2000);
cy.do(saveAndClose.click());
},

selectMembers(member) {
cy.do([
selectMembersModal.find(ListRow(member)).find(Checkbox()).click(),
saveAndClose.click()
]);
},

verifyPageAfterSelectingMembers(memberCount) {
cy.expect(Modal().absent());
cy.get('[class^="NavListItem"]').then((items) => {
const textArray = items.get().map((el) => el.innerText);
const sortedArray = [...textArray].sort((a, b) => a - b);
expect(sortedArray).to.eql(textArray);
});
this.waitLoading();
cy.expect([
HTML(`${memberCount} members selected`).exists(),
selectMembersButton.has({ disabled: false }),
HTML('Choose settings').exists()
]);
},

chooseSettingsItem(item) {
cy.do([
NavListItem(item).click(),
HTML('Choose settings').absent(),
Pane(item).exists()
]);
},

chooseUsersItem(item) {
cy.do([
NavListItem(item).click(),
Pane(item).exists(),
HTML(including(item, { class: 'headline' })).exists(),
]);
[
'Name',
'Code',
'Last updated',
'# of Users',
'Member libraries',
'Actions'
].forEach((header) => {
cy.expect(MultiColumnListHeader(header).exists());
});
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import uuid from 'uuid';
import { REQUEST_METHOD } from '../../constants';
import {
Button,
MultiColumnListCell,
MultiColumnListRow,
including,
} from '../../../../interactors';

const id = uuid();

export default {
createViaApi: (department) => {
return cy.getConsortiaId().then((consortiaId) => {
cy.okapiRequest({
method: REQUEST_METHOD.POST,
path: `consortia/${consortiaId}/sharing/settings`,
body: {
url: '/departments',
settingId: id,
payload: {
name: department.payload.name,
code: department.payload.code,
id,
},
},
}).then(() => {
department.url = '/departments';
department.settingId = id;
department.id = id;
return department;
});
});
},

deleteViaApi: (department) => {
cy.getConsortiaId().then((consortiaId) => {
cy.okapiRequest({
method: REQUEST_METHOD.DELETE,
path: `consortia/${consortiaId}/sharing/settings/${department.settingId}`,
body: department,
});
});
},

verifyDepartmentInTheList(name, code, number, members, ...actions) {
const row = MultiColumnListRow({ content: including(name) });
cy.expect([
row.exists(),
row.find(MultiColumnListCell({ columnIndex: 1, content: code })).exists(),
row.find(MultiColumnListCell({ columnIndex: 3, content: number })).exists(),
row.find(MultiColumnListCell({ columnIndex: 4, content: members })).exists(),
]);
if (!actions) {
row.find(MultiColumnListCell({ columnIndex: 5, content: '' })).exists();
} else {
actions.forEach((action) => {
cy.expect([row.find(Button({ icon: action })).exists()]);
});
}
},

verifyNoDepartmentInTheList(name) {
cy.expect(MultiColumnListRow({ content: including(name) }).absent());
},
};
Loading

0 comments on commit fa89cc3

Please sign in to comment.