Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-search.spec.js
Show All 24 Lines | |||||
function searchShouldShowNotFound(searchText, msg) { | function searchShouldShowNotFound(searchText, msg) { | ||||
doSearch(searchText); | doSearch(searchText); | ||||
cy.get('#swh-no-result') | cy.get('#swh-no-result') | ||||
.should('be.visible') | .should('be.visible') | ||||
.and('contain', msg); | .and('contain', msg); | ||||
} | } | ||||
function stubOriginVisitLatestRequests() { | function stubOriginVisitLatestRequests(status = 200) { | ||||
cy.server(); | cy.server(); | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: '**/visit/latest/**', | url: '**/visit/latest/**', | ||||
response: { | response: { | ||||
type: 'tar' | type: 'git' | ||||
} | }, | ||||
status: status | |||||
}).as('originVisitLatest'); | }).as('originVisitLatest'); | ||||
} | } | ||||
describe('Test origin-search', function() { | describe('Test origin-search', function() { | ||||
before(function() { | before(function() { | ||||
origin = this.origin[0]; | origin = this.origin[0]; | ||||
url = this.Urls.browse_search(); | url = this.Urls.browse_search(); | ||||
}); | }); | ||||
beforeEach(function() { | beforeEach(function() { | ||||
cy.visit(url); | cy.visit(url); | ||||
}); | }); | ||||
it('should show in result when url is searched', function() { | it('should show in result when url is searched', function() { | ||||
stubOriginVisitLatestRequests(); | |||||
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.get('#origin-search-results') | cy.get('#origin-search-results') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
cy.contains('tr', origin.url) | cy.contains('tr', origin.url) | ||||
.should('be.visible') | .should('be.visible') | ||||
.find('.swh-visit-status') | .find('.swh-visit-status') | ||||
.find('i') | .find('i') | ||||
.should('have.class', 'mdi-check-bold') | .should('have.class', 'mdi-check-bold') | ||||
.and('have.attr', 'title', | .and('have.attr', 'title', | ||||
'Software origin has been archived by Software Heritage'); | 'Software origin has been archived by Software Heritage'); | ||||
const browseOriginUrl = `${this.Urls.browse_origin()}?origin_url=${encodeURIComponent(origin.url)}`; | const browseOriginUrl = `${this.Urls.browse_origin()}?origin_url=${encodeURIComponent(origin.url)}`; | ||||
cy.get('tr a') | cy.get('tr a') | ||||
.should('have.attr', 'href', browseOriginUrl); | .should('have.attr', 'href', browseOriginUrl); | ||||
}); | }); | ||||
it('should hide origin not yet archived when related option is on', function() { | |||||
stubOriginVisitLatestRequests(404); | |||||
cy.get('#origins-url-patterns') | |||||
.type(origin.url); | |||||
cy.get('.swh-search-icon') | |||||
.click(); | |||||
cy.wait('@originVisitLatest'); | |||||
cy.get('#origin-search-results') | |||||
.should('be.visible') | |||||
.find('tr') | |||||
.should('have.length', 1); | |||||
}); | |||||
it('should show origin not yet archived when related option is off', function() { | |||||
stubOriginVisitLatestRequests(404); | |||||
cy.get('#swh-search-origins-with-visit') | |||||
.uncheck({force: true}); | |||||
cy.get('#origins-url-patterns') | |||||
.type(origin.url); | |||||
cy.get('.swh-search-icon') | |||||
.click(); | |||||
cy.wait('@originVisitLatest'); | |||||
cy.get('#origin-search-results') | |||||
.should('be.visible') | |||||
.find('tr') | |||||
.should('have.length', 2); | |||||
cy.contains('tr', origin.url) | |||||
.should('be.visible') | |||||
.find('.swh-visit-status') | |||||
.find('i') | |||||
.should('have.class', 'mdi-close-thick') | |||||
.and('have.attr', 'title', | |||||
'Software origin archival by Software Heritage is pending'); | |||||
}); | |||||
it('should show not found message when no repo matches', function() { | it('should show not found message when no repo matches', function() { | ||||
searchShouldShowNotFound(nonExistentText, | searchShouldShowNotFound(nonExistentText, | ||||
'No origins matching the search criteria were found.'); | 'No origins matching the search criteria were found.'); | ||||
}); | }); | ||||
it('should add appropriate URL parameters', function() { | it('should add appropriate URL parameters', function() { | ||||
// Check all three checkboxes and check if | // Check all three checkboxes and check if | ||||
// correct url params are added | // correct url params are added | ||||
▲ Show 20 Lines • Show All 351 Lines • Show Last 20 Lines |