Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/persistent-identifiers.spec.js
/** | /** | ||||
* Copyright (C) 2019 The Software Heritage developers | * Copyright (C) 2019 The Software Heritage developers | ||||
* See the AUTHORS file at the top-level directory of this distribution | * See the AUTHORS file at the top-level directory of this distribution | ||||
* License: GNU Affero General Public License version 3, or any later version | * License: GNU Affero General Public License version 3, or any later version | ||||
* See top-level LICENSE file for more information | * See top-level LICENSE file for more information | ||||
*/ | */ | ||||
let origin; | let origin, originBadgeUrl, originBrowseUrl; | ||||
let url; | let url, urlPrefix; | ||||
let browsedObjectMetadata; | let browsedObjectMetadata; | ||||
let cntPid, cntPidWithOrigin, cntPidWithOriginAndLines; | let cntPid, cntPidWithOrigin, cntPidWithOriginAndLines; | ||||
let dirPid, dirPidWithOrigin; | let dirPid, dirPidWithOrigin; | ||||
let relPid, relPidWithOrigin; | let relPid, relPidWithOrigin; | ||||
let revPid, revPidWithOrigin; | let revPid, revPidWithOrigin; | ||||
let snpPid, snpPidWithOrigin; | let snpPid, snpPidWithOrigin; | ||||
let testsData; | |||||
const firstSelLine = 6; | const firstSelLine = 6; | ||||
const lastSelLine = 12; | const lastSelLine = 12; | ||||
describe('Persistent Identifiers Tests', function() { | describe('Persistent Identifiers Tests', function() { | ||||
before(function() { | before(function() { | ||||
origin = this.origin[1]; | origin = this.origin[1]; | ||||
url = this.Urls.browse_origin_content(origin.url, origin.content[0].path); | url = this.Urls.browse_origin_content(origin.url, origin.content[0].path); | ||||
url = `${url}?release=${origin.release}#L${firstSelLine}-L${lastSelLine}`; | url = `${url}?release=${origin.release}#L${firstSelLine}-L${lastSelLine}`; | ||||
}); | originBadgeUrl = this.Urls.swh_badge('origin', origin.url); | ||||
originBrowseUrl = this.Urls.browse_origin(origin.url); | |||||
beforeEach(function() { | |||||
cy.visit(url).window().then(win => { | cy.visit(url).window().then(win => { | ||||
urlPrefix = `${win.location.protocol}//${win.location.hostname}`; | |||||
if (win.location.port) { | |||||
urlPrefix += `:${win.location.port}`; | |||||
} | |||||
browsedObjectMetadata = win.swh.webapp.getBrowsedSwhObjectMetadata(); | browsedObjectMetadata = win.swh.webapp.getBrowsedSwhObjectMetadata(); | ||||
cntPid = `swh:1:cnt:${browsedObjectMetadata.sha1_git}`; | cntPid = `swh:1:cnt:${browsedObjectMetadata.sha1_git}`; | ||||
cntPidWithOrigin = `${cntPid};origin=${origin.url}`; | cntPidWithOrigin = `${cntPid};origin=${origin.url}`; | ||||
cntPidWithOriginAndLines = `${cntPidWithOrigin};lines=${firstSelLine}-${lastSelLine}`; | cntPidWithOriginAndLines = `${cntPidWithOrigin};lines=${firstSelLine}-${lastSelLine}`; | ||||
dirPid = `swh:1:dir:${browsedObjectMetadata.directory}`; | dirPid = `swh:1:dir:${browsedObjectMetadata.directory}`; | ||||
dirPidWithOrigin = `${dirPid};origin=${origin.url}`; | dirPidWithOrigin = `${dirPid};origin=${origin.url}`; | ||||
revPid = `swh:1:rev:${browsedObjectMetadata.revision}`; | revPid = `swh:1:rev:${browsedObjectMetadata.revision}`; | ||||
revPidWithOrigin = `${revPid};origin=${origin.url}`; | revPidWithOrigin = `${revPid};origin=${origin.url}`; | ||||
relPid = `swh:1:rel:${browsedObjectMetadata.release}`; | relPid = `swh:1:rel:${browsedObjectMetadata.release}`; | ||||
relPidWithOrigin = `${relPid};origin=${origin.url}`; | relPidWithOrigin = `${relPid};origin=${origin.url}`; | ||||
snpPid = `swh:1:snp:${browsedObjectMetadata.snapshot}`; | snpPid = `swh:1:snp:${browsedObjectMetadata.snapshot}`; | ||||
snpPidWithOrigin = `${snpPid};origin=${origin.url}`; | snpPidWithOrigin = `${snpPid};origin=${origin.url}`; | ||||
testsData = [ | |||||
{ | |||||
'objectType': 'content', | |||||
'objectPids': [cntPidWithOriginAndLines, cntPidWithOrigin, cntPid], | |||||
'badgeUrl': this.Urls.swh_badge('content', browsedObjectMetadata.sha1_git), | |||||
'badgePidUrl': this.Urls.swh_badge_pid(cntPidWithOriginAndLines), | |||||
'browseUrl': this.Urls.browse_swh_id(cntPidWithOriginAndLines) | |||||
}, | |||||
{ | |||||
'objectType': 'directory', | |||||
'objectPids': [dirPidWithOrigin, dirPid], | |||||
'badgeUrl': this.Urls.swh_badge('directory', browsedObjectMetadata.directory), | |||||
'badgePidUrl': this.Urls.swh_badge_pid(dirPidWithOrigin), | |||||
'browseUrl': this.Urls.browse_swh_id(dirPidWithOrigin) | |||||
}, | |||||
{ | |||||
'objectType': 'release', | |||||
'objectPids': [relPidWithOrigin, relPid], | |||||
'badgeUrl': this.Urls.swh_badge('release', browsedObjectMetadata.release), | |||||
'badgePidUrl': this.Urls.swh_badge_pid(relPidWithOrigin), | |||||
'browseUrl': this.Urls.browse_swh_id(relPidWithOrigin) | |||||
}, | |||||
{ | |||||
'objectType': 'revision', | |||||
'objectPids': [revPidWithOrigin, revPid], | |||||
'badgeUrl': this.Urls.swh_badge('revision', browsedObjectMetadata.revision), | |||||
'badgePidUrl': this.Urls.swh_badge_pid(revPidWithOrigin), | |||||
'browseUrl': this.Urls.browse_swh_id(revPidWithOrigin) | |||||
}, | |||||
{ | |||||
'objectType': 'snapshot', | |||||
'objectPids': [snpPidWithOrigin, snpPid], | |||||
'badgeUrl': this.Urls.swh_badge('snapshot', browsedObjectMetadata.snapshot), | |||||
'badgePidUrl': this.Urls.swh_badge_pid(snpPidWithOrigin), | |||||
'browseUrl': this.Urls.browse_swh_id(snpPidWithOrigin) | |||||
} | |||||
]; | |||||
}); | }); | ||||
}); | }); | ||||
beforeEach(function() { | |||||
cy.visit(url); | |||||
}); | |||||
it('should open and close identifiers tab when clicking on handle', function() { | it('should open and close identifiers tab when clicking on handle', function() { | ||||
cy.get('#swh-identifiers') | cy.get('#swh-identifiers') | ||||
.should('have.class', 'ui-slideouttab-ready'); | .should('have.class', 'ui-slideouttab-ready'); | ||||
cy.get('.ui-slideouttab-handle') | cy.get('.ui-slideouttab-handle') | ||||
.click(); | .click(); | ||||
cy.get('#swh-identifiers') | cy.get('#swh-identifiers') | ||||
.should('have.class', 'ui-slideouttab-open'); | .should('have.class', 'ui-slideouttab-open'); | ||||
cy.get('.ui-slideouttab-handle') | cy.get('.ui-slideouttab-handle') | ||||
.click(); | .click(); | ||||
cy.get('#swh-identifiers') | cy.get('#swh-identifiers') | ||||
.should('not.have.class', 'ui-slideouttab-open'); | .should('not.have.class', 'ui-slideouttab-open'); | ||||
}); | }); | ||||
it('should display identifiers with permalinks for browsed objects', function() { | it('should display identifiers with permalinks for browsed objects', function() { | ||||
cy.get('.ui-slideouttab-handle') | cy.get('.ui-slideouttab-handle') | ||||
.click(); | .click(); | ||||
const testData = [ | for (let td of testsData) { | ||||
{ | |||||
'objectType': 'content', | |||||
'objectPid': cntPidWithOriginAndLines | |||||
}, | |||||
{ | |||||
'objectType': 'directory', | |||||
'objectPid': dirPidWithOrigin | |||||
}, | |||||
{ | |||||
'objectType': 'release', | |||||
'objectPid': relPidWithOrigin | |||||
}, | |||||
{ | |||||
'objectType': 'revision', | |||||
'objectPid': revPidWithOrigin | |||||
}, | |||||
{ | |||||
'objectType': 'snapshot', | |||||
'objectPid': snpPidWithOrigin | |||||
} | |||||
]; | |||||
for (let td of testData) { | |||||
cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) | cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) | ||||
.click(); | .click(); | ||||
cy.get(`#swh-id-tab-${td.objectType}`) | cy.get(`#swh-id-tab-${td.objectType}`) | ||||
.should('be.visible'); | .should('be.visible'); | ||||
cy.get(`#swh-id-tab-${td.objectType} .swh-id`) | cy.get(`#swh-id-tab-${td.objectType} .swh-id`) | ||||
.contains(td.objectPid) | .contains(td.objectPids[0]) | ||||
.should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPid)); | .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0])); | ||||
} | } | ||||
}); | }); | ||||
it('should update content identifier metadata when toggling option checkboxes', function() { | it('should update content identifier metadata when toggling option checkboxes', function() { | ||||
cy.get('.ui-slideouttab-handle') | cy.get('.ui-slideouttab-handle') | ||||
.click(); | .click(); | ||||
Show All 31 Lines | cy.get(`#swh-id-tab-content .swh-id`) | ||||
.should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOriginAndLines)); | .should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOriginAndLines)); | ||||
}); | }); | ||||
it('should update other object identifiers metadata when toggling option checkboxes', function() { | it('should update other object identifiers metadata when toggling option checkboxes', function() { | ||||
cy.get('.ui-slideouttab-handle') | cy.get('.ui-slideouttab-handle') | ||||
.click(); | .click(); | ||||
const testData = [ | for (let td of testsData) { | ||||
{ | |||||
'objectType': 'directory', | // already tested | ||||
'objectPids': [dirPidWithOrigin, dirPid] | if (td.objectType === 'content') continue; | ||||
}, | |||||
{ | |||||
'objectType': 'release', | |||||
'objectPids': [relPidWithOrigin, relPid] | |||||
}, | |||||
{ | |||||
'objectType': 'revision', | |||||
'objectPids': [revPidWithOrigin, revPid] | |||||
}, | |||||
{ | |||||
'objectType': 'snapshot', | |||||
'objectPids': [snpPidWithOrigin, snpPid] | |||||
} | |||||
]; | |||||
for (let td of testData) { | |||||
cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) | cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) | ||||
.click(); | .click(); | ||||
cy.get(`#swh-id-tab-${td.objectType} .swh-id`) | cy.get(`#swh-id-tab-${td.objectType} .swh-id`) | ||||
.contains(td.objectPids[0]) | .contains(td.objectPids[0]) | ||||
.should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0])); | .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0])); | ||||
cy.get(`#swh-id-tab-${td.objectType} .swh-id-option-origin`) | cy.get(`#swh-id-tab-${td.objectType} .swh-id-option-origin`) | ||||
.click(); | .click(); | ||||
cy.get(`#swh-id-tab-${td.objectType} .swh-id`) | cy.get(`#swh-id-tab-${td.objectType} .swh-id`) | ||||
.contains(td.objectPids[1]) | .contains(td.objectPids[1]) | ||||
.should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[1])); | .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[1])); | ||||
cy.get(`#swh-id-tab-${td.objectType} .swh-id-option-origin`) | cy.get(`#swh-id-tab-${td.objectType} .swh-id-option-origin`) | ||||
.click(); | .click(); | ||||
cy.get(`#swh-id-tab-${td.objectType} .swh-id`) | cy.get(`#swh-id-tab-${td.objectType} .swh-id`) | ||||
.contains(td.objectPids[0]) | .contains(td.objectPids[0]) | ||||
.should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0])); | .should('have.attr', 'href', this.Urls.browse_swh_id(td.objectPids[0])); | ||||
} | } | ||||
}); | }); | ||||
it('should display swh badges in identifiers tab for browsed objects', function() { | |||||
cy.get('.ui-slideouttab-handle') | |||||
.click(); | |||||
const originBadgeUrl = this.Urls.swh_badge('origin', origin.url); | |||||
for (let td of testsData) { | |||||
cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) | |||||
.click(); | |||||
cy.get(`#swh-id-tab-${td.objectType} .swh-badge-origin`) | |||||
.should('have.attr', 'src', originBadgeUrl); | |||||
cy.get(`#swh-id-tab-${td.objectType} .swh-badge-${td.objectType}`) | |||||
.should('have.attr', 'src', td.badgeUrl); | |||||
} | |||||
}); | |||||
it('should display badge integration info when clicking on it', function() { | |||||
cy.get('.ui-slideouttab-handle') | |||||
.click(); | |||||
for (let td of testsData) { | |||||
cy.get(`a[href="#swh-id-tab-${td.objectType}"]`) | |||||
.click(); | |||||
cy.get(`#swh-id-tab-${td.objectType} .swh-badge-origin`) | |||||
.click() | |||||
.wait(500); | |||||
for (let badgeType of ['html', 'md', 'rst']) { | |||||
cy.get(`.modal .swh-badge-${badgeType}`) | |||||
.contains(`${urlPrefix}${originBrowseUrl}`) | |||||
.contains(`${urlPrefix}${originBadgeUrl}`); | |||||
} | |||||
cy.get('.modal.show .close') | |||||
.click() | |||||
.wait(500); | |||||
cy.get(`#swh-id-tab-${td.objectType} .swh-badge-${td.objectType}`) | |||||
.click() | |||||
vlorentz: Are these `.wait(500)` needed? `cy.get` should already waits as long as needed | |||||
.wait(500); | |||||
for (let badgeType of ['html', 'md', 'rst']) { | |||||
cy.get(`.modal .swh-badge-${badgeType}`) | |||||
.contains(`${urlPrefix}${td.browseUrl}`) | |||||
.contains(`${urlPrefix}${td.badgePidUrl}`); | |||||
} | |||||
cy.get('.modal.show .close') | |||||
.click() | |||||
Not Done Inline ActionsWhy is this one needed? vlorentz: Why is this one needed? | |||||
Done Inline ActionsBecause there is some fade in / fade out animations with bootstrap modals when displaying / closing them that mess up with cypress. Tests were failing without these wait instructions. anlambert: Because there is some fade in / fade out animations with bootstrap modals when displaying /… | |||||
.wait(500); | |||||
} | |||||
}); | |||||
}); | }); |
Are these .wait(500) needed? cy.get should already waits as long as needed