Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cypress tests #1184

Merged
merged 7 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ui/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ testem.log
# System files
.DS_Store
Thumbs.db

# Cypress
/cypress/plugins/credentials_qa.json
/cypress/plugins/token_qa.json
/cypress/fixtures/credentials.json
/cypress/fixtures/downloadedAffiliations.csv
/cypress/fixtures/editAffiliations.csv
/cypress/videos
/cypress/screenshots
16 changes: 16 additions & 0 deletions ui/cypress.config.ts
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',
},
});
123 changes: 123 additions & 0 deletions ui/cypress/e2e/bulk-edit-salesforce-ids.cy.js
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);
});
}
});
});
});
});
57 changes: 57 additions & 0 deletions ui/cypress/e2e/reset-test-data.cy.js
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()
});
})
165 changes: 165 additions & 0 deletions ui/cypress/e2e/retention/add-affiliation.cy.js
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();
});
});
Loading
Loading