Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-search.spec.js
/** | /** | ||||
* Copyright (C) 2019-2020 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; | ||||
Show All 14 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, response = {type: 'tar'}) { | ||||
cy.server(); | cy.server(); | ||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: '**/visit/latest/**', | url: '**/visit/latest/**', | ||||
response: { | response: response, | ||||
type: 'tar' | 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(); | ||||
}); | }); | ||||
Show All 26 Lines | cy.contains('tr', origin.url) | ||||
.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 remove origin URL with no archived content', function() { | |||||
stubOriginVisitLatestRequests(404); | |||||
cy.get('#swh-origins-url-patterns') | |||||
.type(origin.url); | |||||
cy.get('.swh-search-icon') | |||||
.click(); | |||||
cy.wait('@originVisitLatest'); | |||||
cy.get('#origin-search-results') | |||||
.should('be.visible') | |||||
.find('tbody tr').should('have.length', 0); | |||||
stubOriginVisitLatestRequests(200, {}); | |||||
cy.get('.swh-search-icon') | |||||
.click(); | |||||
cy.wait('@originVisitLatest'); | |||||
cy.get('#origin-search-results') | |||||
.should('be.visible') | |||||
.find('tbody tr').should('have.length', 0); | |||||
}); | |||||
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 |