forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8937d74
commit 572baaf
Showing
1 changed file
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/** | ||
* @file cypress/tests/integration/Orcid.cy.js | ||
* | ||
* Copyright (c) 2014-2021 Simon Fraser University | ||
* Copyright (c) 2000-2021 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
*/ | ||
|
||
describe('ORCID tests', function () { | ||
it('Enables ORCID', function () { | ||
cy.login('admin', 'admin'); | ||
|
||
cy.visit('index.php/publicknowledge/management/settings/access'); | ||
cy.get('#orcidSettings-button').should('exist').click(); | ||
|
||
// Check that the checkbox to enable ORCID is visible, and select it | ||
cy.get('input[name^="orcidEnabled"]').should('be.visible').check(); | ||
|
||
// Check that the form fields are visible | ||
cy.get('select[name="orcidApiType"]') | ||
.should('be.visible') | ||
.select('memberSandbox'); | ||
cy.get('input[name="orcidClientId"]') | ||
.should('be.visible') | ||
.clear() | ||
.type('TEST_CLIENT_ID', {delay: 0}); | ||
cy.get('input[name="orcidClientSecret"]') | ||
.should('be.visible') | ||
.clear() | ||
.type('TEST_SECRET', {delay: 0}); | ||
cy.get('input[name="orcidCity"]').should('be.visible'); | ||
cy.get('input[name="orcidSendMailToAuthorsOnPublication"]') | ||
.should('be.visible') | ||
.check(); | ||
cy.get('select[name="orcidLogLevel"]').should('be.visible').select('INFO'); | ||
cy.get('button:contains("Save")').eq(1).should('be.visible').click(); | ||
|
||
cy.reload(); | ||
|
||
cy.get('input[name="orcidClientId"]') | ||
.should('be.visible') | ||
.should('have.value', 'TEST_CLIENT_ID'); | ||
}); | ||
|
||
// This should be skipped for OPS & OMP since they are not using the new UI yet | ||
it('Sends ORCID verification request to author', function () { | ||
cy.login('dbarnes'); | ||
cy.visit( | ||
'index.php/publicknowledge/en/dashboard/editorial?currentViewId=assigned-to-me', | ||
); | ||
|
||
// CLick on first submission in submission list | ||
cy.get('button[aria-describedby^="submission-title-"]').first().click(); | ||
|
||
// TODO Check that the Publications sections is expanded before attempting to click on Contributors | ||
cy.get('a').contains('Contributors').click(); | ||
|
||
cy.get('div.listPanel__itemActions') | ||
.contains('Primary Contact') | ||
.parents('div.listPanel__itemActions') | ||
.within(() => { | ||
cy.contains('button', 'Edit').click(); | ||
}) | ||
.then(() => { | ||
// Ensure side modal is opened before continuing | ||
cy.wait(10000); | ||
|
||
cy.get('[data-cy="sidemodal-header"]').should('be.visible'); | ||
cy.contains('Request verification').click(); | ||
cy.get('button').contains('Yes').click(); | ||
cy.contains( | ||
'ORCID Verification has been requested! Resend Verification Email', | ||
).should('be.visible'); | ||
}); | ||
}); | ||
|
||
it('Adds ORCID to user profile', function () { | ||
cy.login('dbarnes'); | ||
cy.visit('index.php/publicknowledge/en/user/profile'); | ||
cy.window().then((win) => cy.stub(win, 'open').returns({})); | ||
|
||
cy.get('#connect-orcid-button').should('be.visible').click(); | ||
}); | ||
|
||
it('Uses ORCID in user registration', function () { | ||
cy.visit('index.php/publicknowledge/user/register'); | ||
|
||
cy.window().then((win) => { | ||
// Cypress does not work well with multiple tabs or windows | ||
// instead of displaying the ORCID oauth interface in a new tab, have it load in a hidden iFrame | ||
// then intercept the call to ORCID and return stubbed data | ||
cy.stub(win, 'open').callsFake((url) => { | ||
// Create an iframe and set its source to the URL | ||
const iframe = win.document.createElement('iframe'); | ||
iframe.src = url; | ||
iframe.id = 'new-tab-iframe'; | ||
iframe.style.display = 'none'; | ||
win.document.body.appendChild(iframe); // Append the iframe to the body | ||
|
||
return iframe.contentWindow; | ||
}); | ||
}); | ||
|
||
// Intercept requests from the iframe (simulating new tab requests) | ||
cy.intercept( | ||
{ | ||
method: 'GET', | ||
url: 'https://sandbox.orcid.org/oauth/authorize?client_id=TEST_CLIENT_ID&response_type=code&scope=%2Factivities%2Fupdate&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Findex.php%2Fpublicknowledge%2Forcid%2FauthorizeOrcid%3FtargetOp%3Dregister', | ||
}, | ||
(req) => { | ||
req.reply({ | ||
statusCode: 200, | ||
headers: {'Content-Type': 'text/html'}, | ||
body: ` | ||
<html><body><script type='text/javascript'> | ||
// Simulating the response from ORCID and setting values in the main window | ||
parent.document.getElementById("givenName").value = 'John'; | ||
parent.document.getElementById("familyName").value = 'Doe'; | ||
parent.document.getElementById("email").value = '[email protected]'; | ||
parent.document.getElementById("country").value = 'JM'; | ||
parent.document.getElementById("affiliation").value = 'PKP'; | ||
parent.document.getElementById("orcid").value = '1000-2000-3000-400'; | ||
parent.document.getElementById("connect-orcid-button").style.display = "none"; | ||
</script></body></html>`, | ||
}); | ||
}, | ||
); | ||
|
||
// Trigger the action that would normally open a new tab | ||
cy.get('#connect-orcid-button').should('be.visible').click(); | ||
|
||
cy.wait(5000); | ||
|
||
cy.get('iframe').should('exist').and('not.be.visible'); | ||
|
||
// Fields should be populated with ORCID data | ||
cy.get('#givenName').should('have.value', 'John'); | ||
cy.get('#familyName').should('have.value', 'Doe'); | ||
cy.get('#email').should('have.value', '[email protected]'); | ||
cy.get('select#country').should('have.value', 'JM'); | ||
cy.get('#affiliation').should('have.value', 'PKP'); | ||
cy.get('#orcid').should('have.value', '1000-2000-3000-4000'); | ||
|
||
// Populate remaining fields and submit registration form | ||
cy.get('#username').type('johndoe'); | ||
cy.get('#password').type('superSecretPassword'); | ||
cy.get('#password2').type('superSecretPassword'); | ||
cy.get('input[name="privacyConsent"]').check(); | ||
|
||
cy.get('button[type="submit"]').click(); | ||
|
||
// Navigate to profile and check user data | ||
cy.visit('http://localhost:8000/index.php/publicknowledge/en/user/profile'); | ||
cy.get('input[name="givenName[en]"]').should('have.value', 'John'); | ||
cy.get('input[name="familyName[en]"]').should('have.value', 'Doe'); | ||
}); | ||
|
||
it('Disables ORCID', function () { | ||
cy.login('admin', 'admin'); | ||
|
||
cy.visit('index.php/publicknowledge/management/settings/access'); | ||
cy.get('#orcidSettings-button').should('exist').click(); | ||
|
||
// Check that the checkbox to disbaled ORCID is visible | ||
cy.get('input[name^="orcidEnabled"]').should('be.visible'); | ||
|
||
cy.get('input[name^="orcidEnabled"]').then((checkbox) => { | ||
if (checkbox.prop('checked')) { | ||
cy.get('input[name^="orcidEnabled"]').click(); | ||
|
||
// Check that the form fields are visible | ||
cy.get('select[name="orcidApiType"]').should('not.exist'); | ||
cy.get('input[name="orcidClientId"]').should('not.exist'); | ||
cy.get('input[name="orcidClientSecret"]').should('not.exist'); | ||
cy.get('input[name="orcidCity"]').should('not.exist'); | ||
cy.get('input[name="orcidSendMailToAuthorsOnPublication"]').should( | ||
'not.exist', | ||
); | ||
cy.get('select[name="orcidLogLevel"]').should('not.exist'); | ||
cy.get('button:contains("Save")').eq(1).should('be.visible').click(); | ||
|
||
// reload to check that data was saved | ||
cy.reload(); | ||
cy.get('input[name^="orcidEnabled"]').should('not.be.checked'); | ||
} | ||
}); | ||
}); | ||
}); |