-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1184 from ORCID/add-cypress-tests
Add cypress tests
- Loading branch information
Showing
38 changed files
with
5,399 additions
and
219 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
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,16 @@ | ||
import { defineConfig } from 'cypress'; | ||
|
||
export default defineConfig({ | ||
taskTimeout: 300000, | ||
defaultCommandTimeout: 10000, | ||
video: false, | ||
e2e: { | ||
// We've imported your old cypress plugins here. | ||
// You may want to clean this up later by importing these. | ||
setupNodeEvents(on, config) { | ||
return require('./cypress/plugins/index.js')(on, config); | ||
}, | ||
// TODO: cy.visit('ui') should be changed to cy.visit('/') | ||
baseUrl: 'https://member-portal.qa.orcid.org', | ||
}, | ||
}); |
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,123 @@ | ||
/// <reference types="cypress" /> | ||
import config from '../fixtures/bulk-edit-salesforce-ids-config.json'; | ||
|
||
describe('Bulk edit invalid salesforce ids', () => { | ||
it('Replace all invalid ids with unused valid ones', () => { | ||
cy.request({ | ||
url: config.endpoint, | ||
method: 'GET', | ||
headers: { | ||
Authorization: config.token | ||
} | ||
}).then(res => { | ||
let totalPages = 0; | ||
let sfIds = []; | ||
let mpIds = []; | ||
let data = res.body; | ||
data = JSON.parse(data); | ||
for (const id in data.records) { | ||
if (!sfIds.includes(data.records[id]['Id'])) { | ||
sfIds.push(data.records[id]['Id']); | ||
} | ||
} | ||
cy.visit(config.base_url); | ||
cy.get('#username') | ||
.clear() | ||
.type(config.username) | ||
.get('#password') | ||
.type(config.password) | ||
.get('button') | ||
.filter('[type="submit"]') | ||
.click(); | ||
cy.get('#admin-menu').click(); | ||
cy.get('a') | ||
.filter('[href="/member"]') | ||
.click(); | ||
cy.wait(1000); | ||
cy.get('.pagination') | ||
.children() | ||
.eq(-3) | ||
.then(e => { | ||
totalPages = +e[0].textContent.replace('(current)', '').trim(); | ||
// get list of salesforce ids used in the portal | ||
for (let i = 0; i < totalPages; i++) { | ||
cy.get('tbody') | ||
.children() | ||
.each($e => { | ||
mpIds.push($e[0].children[0].textContent); | ||
}); | ||
cy.get('.pagination') | ||
.children() | ||
.eq(-2) | ||
.click(); | ||
cy.wait(200); | ||
} | ||
}) | ||
.then(() => { | ||
cy.get('tbody') | ||
.children() | ||
.each($e => { | ||
mpIds.push($e[0].children[0].textContent); | ||
}); | ||
// create list of salesforce ids not used in the portal | ||
let filteredIds = []; | ||
for (var i = 0; i < sfIds.length; i += 1) { | ||
if (mpIds.indexOf(sfIds[i]) == -1) { | ||
filteredIds.push(sfIds[i]); | ||
} | ||
} | ||
// go back to first page | ||
cy.get('.pagination') | ||
.children() | ||
.eq(0) | ||
.click(); | ||
cy.wait(1000); | ||
for (var i = 0; i < totalPages; i++) { | ||
cy.get('.pagination > li.active').then(page => { | ||
// get current page number | ||
const pageNumber = +page[0].textContent.replace('(current)', '').trim(); | ||
cy.get('tbody') | ||
.children() | ||
.each($e => { | ||
if ($e[0].children[0].textContent !== '001G000001AP83e') { | ||
if (!sfIds.includes($e[0].children[0].textContent)) { | ||
// click on the edit button | ||
cy.get('tbody') | ||
.children() | ||
.eq($e[0].sectionRowIndex) | ||
.children() | ||
.eq(6) | ||
.children() | ||
.eq(0) | ||
.click(); | ||
// change id | ||
cy.get('#field_salesforceId') | ||
.clear() | ||
.type(filteredIds[0]); | ||
cy.get('#save-entity').click(); | ||
filteredIds.shift() | ||
// saving the id redirects you to page 1, make sure you return to the relevant page | ||
if (pageNumber !== 1) { | ||
for (var p = 1; p < pageNumber; p++) { | ||
cy.get('.pagination') | ||
.children() | ||
.eq(-2) | ||
.click(); | ||
} | ||
cy.wait(200); | ||
} | ||
} | ||
} | ||
}); | ||
// go to the next page | ||
cy.get('.pagination') | ||
.children() | ||
.eq(-2) | ||
.click(); | ||
cy.wait(250); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
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,57 @@ | ||
/// <reference types="cypress" /> | ||
import data from '../fixtures/test-data.json'; | ||
import credentials from '../fixtures/credentials.json'; | ||
|
||
describe('Add new user', () => { | ||
it('Reset organization owner', () => { | ||
cy.programmaticSignin(credentials.adminEmail, credentials.adminPassword) | ||
cy.changeOrgOwner() | ||
}) | ||
|
||
it('Remove all affiliations from test group', function () { | ||
cy.programmaticSignin(data.member.users.owner.email, credentials.password) | ||
cy.visit('/assertion') | ||
cy.get('.btn-group').each($e => { | ||
cy.wrap($e).children().last().click() | ||
cy.get('#jhi-confirm-delete-assertion').click() | ||
}) | ||
cy.visit('/user') | ||
cy.get('.btn-group').each($e => { | ||
cy.wrap($e).children().last().invoke('attr', 'disabled').then((disabled) => { | ||
disabled ? cy.log("Skipping user, button is disabled") : cy.removeAffiliation($e) | ||
}) | ||
}) | ||
cy.programmaticSignout() | ||
}) | ||
|
||
it('Remove all affiliations from test member', function () { | ||
cy.programmaticSignin(data.member.users.owner.email, credentials.password) | ||
cy.visit('/user') | ||
cy.get('.btn-group').each($e => { | ||
cy.wrap($e).children().last().invoke('attr', 'disabled').then((disabled) => { | ||
disabled ? cy.log("Skipping user, button is disabled") : cy.removeAffiliation($e) | ||
}) | ||
}) | ||
cy.programmaticSignout() | ||
}) | ||
|
||
it('Remove all affiliations from csv test member', function () { | ||
cy.programmaticSignin(data.csvMember.users.owner.email, credentials.password) | ||
cy.visit('/assertion') | ||
cy.get('.btn-group').each($e => { | ||
cy.wrap($e).children().last().click() | ||
cy.get('#jhi-confirm-delete-assertion').click() | ||
}) | ||
cy.programmaticSignout() | ||
}) | ||
|
||
it('Remove all affiliations from the notifications member', function() { | ||
cy.programmaticSignin(data.notificationsMember.users.owner.email, credentials.password); | ||
cy.visit('/assertion') | ||
cy.get('.btn-group').each($e => { | ||
cy.wrap($e).children().last().click() | ||
cy.get('#jhi-confirm-delete-assertion').click() | ||
}) | ||
cy.programmaticSignout() | ||
}); | ||
}) |
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,165 @@ | ||
/// <reference types="cypress" /> | ||
import data from '../../fixtures/test-data.json'; | ||
import record from '../../fixtures/orcid-record.json'; | ||
import credentials from '../../fixtures/credentials.json'; | ||
import { recurse } from 'cypress-recurse'; | ||
|
||
const months = { | ||
January: '01', | ||
February: '02', | ||
March: '03', | ||
April: '04', | ||
May: '05', | ||
June: '06', | ||
July: '07', | ||
August: '08', | ||
September: '09', | ||
October: '10', | ||
November: '11', | ||
December: '12' | ||
}; | ||
const { country, countryCode, url, invalidUrl, startDate, endDate, type } = record.affiliation; | ||
const { ringgold, grid, ror } = record.affiliation.org; | ||
describe('Add and remove affiliation', () => { | ||
/* beforeEach(() => { | ||
cy.programmaticSignin(data.member.users.owner.email, credentials.password); | ||
}); | ||
afterEach(() => { | ||
cy.programmaticSignout(); | ||
});*/ | ||
|
||
it('Add affiliation', function () { | ||
cy.programmaticSignin(data.member.users.owner.email, credentials.password); | ||
cy.visit('/assertion/new'); | ||
|
||
cy.get('#field_email').type(record.invalidEmail); | ||
cy.get('small.text-danger').should('exist'); | ||
cy.get('#field_email') | ||
.clear() | ||
.type(record.email); | ||
cy.get('small.text-danger').should('not.exist'); | ||
cy.get('#field_affiliationSection').select(type); | ||
cy.get('#field_orgName').type(data.testString); | ||
cy.get('#field_orgCity').type(data.testString); | ||
cy.get('#field_orgCountry').select(country); | ||
cy.checkOrgId(ringgold.name, ringgold.invalidId, ringgold.id); | ||
cy.checkOrgId(grid.name, grid.invalidId, grid.id); | ||
cy.checkOrgId(ror.name, ror.invalidId, ror.id); | ||
cy.get('#field_departmentName').type(data.testString); | ||
cy.get('#field_roleTitle').type(data.testString); | ||
cy.get('#field_url').type(invalidUrl); | ||
cy.get('#field_startYear').select(startDate.year); | ||
cy.get('#field_startMonth').select(startDate.month); | ||
cy.get('#field_startDay').select(startDate.invalidDay); | ||
cy.get('#field_endYear').select(endDate.year); | ||
cy.get('#field_endMonth').select(endDate.month); | ||
cy.get('#field_endDay').select(endDate.day); | ||
cy.get('small') | ||
.filter('[jhitranslate="entity.validation.endDate.string"]') | ||
.should('exist'); | ||
cy.get('#save-entity') | ||
.invoke('attr', 'disabled') | ||
.should('exist'); | ||
cy.get('#field_startDay').select(startDate.day); | ||
cy.get('small').should('not.exist'); | ||
cy.get('#save-entity').click(); | ||
cy.get('.alerts') | ||
.children() | ||
.should('have.length', 1); | ||
|
||
cy.get('#save-entity').click(); | ||
cy.get('.alerts') | ||
.children() | ||
.should('have.length', 2); | ||
cy.get('#field_url') | ||
.clear() | ||
.type(url) | ||
.get('#save-entity') | ||
.click(); | ||
cy.get('.alert-success').should('exist'); | ||
cy.programmaticSignout(); | ||
}); | ||
|
||
it('Grant permission and check ORCID record for added affiliation', () => { | ||
cy.programmaticSignin(data.member.users.owner.email, credentials.password); | ||
// Get permission link | ||
cy.visit('/assertion'); | ||
cy.get('tbody').children().first().children().eq(0).contains(record.email); | ||
cy.get('tbody').children().first().children().eq(1).should('not.contain', record.id); | ||
cy.get('tbody').children().first().children().eq(2).contains(record.affiliation.type); | ||
cy.get('tbody').children().first().children().eq(4).contains('Pending'); | ||
|
||
cy.fetchLinkAndGrantPermission(record.email); | ||
|
||
recurse( | ||
() => | ||
cy.request({ | ||
url: `https://pub.qa.orcid.org/v3.0/${record.id}/services`, | ||
headers: { Accept: 'application/json' } | ||
}), | ||
res => { | ||
const service = res.body['affiliation-group'][0]['summaries'][0]['service-summary']; | ||
expect(res.body['affiliation-group']).to.have.length(1); | ||
expect(service['department-name']).to.eq(data.testString); | ||
expect(service['role-title']).to.eq(data.testString); | ||
expect(service['organization']['address']['city']).to.eq(data.testString.trim()); | ||
expect(service['organization']['address']['country']).to.eq(countryCode); | ||
expect(service['organization']['name']).to.eq(data.testString.trim()); | ||
expect(service['url']['value']).to.eq(url); | ||
expect(service['start-date']['year']['value']).to.eq(startDate.year); | ||
expect(service['start-date']['month']['value']).to.eq(months[startDate.month]); | ||
expect(service['start-date']['day']['value']).to.eq(startDate.day); | ||
expect(service['end-date']['year']['value']).to.eq(endDate.year); | ||
expect(service['end-date']['month']['value']).to.eq(months[endDate.month]); | ||
expect(service['end-date']['day']['value']).to.eq(endDate.day); | ||
expect(service['organization']['disambiguated-organization']['disambiguated-organization-identifier']).to.eq(ror.id); | ||
expect(service['organization']['disambiguated-organization']['disambiguation-source']).to.eq(ror.name); | ||
}, | ||
{ | ||
log: true, | ||
limit: 20, // max number of iterations | ||
timeout: 600000, // time limit in ms | ||
delay: 30000 // delay before next iteration, ms | ||
} | ||
); | ||
}); | ||
|
||
it('Confirm UI changes on the assertion page', () => { | ||
cy.programmaticSignin(data.member.users.owner.email, credentials.password); | ||
cy.visit('/assertion'); | ||
cy.get('tbody').children().first().children().eq(1).contains(record.id); | ||
cy.get('tbody').children().first().children().eq(4).contains('In ORCID'); | ||
cy.programmaticSignout(); | ||
}) | ||
|
||
it('Delete affiliation', () => { | ||
cy.programmaticSignin(data.member.users.owner.email, credentials.password); | ||
cy.visit('/assertion'); | ||
cy.get('.btn-group').each($e => { | ||
cy.wrap($e) | ||
.children() | ||
.last() | ||
.click(); | ||
cy.get('#jhi-confirm-delete-assertion').click(); | ||
}); | ||
recurse( | ||
() => | ||
cy.request({ | ||
url: `https://pub.qa.orcid.org/v3.0/${record.id}/services`, | ||
headers: { Accept: 'application/json' } | ||
}), | ||
res => { | ||
console.log(res); | ||
expect(res.body['affiliation-group']).to.have.length(0); | ||
}, | ||
{ | ||
log: true, | ||
limit: 20, // max number of iterations | ||
timeout: 600000, // time limit in ms | ||
delay: 30000 // delay before next iteration, ms | ||
} | ||
); | ||
cy.programmaticSignout(); | ||
}); | ||
}); |
Oops, something went wrong.