Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-search.spec.js
Show First 20 Lines • Show All 505 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) { | function checkInvalidSWHIDReport(url, searchInputElt, swhidInput, validationMessagePattern = '') { | ||||
const invalidSWHID = `swh:1:cnt:${repoData.content[0].sha1git};lines=45-60/`; | |||||
cy.visit(url); | cy.visit(url); | ||||
doSearch(invalidSWHID, searchInputElt); | doSearch(swhidInput, searchInputElt); | ||||
cy.get(searchInputElt) | cy.get(searchInputElt) | ||||
.then($el => $el[0].checkValidity()).should('be.false'); | .then($el => $el[0].checkValidity()).should('be.false'); | ||||
cy.get(searchInputElt) | cy.get(searchInputElt) | ||||
.invoke('prop', 'validationMessage') | .invoke('prop', 'validationMessage') | ||||
.should('not.equal', ''); | .should('not.equal', '') | ||||
.should('contain', validationMessagePattern); | |||||
} | } | ||||
it('should report invalid SWHID in search page input', function() { | it('should report invalid SWHID in search page input', function() { | ||||
checkInvalidSWHIDReport(this.Urls.browse_search(), '#swh-origins-url-patterns', this.unarchivedRepo); | const swhidInput = | ||||
`swh:1:cnt:${this.unarchivedRepo.content[0].sha1git};lines=45-60/`; | |||||
checkInvalidSWHIDReport(this.Urls.browse_search(), '#swh-origins-url-patterns', swhidInput); | |||||
cy.get('.invalid-feedback') | cy.get('.invalid-feedback') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
}); | }); | ||||
it('should report invalid SWHID in top right search input', function() { | it('should report invalid SWHID in top right search input', function() { | ||||
checkInvalidSWHIDReport(this.Urls.browse_help(), '#swh-origins-search-top-input', this.unarchivedRepo); | const swhidInput = | ||||
`swh:1:cnt:${this.unarchivedRepo.content[0].sha1git};lines=45-60/`; | |||||
checkInvalidSWHIDReport(this.Urls.browse_help(), '#swh-origins-search-top-input', swhidInput); | |||||
}); | |||||
it('should report SWHID with uppercase chars in search page input', function() { | |||||
const swhidInput = | |||||
`swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`.toUpperCase(); | |||||
checkInvalidSWHIDReport(this.Urls.browse_search(), '#swh-origins-url-patterns', swhidInput, swhidInput.toLowerCase()); | |||||
cy.get('.invalid-feedback') | |||||
.should('be.visible'); | |||||
}); | |||||
it('should report SWHID with uppercase chars in top right search input', function() { | |||||
let swhidInput = | |||||
`swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`.toUpperCase(); | |||||
swhidInput += ';lines=45-60/'; | |||||
checkInvalidSWHIDReport(this.Urls.browse_help(), '#swh-origins-search-top-input', swhidInput.toLowerCase()); | |||||
}); | }); | ||||
}); | }); | ||||
}); | }); |