diff --git a/cypress/integration/origin-search.spec.js b/cypress/integration/origin-search.spec.js --- a/cypress/integration/origin-search.spec.js +++ b/cypress/integration/origin-search.spec.js @@ -1,5 +1,5 @@ /** - * 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 * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information @@ -30,14 +30,13 @@ .and('contain', msg); } -function stubOriginVisitLatestRequests() { +function stubOriginVisitLatestRequests(status = 200, response = {type: 'tar'}) { cy.server(); cy.route({ method: 'GET', url: '**/visit/latest/**', - response: { - type: 'tar' - } + response: response, + status: status }).as('originVisitLatest'); } @@ -80,6 +79,33 @@ .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() { searchShouldShowNotFound(nonExistentText, 'No origins matching the search criteria were found.'); diff --git a/swh/web/assets/src/bundles/browse/origin-search.js b/swh/web/assets/src/bundles/browse/origin-search.js --- a/swh/web/assets/src/bundles/browse/origin-search.js +++ b/swh/web/assets/src/bundles/browse/origin-search.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2018-2020 The Software Heritage developers + * Copyright (C) 2018-2021 The Software Heritage developers * See the AUTHORS file at the top-level directory of this distribution * License: GNU Affero General Public License version 3, or any later version * See top-level LICENSE file for more information @@ -55,21 +55,29 @@ let latestSnapshotUrl = Urls.api_1_origin_visit_latest(origin.url); latestSnapshotUrl += '?require_snapshot=true'; fetch(latestSnapshotUrl) - .then(response => response.json()) + .then(response => { + if (response.status === 404) { + throw new Error(); + } + return response.json(); + }) .then(data => { - $(`#visit-type-origin-${i}`).html(data.type); - $(`#visit-status-origin-${i}`).children().remove(); - if (data) { + if (data.type) { + $(`#visit-type-origin-${i}`).html(data.type); $(`#visit-status-origin-${i}`).html( 'Archived'); } else { - $(`#visit-status-origin-${i}`).html( - 'Pending archival'); - if ($('#swh-filter-empty-visits').prop('checked')) { - $(`#origin-${i}`).remove(); - } + throw new Error(); + } + }) + .catch(() => { + $(`#visit-type-origin-${i}`).html('unknown'); + $(`#visit-status-origin-${i}`).html( + 'Pending archival'); + if ($('#swh-filter-empty-visits').prop('checked')) { + $(`#origin-${i}`).remove(); } }); }