Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/persistent-identifiers.spec.js
/** | /** | ||||
* Copyright (C) 2019-2020 The Software Heritage developers | * Copyright (C) 2019-2020 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, originBadgeUrl, originBrowseUrl; | let origin, originBadgeUrl, originBrowseUrl; | ||||
let url, urlPrefix; | let url, urlPrefix; | ||||
let browsedObjectMetadata; | let cntSWHID, cntSWHIDWithContext; | ||||
let cntPid, cntPidWithOrigin, cntPidWithOriginAndLines; | let dirSWHID, dirSWHIDWithContext; | ||||
let dirPid, dirPidWithOrigin; | let relSWHID, relSWHIDWithContext; | ||||
let relPid, relPidWithOrigin; | let revSWHID, revSWHIDWithContext; | ||||
let revPid, revPidWithOrigin; | let snpSWHID, snpSWHIDWithContext; | ||||
let snpPid, snpPidWithOrigin; | |||||
let testsData; | 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.url}&path=${origin.content[0].path}`; | url = `${this.Urls.browse_origin_content()}?origin_url=${origin.url}&path=${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); | originBadgeUrl = this.Urls.swh_badge('origin', origin.url); | ||||
originBrowseUrl = `${this.Urls.browse_origin()}?origin_url=${origin.url}`; | originBrowseUrl = `${this.Urls.browse_origin()}?origin_url=${origin.url}`; | ||||
cy.visit(url).window().then(win => { | cy.visit(url).window().then(win => { | ||||
urlPrefix = `${win.location.protocol}//${win.location.hostname}`; | urlPrefix = `${win.location.protocol}//${win.location.hostname}`; | ||||
if (win.location.port) { | if (win.location.port) { | ||||
urlPrefix += `:${win.location.port}`; | urlPrefix += `:${win.location.port}`; | ||||
} | } | ||||
browsedObjectMetadata = win.swh.webapp.getBrowsedSwhObjectMetadata(); | const swhids = win.swh.webapp.getSwhIdsContext(); | ||||
cntPid = `swh:1:cnt:${browsedObjectMetadata.sha1_git}`; | cntSWHID = swhids.content.swhid; | ||||
cntPidWithOrigin = `${cntPid};origin=${origin.url}`; | cntSWHIDWithContext = swhids.content.swhid_with_context; | ||||
cntPidWithOriginAndLines = `${cntPidWithOrigin};lines=${firstSelLine}-${lastSelLine}`; | cntSWHIDWithContext += `;lines=${firstSelLine}-${lastSelLine}`; | ||||
dirPid = `swh:1:dir:${browsedObjectMetadata.directory}`; | dirSWHID = swhids.directory.swhid; | ||||
dirPidWithOrigin = `${dirPid};origin=${origin.url}`; | dirSWHIDWithContext = swhids.directory.swhid_with_context; | ||||
revPid = `swh:1:rev:${browsedObjectMetadata.revision}`; | revSWHID = swhids.revision.swhid; | ||||
revPidWithOrigin = `${revPid};origin=${origin.url}`; | revSWHIDWithContext = swhids.revision.swhid_with_context; | ||||
relPid = `swh:1:rel:${browsedObjectMetadata.release}`; | relSWHID = swhids.release.swhid; | ||||
relPidWithOrigin = `${relPid};origin=${origin.url}`; | relSWHIDWithContext = swhids.release.swhid_with_context; | ||||
snpPid = `swh:1:snp:${browsedObjectMetadata.snapshot}`; | snpSWHID = swhids.snapshot.swhid; | ||||
snpPidWithOrigin = `${snpPid};origin=${origin.url}`; | snpSWHIDWithContext = swhids.snapshot.swhid_with_context; | ||||
testsData = [ | testsData = [ | ||||
{ | { | ||||
'objectType': 'content', | 'objectType': 'content', | ||||
'objectPids': [cntPidWithOriginAndLines, cntPidWithOrigin, cntPid], | 'objectPids': [cntSWHIDWithContext, cntSWHID], | ||||
'badgeUrl': this.Urls.swh_badge('content', browsedObjectMetadata.sha1_git), | 'badgeUrl': this.Urls.swh_badge('content', swhids.content.object_id), | ||||
'badgePidUrl': this.Urls.swh_badge_pid(cntPidWithOriginAndLines), | 'badgePidUrl': this.Urls.swh_badge_pid(cntSWHID), | ||||
'browseUrl': this.Urls.browse_swh_id(cntPidWithOriginAndLines) | 'browseUrl': this.Urls.browse_swh_id(cntSWHIDWithContext) | ||||
}, | }, | ||||
{ | { | ||||
'objectType': 'directory', | 'objectType': 'directory', | ||||
'objectPids': [dirPidWithOrigin, dirPid], | 'objectPids': [dirSWHIDWithContext, dirSWHID], | ||||
'badgeUrl': this.Urls.swh_badge('directory', browsedObjectMetadata.directory), | 'badgeUrl': this.Urls.swh_badge('directory', swhids.directory.object_id), | ||||
'badgePidUrl': this.Urls.swh_badge_pid(dirPidWithOrigin), | 'badgePidUrl': this.Urls.swh_badge_pid(dirSWHID), | ||||
'browseUrl': this.Urls.browse_swh_id(dirPidWithOrigin) | 'browseUrl': this.Urls.browse_swh_id(dirSWHIDWithContext) | ||||
}, | }, | ||||
{ | { | ||||
'objectType': 'release', | 'objectType': 'release', | ||||
'objectPids': [relPidWithOrigin, relPid], | 'objectPids': [relSWHIDWithContext, relSWHID], | ||||
'badgeUrl': this.Urls.swh_badge('release', browsedObjectMetadata.release), | 'badgeUrl': this.Urls.swh_badge('release', swhids.release.object_id), | ||||
'badgePidUrl': this.Urls.swh_badge_pid(relPidWithOrigin), | 'badgePidUrl': this.Urls.swh_badge_pid(relSWHID), | ||||
'browseUrl': this.Urls.browse_swh_id(relPidWithOrigin) | 'browseUrl': this.Urls.browse_swh_id(relSWHIDWithContext) | ||||
}, | }, | ||||
{ | { | ||||
'objectType': 'revision', | 'objectType': 'revision', | ||||
'objectPids': [revPidWithOrigin, revPid], | 'objectPids': [revSWHIDWithContext, revSWHID], | ||||
'badgeUrl': this.Urls.swh_badge('revision', browsedObjectMetadata.revision), | 'badgeUrl': this.Urls.swh_badge('revision', swhids.revision.object_id), | ||||
'badgePidUrl': this.Urls.swh_badge_pid(revPidWithOrigin), | 'badgePidUrl': this.Urls.swh_badge_pid(revSWHID), | ||||
'browseUrl': this.Urls.browse_swh_id(revPidWithOrigin) | 'browseUrl': this.Urls.browse_swh_id(revSWHIDWithContext) | ||||
}, | }, | ||||
{ | { | ||||
'objectType': 'snapshot', | 'objectType': 'snapshot', | ||||
'objectPids': [snpPidWithOrigin, snpPid], | 'objectPids': [snpSWHIDWithContext, snpSWHID], | ||||
'badgeUrl': this.Urls.swh_badge('snapshot', browsedObjectMetadata.snapshot), | 'badgeUrl': this.Urls.swh_badge('snapshot', swhids.snapshot.object_id), | ||||
'badgePidUrl': this.Urls.swh_badge_pid(snpPidWithOrigin), | 'badgePidUrl': this.Urls.swh_badge_pid(snpSWHID), | ||||
'browseUrl': this.Urls.browse_swh_id(snpPidWithOrigin) | 'browseUrl': this.Urls.browse_swh_id(snpSWHIDWithContext) | ||||
} | } | ||||
]; | ]; | ||||
}); | }); | ||||
}); | }); | ||||
beforeEach(function() { | beforeEach(function() { | ||||
cy.visit(url); | cy.visit(url); | ||||
Show All 31 Lines | for (let td of testsData) { | ||||
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 update content identifier metadata when toggling option checkboxes', function() { | it('should update other object identifiers contextual info when toggling context checkbox', function() { | ||||
cy.get('.ui-slideouttab-handle') | |||||
.click(); | |||||
cy.get(`#swh-id-tab-content .swh-id`) | |||||
.contains(cntPidWithOriginAndLines) | |||||
.should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOriginAndLines)); | |||||
cy.get('#swh-id-tab-content .swh-id-option-lines') | |||||
.click(); | |||||
cy.get(`#swh-id-tab-content .swh-id`) | |||||
.contains(cntPidWithOrigin) | |||||
.should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOrigin)); | |||||
cy.get('#swh-id-tab-content .swh-id-option-origin') | |||||
.click(); | |||||
cy.get(`#swh-id-tab-content .swh-id`) | |||||
.contains(cntPid) | |||||
.should('have.attr', 'href', this.Urls.browse_swh_id(cntPid)); | |||||
cy.get('#swh-id-tab-content .swh-id-option-origin') | |||||
.click(); | |||||
cy.get(`#swh-id-tab-content .swh-id`) | |||||
.contains(cntPidWithOrigin) | |||||
.should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOrigin)); | |||||
cy.get('#swh-id-tab-content .swh-id-option-lines') | |||||
.click(); | |||||
cy.get(`#swh-id-tab-content .swh-id`) | |||||
.contains(cntPidWithOriginAndLines) | |||||
.should('have.attr', 'href', this.Urls.browse_swh_id(cntPidWithOriginAndLines)); | |||||
}); | |||||
it('should update other object identifiers metadata when toggling option checkboxes', function() { | |||||
cy.get('.ui-slideouttab-handle') | cy.get('.ui-slideouttab-handle') | ||||
.click(); | .click(); | ||||
for (let td of testsData) { | for (let td of testsData) { | ||||
// already tested | |||||
if (td.objectType === 'content') continue; | |||||
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-context-option`) | ||||
.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-context-option`) | ||||
.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])); | ||||
} | } | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |