From 6629e1b6f0e0db32e86fc5401f2b1c1488c473c5 Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Tue, 10 Dec 2024 16:22:13 -0500 Subject: [PATCH] pkp/pkp-lib#10745 Add tests for email access restriction feature --- cypress/support/commands_new_workflow.js | 21 +++ .../emailTemplates/emailTemplates.cy.js | 170 ++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 cypress/tests/integration/emailTemplates/emailTemplates.cy.js diff --git a/cypress/support/commands_new_workflow.js b/cypress/support/commands_new_workflow.js index c2bf43b7d76..7bb24dd0f73 100644 --- a/cypress/support/commands_new_workflow.js +++ b/cypress/support/commands_new_workflow.js @@ -973,3 +973,24 @@ Cypress.Commands.add('createUserByInvitation', user => { cy.logout(); }); + +Cypress.Commands.add('openEmailTemplate', (mailableName, templateName) => { + // Select the mailable + cy.contains('li.listPanel__item', mailableName) + .find('button') + .contains('Edit') + .click(); + + // Select the template + cy.contains('.listPanel', 'Templates') + .find('li.listPanel__item') + .contains(templateName) + .parents('li.listPanel__item') + .find('button') + .contains('Edit') + .click(); +}); + +Cypress.Commands.add('setEmailTemplateUnrestrictedTo', (value) => { + cy.get('input[name="isUnrestricted"]')[value ? 'check' : 'uncheck']({ force: true }); +}); diff --git a/cypress/tests/integration/emailTemplates/emailTemplates.cy.js b/cypress/tests/integration/emailTemplates/emailTemplates.cy.js new file mode 100644 index 00000000000..08832b5b72f --- /dev/null +++ b/cypress/tests/integration/emailTemplates/emailTemplates.cy.js @@ -0,0 +1,170 @@ +/** + * @file cypress/tests/integration/Orcid.cy.js + * + * Copyright (c) 2014-2024 Simon Fraser University + * Copyright (c) 2000-2024 John Willinsky + * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. + * + */ + +function populateEmailTemplateBody(){ + cy.get('#editEmailTemplate-body-control-en_ifr') + .its('0.contentDocument.body') + .should('not.be.empty') + .then((body) => { + cy.wrap(body).clear().type('Test template body'); + }); +} + +describe('Email Template Access Tests', function () { + it('Remove unrestricted from a template', () => { + cy.login('admin', 'admin', 'publicknowledge'); + cy.visit('/index.php/publicknowledge/management/settings/manageEmails'); + + cy.openEmailTemplate('Discussion (Production)', 'Discussion (Production)'); + cy.setEmailTemplateUnrestrictedTo(false) + cy.contains('button', 'Save').click(); + // reload and check that template was updated + cy.reload() + cy.openEmailTemplate('Discussion (Production)', 'Discussion (Production)'); + cy.get('input[name="isUnrestricted"]').should('not.be.checked') + }); + + it('Marks template as unrestricted', () => { + cy.login('admin', 'admin', 'publicknowledge'); + cy.visit('/index.php/publicknowledge/management/settings/manageEmails'); + + cy.openEmailTemplate('Discussion (Production)', 'Discussion (Production)'); + cy.get('input[name="isUnrestricted"]').should('not.be.checked') + cy.setEmailTemplateUnrestrictedTo(true); + + cy.contains('button', 'Save').click(); + cy.reload(); + + cy.openEmailTemplate('Discussion (Production)', 'Discussion (Production)'); + cy.get('input[name="isUnrestricted"]').should('be.checked') + }); + + it('Assigns user groups to template', () => { + cy.login('admin', 'admin', 'publicknowledge'); + cy.visit('/index.php/publicknowledge/management/settings/manageEmails'); + cy.openEmailTemplate('Discussion (Production)', 'Discussion (Production)'); + + // Assign the fist two user groups in the list + cy.get('input[name="assignedUserGroupIds"]').first().check(); + cy.get('input[name="assignedUserGroupIds"]').eq(1).check(); + cy.contains('button', 'Save').click(); + + cy.reload() + + cy.openEmailTemplate('Discussion (Production)', 'Discussion (Production)'); + cy.get('input[name="assignedUserGroupIds"]').first().should('be.checked'); + cy.get('input[name="assignedUserGroupIds"]').eq(1).should('be.checked'); + }) + + it('Removes user groups from template', () => { + cy.login('admin', 'admin', 'publicknowledge'); + cy.visit('/index.php/publicknowledge/management/settings/manageEmails'); + + cy.openEmailTemplate('Discussion (Production)', 'Discussion (Production)'); + + cy.get('input[name="assignedUserGroupIds"]').first().should('be.checked'); + cy.get('input[name="assignedUserGroupIds"]').eq(1).should('be.checked'); + + cy.contains('button', 'Save').click(); + + cy.reload(); + cy.openEmailTemplate('Discussion (Production)', 'Discussion (Production)'); + cy.get('input[name="assignedUserGroupIds"]').first().uncheck(); + cy.get('input[name="assignedUserGroupIds"]').eq(1).uncheck(); + }) + + it('Creates template with user groups assigned (restricted template)', () => { + cy.login('admin', 'admin', 'publicknowledge'); + cy.visit('/index.php/publicknowledge/management/settings/manageEmails'); + + // Select the mailable + cy.contains('li.listPanel__item', 'Discussion (Production)') + .find('button') + .contains('Edit') + .click(); + + cy.contains('button', 'Add Template').click() + + const templateName = 'TEST TEMPLATE NAME ' + (new Date()).getMilliseconds(); + cy.get('input[id^="editEmailTemplate-name-control-en"]').type(templateName) + cy.get('input[id^="editEmailTemplate-subject-control-en"]').type('TEST TEMPLATE SUBJECT') + + populateEmailTemplateBody() + cy.setEmailTemplateUnrestrictedTo(false) + + // Assign two available user groups + cy.get('input[name="assignedUserGroupIds"]').eq(1).check(); + cy.get('input[name="assignedUserGroupIds"]').eq(2).check(); + cy.contains('button', 'Save').click(); + + cy.reload(); + + cy.openEmailTemplate('Discussion (Production)', templateName) + cy.get('input[name="assignedUserGroupIds"]').eq(1).should('be.checked'); + cy.get('input[name="assignedUserGroupIds"]').eq(2).should('be.checked'); + }) + + it('Creates unrestricted template', () => { + cy.login('admin', 'admin', 'publicknowledge'); + cy.visit('/index.php/publicknowledge/management/settings/manageEmails'); + + // Select the mailable + cy.contains('li.listPanel__item', 'Discussion (Production)') + .find('button') + .contains('Edit') + .click(); + + cy.contains('button', 'Add Template').click() + + const templateName = 'TEST TEMPLATE NAME ' + (new Date()).getMilliseconds(); + + cy.get('input[id^="editEmailTemplate-name-control-en"]').type(templateName) + cy.get('input[id^="editEmailTemplate-subject-control-en"]').type('TEST TEMPLATE SUBJECT') + + populateEmailTemplateBody(); + cy.setEmailTemplateUnrestrictedTo(true); + + cy.contains('button', 'Save').click(); + + cy.reload() + cy.openEmailTemplate('Discussion (Production)', templateName) + cy.get('input[name="isUnrestricted"]').should('be.checked') + }) + + it('Creates restricted template with no assigned user groups', () => { + cy.login('admin', 'admin', 'publicknowledge'); + cy.visit('/index.php/publicknowledge/management/settings/manageEmails'); + + // Select the mailable + cy.contains('li.listPanel__item', 'Reinstate Submission Declined Without Review') + .find('button') + .contains('Edit') + .click(); + + cy.contains('button', 'Add Template').click() + + const templateName = 'TEST TEMPLATE NAME ' + (new Date()).getMilliseconds(); + + cy.get('input[id^="editEmailTemplate-name-control-en"]').type(templateName) + cy.get('input[id^="editEmailTemplate-subject-control-en"]').type('TEST TEMPLATE SUBJECT') + + populateEmailTemplateBody(); + cy.setEmailTemplateUnrestrictedTo(false); + + cy.contains('button', 'Save').click(); + + cy.reload() + cy.openEmailTemplate('Reinstate Submission Declined Without Review', templateName) + cy.get('input[name="isUnrestricted"]').should('not.be.checked'); + + cy.get('input[name="assignedUserGroupIds"]').each(($checkbox) => { + cy.wrap($checkbox).should('not.be.checked'); + }); + }) +});