Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-search.spec.js
Show First 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | cy.get('#swh-search-origins-with-visit') | ||||
}); | }); | ||||
}); | }); | ||||
it('should not send request to the resolve endpoint', function() { | it('should not send request to the resolve endpoint', function() { | ||||
cy.server(); | cy.server(); | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: `${this.Urls.api_1_resolve_swh_pid('').slice(0, -1)}**` | url: `${this.Urls.api_1_resolve_swhid('').slice(0, -1)}**` | ||||
}).as('resolvePid'); | }).as('resolveSWHID'); | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: `${this.Urls.api_1_origin_search(origin.url)}**` | url: `${this.Urls.api_1_origin_search(origin.url)}**` | ||||
}).as('searchOrigin'); | }).as('searchOrigin'); | ||||
cy.get('#origins-url-patterns') | cy.get('#origins-url-patterns') | ||||
.type(origin.url); | .type(origin.url); | ||||
cy.get('.swh-search-icon') | cy.get('.swh-search-icon') | ||||
.click(); | .click(); | ||||
cy.wait('@searchOrigin'); | cy.wait('@searchOrigin'); | ||||
cy.xhrShouldBeCalled('resolvePid', 0); | cy.xhrShouldBeCalled('resolveSWHID', 0); | ||||
cy.xhrShouldBeCalled('searchOrigin', 1); | cy.xhrShouldBeCalled('searchOrigin', 1); | ||||
}); | }); | ||||
context('Test pagination', function() { | context('Test pagination', function() { | ||||
it('should not paginate if there are not many results', function() { | it('should not paginate if there are not many results', function() { | ||||
// Setup search | // Setup search | ||||
cy.get('#swh-search-origins-with-visit') | cy.get('#swh-search-origins-with-visit') | ||||
.uncheck({force: true}) | .uncheck({force: true}) | ||||
▲ Show 20 Lines • Show All 204 Lines • ▼ Show 20 Lines | it('should paginate backward from the last page', function() { | ||||
cy.get('#origins-prev-results-button') | cy.get('#origins-prev-results-button') | ||||
.should('have.class', 'disabled'); | .should('have.class', 'disabled'); | ||||
cy.get('#origins-next-results-button') | cy.get('#origins-next-results-button') | ||||
.should('not.have.class', 'disabled'); | .should('not.have.class', 'disabled'); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
context('Test valid persistent ids', function() { | context('Test valid SWHIDs', function() { | ||||
it('should resolve directory', function() { | it('should resolve directory', function() { | ||||
const redirectUrl = this.Urls.browse_directory(origin.content[0].directory); | const redirectUrl = this.Urls.browse_directory(origin.content[0].directory); | ||||
const persistentId = `swh:1:dir:${origin.content[0].directory}`; | const swhid = `swh:1:dir:${origin.content[0].directory}`; | ||||
searchShouldRedirect(persistentId, redirectUrl); | searchShouldRedirect(swhid, redirectUrl); | ||||
}); | }); | ||||
it('should resolve revision', function() { | it('should resolve revision', function() { | ||||
const redirectUrl = this.Urls.browse_revision(origin.revisions[0]); | const redirectUrl = this.Urls.browse_revision(origin.revisions[0]); | ||||
const persistentId = `swh:1:rev:${origin.revisions[0]}`; | const swhid = `swh:1:rev:${origin.revisions[0]}`; | ||||
searchShouldRedirect(persistentId, redirectUrl); | searchShouldRedirect(swhid, redirectUrl); | ||||
}); | }); | ||||
it('should resolve snapshot', function() { | it('should resolve snapshot', function() { | ||||
const redirectUrl = this.Urls.browse_snapshot_directory(origin.snapshot); | const redirectUrl = this.Urls.browse_snapshot_directory(origin.snapshot); | ||||
const persistentId = `swh:1:snp:${origin.snapshot}`; | const swhid = `swh:1:snp:${origin.snapshot}`; | ||||
searchShouldRedirect(persistentId, redirectUrl); | searchShouldRedirect(swhid, redirectUrl); | ||||
}); | }); | ||||
it('should resolve content', function() { | it('should resolve content', function() { | ||||
const redirectUrl = this.Urls.browse_content(`sha1_git:${origin.content[0].sha1git}`); | const redirectUrl = this.Urls.browse_content(`sha1_git:${origin.content[0].sha1git}`); | ||||
const persistentId = `swh:1:cnt:${origin.content[0].sha1git}`; | const swhid = `swh:1:cnt:${origin.content[0].sha1git}`; | ||||
searchShouldRedirect(persistentId, redirectUrl); | searchShouldRedirect(swhid, redirectUrl); | ||||
}); | }); | ||||
it('should not send request to the search endpoint', function() { | it('should not send request to the search endpoint', function() { | ||||
cy.server(); | cy.server(); | ||||
const persistentId = `swh:1:rev:${origin.revisions[0]}`; | const swhid = `swh:1:rev:${origin.revisions[0]}`; | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: this.Urls.api_1_resolve_swh_pid(persistentId) | url: this.Urls.api_1_resolve_swhid(swhid) | ||||
}).as('resolvePid'); | }).as('resolveSWHID'); | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: `${this.Urls.api_1_origin_search('').slice(0, -1)}**` | url: `${this.Urls.api_1_origin_search('').slice(0, -1)}**` | ||||
}).as('searchOrigin'); | }).as('searchOrigin'); | ||||
cy.get('#origins-url-patterns') | cy.get('#origins-url-patterns') | ||||
.type(persistentId); | .type(swhid); | ||||
cy.get('.swh-search-icon') | cy.get('.swh-search-icon') | ||||
.click(); | .click(); | ||||
cy.wait('@resolvePid'); | cy.wait('@resolveSWHID'); | ||||
cy.xhrShouldBeCalled('resolvePid', 1); | cy.xhrShouldBeCalled('resolveSWHID', 1); | ||||
cy.xhrShouldBeCalled('searchOrigin', 0); | cy.xhrShouldBeCalled('searchOrigin', 0); | ||||
}); | }); | ||||
}); | }); | ||||
context('Test invalid persistent ids', function() { | context('Test invalid SWHIDs', function() { | ||||
it('should show not found for directory', function() { | it('should show not found for directory', function() { | ||||
const persistentId = `swh:1:dir:${this.unarchivedRepo.rootDirectory}`; | const swhid = `swh:1:dir:${this.unarchivedRepo.rootDirectory}`; | ||||
const msg = `Directory with sha1_git ${this.unarchivedRepo.rootDirectory} not found`; | const msg = `Directory with sha1_git ${this.unarchivedRepo.rootDirectory} not found`; | ||||
searchShouldShowNotFound(persistentId, msg); | searchShouldShowNotFound(swhid, msg); | ||||
}); | }); | ||||
it('should show not found for snapshot', function() { | it('should show not found for snapshot', function() { | ||||
const persistentId = `swh:1:snp:${this.unarchivedRepo.snapshot}`; | const swhid = `swh:1:snp:${this.unarchivedRepo.snapshot}`; | ||||
const msg = `Snapshot with id ${this.unarchivedRepo.snapshot} not found!`; | const msg = `Snapshot with id ${this.unarchivedRepo.snapshot} not found!`; | ||||
searchShouldShowNotFound(persistentId, msg); | searchShouldShowNotFound(swhid, msg); | ||||
}); | }); | ||||
it('should show not found for revision', function() { | it('should show not found for revision', function() { | ||||
const persistentId = `swh:1:rev:${this.unarchivedRepo.revision}`; | const swhid = `swh:1:rev:${this.unarchivedRepo.revision}`; | ||||
const msg = `Revision with sha1_git ${this.unarchivedRepo.revision} not found.`; | const msg = `Revision with sha1_git ${this.unarchivedRepo.revision} not found.`; | ||||
searchShouldShowNotFound(persistentId, msg); | searchShouldShowNotFound(swhid, msg); | ||||
}); | }); | ||||
it('should show not found for content', function() { | it('should show not found for content', function() { | ||||
const persistentId = `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(persistentId, msg); | searchShouldShowNotFound(swhid, msg); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); |