Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-search.spec.js
/** | /** | ||||
* Copyright (C) 2019-2021 The Software Heritage developers | * Copyright (C) 2019-2021 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 | ||||
*/ | */ | ||||
const nonExistentText = 'NoMatchExists'; | const nonExistentText = 'NoMatchExists'; | ||||
let origin; | let origin; | ||||
let url; | let url; | ||||
function doSearch(searchText) { | function doSearch(searchText, searchInputElt = '#swh-origins-url-patterns') { | ||||
cy.get('#swh-origins-url-patterns') | if (searchText.startsWith('swh:')) { | ||||
.type(searchText) | cy.intercept('**/api/1/resolve/**') | ||||
.as('swhidResolve'); | |||||
} | |||||
cy.get(searchInputElt) | |||||
// to avoid sending too much SWHID validation requests | |||||
// as cypress insert character one by one when using type | |||||
.invoke('val', searchText.slice(0, -1)) | |||||
.type(searchText.slice(-1)) | |||||
.get('.swh-search-icon') | .get('.swh-search-icon') | ||||
.click(); | .click(); | ||||
if (searchText.startsWith('swh:')) { | |||||
cy.wait('@swhidResolve'); | |||||
} | |||||
} | } | ||||
function searchShouldRedirect(searchText, redirectUrl) { | function searchShouldRedirect(searchText, redirectUrl) { | ||||
doSearch(searchText); | doSearch(searchText); | ||||
cy.location('pathname') | cy.location('pathname') | ||||
.should('equal', redirectUrl); | .should('equal', redirectUrl); | ||||
} | } | ||||
function searchShouldShowNotFound(searchText, msg) { | function searchShouldShowNotFound(searchText, msg) { | ||||
doSearch(searchText); | doSearch(searchText); | ||||
cy.get('#swh-no-result') | if (searchText.startsWith('swh:')) { | ||||
cy.get('.invalid-feedback') | |||||
.should('be.visible') | .should('be.visible') | ||||
.and('contain', msg); | .and('contain', msg); | ||||
} | } | ||||
} | |||||
function stubOriginVisitLatestRequests(status = 200, response = {type: 'tar'}) { | function stubOriginVisitLatestRequests(status = 200, response = {type: 'tar'}) { | ||||
cy.intercept('**/visit/latest/**', { | cy.intercept('**/visit/latest/**', { | ||||
body: response, | body: response, | ||||
statusCode: status | statusCode: status | ||||
}).as('originVisitLatest'); | }).as('originVisitLatest'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 453 Lines • ▼ Show 20 Lines | context('Test invalid SWHIDs', function() { | ||||
}); | }); | ||||
it('should show not found for content', function() { | it('should show not found for content', function() { | ||||
const swhid = `swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`; | const swhid = `swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`; | ||||
const msg = `Content with sha1_git checksum equals to ${this.unarchivedRepo.content[0].sha1git} not found!`; | const msg = `Content with sha1_git checksum equals to ${this.unarchivedRepo.content[0].sha1git} not found!`; | ||||
searchShouldShowNotFound(swhid, msg); | searchShouldShowNotFound(swhid, msg); | ||||
}); | }); | ||||
function checkInvalidSWHIDReport(url, searchInputElt, repoData) { | |||||
const invalidSWHID = `swh:1:cnt:${repoData.content[0].sha1git};lines=45-60/`; | |||||
cy.visit(url); | |||||
doSearch(invalidSWHID, searchInputElt); | |||||
cy.get(searchInputElt) | |||||
.then($el => $el[0].checkValidity()).should('be.false'); | |||||
cy.get(searchInputElt) | |||||
.invoke('prop', 'validationMessage') | |||||
.should('not.equal', ''); | |||||
} | |||||
it('should report invalid SWHID in search page input', function() { | |||||
checkInvalidSWHIDReport(this.Urls.browse_search(), '#swh-origins-url-patterns', this.unarchivedRepo); | |||||
cy.get('.invalid-feedback') | |||||
.should('be.visible'); | |||||
}); | |||||
it('should report invalid SWHID in top right search input', function() { | |||||
checkInvalidSWHIDReport(this.Urls.browse_help(), '#swh-origins-search-top-input', this.unarchivedRepo); | |||||
}); | |||||
}); | }); | ||||
}); | }); |