Skip to content

Commit

Permalink
Merge pull request #10590 from withanage/9658-create-user-by-inviation
Browse files Browse the repository at this point in the history
add create user invitation  as a  command
  • Loading branch information
withanage authored Nov 7, 2024
2 parents 5afebac + fe55bd8 commit 58199f2
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions cypress/support/commands_new_workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import Api from './api.js';
import 'cypress-file-upload';
import 'cypress-wait-until';
import 'cypress-iframe'

Cypress.Commands.add('setTinyMceContent', (tinyMceId, content) => {
cy.window().then((win) => {
Expand Down Expand Up @@ -144,12 +143,10 @@ Cypress.Commands.add('setLocale', locale => {
Cypress.Commands.add('resetPassword', (username,oldPassword,newPassword) => {
oldPassword = oldPassword || (username + username);
newPassword = newPassword || oldPassword;
cy.visit('index.php/publicknowledge/user/profile');
cy.get('a[name=changePassword]').click();
cy.get('input[name=oldPassword]').type(oldPassword, {delay: 0});
cy.get('input[name=password]').type(newPassword, {delay: 0});
cy.get('input[name=password2]').type(newPassword, {delay: 0});
cy.get('button').contains('Save').click({ force: true });
cy.get('button').contains('OK').click();
});

Cypress.Commands.add('register', data => {
Expand Down Expand Up @@ -605,6 +602,34 @@ Cypress.Commands.add('performReview', (username, password, title, recommendation
cy.logout();
});

Cypress.Commands.add('createUser', user => {
if (!('email' in user)) user.email = user.username + '@mailinator.com';
if (!('password' in user)) user.password = user.username + user.username;
if (!('password2' in user)) user.password2 = user.username + user.username;
if (!('roles' in user)) user.roles = [];
cy.get('div[id=userGridContainer] a:contains("Add User")').click();
cy.wait(2000); // Avoid occasional glitches with given name field
cy.get('input[id^="givenName-en"]').type(user.givenName, {delay: 0});
cy.get('input[id^="familyName-en"]').type(user.familyName, {delay: 0});
cy.get('input[name=email]').type(user.email, {delay: 0});
cy.get('input[name=username]').type(user.username, {delay: 0});
cy.get('input[name=password]').type(user.password, {delay: 0});
cy.get('input[name=password2]').type(user.password2, {delay: 0});
if (!user.mustChangePassword) {
cy.get('input[name="mustChangePassword"]').click();
}
cy.get('select[name=country]').select(user.country);
cy.contains('More User Details').click();
cy.get('span:contains("Less User Details"):visible');
cy.get('input[id^="affiliation-en"]').type(user.affiliation, {delay: 0});
cy.get('form[id=userDetailsForm]').find('button[id^=submitFormButton]').click();
user.roles.forEach(role => {
cy.get('form[id=userRoleForm]').contains(role).click();
});
cy.get('form[id=userRoleForm] button[id^=submitFormButton]').click();
cy.waitJQuery();
});

Cypress.Commands.add('flushNotifications', function() {
cy.window().then(win => {
if (typeof pkp !== 'undefined' && typeof pkp.eventBus !== 'undefined') {
Expand Down Expand Up @@ -934,7 +959,7 @@ Cypress.Commands.add('confirmationByUser', user => {
cy.get('.pkpButton').contains('View All Submissions').click();
});

Cypress.Commands.add('createUser', user => {
Cypress.Commands.add('createUserByInvitation', user => {
cy.login('admin','admin','publicknowledge')
cy.wait(1000)
cy.inviteUser(user);
Expand Down

0 comments on commit 58199f2

Please sign in to comment.