Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-search.spec.js
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | describe('Test origin-search', function() { | ||||
it('should have focus on search form after page load', function() { | it('should have focus on search form after page load', function() { | ||||
cy.get('#swh-origins-url-patterns') | cy.get('#swh-origins-url-patterns') | ||||
.should('have.attr', 'autofocus'); | .should('have.attr', 'autofocus'); | ||||
// for some reason, autofocus is not honored when running cypress tests | // for some reason, autofocus is not honored when running cypress tests | ||||
// while it is in non controlled browsers | // while it is in non controlled browsers | ||||
// .should('have.focus'); | // .should('have.focus'); | ||||
}); | }); | ||||
it('should show in result when url is searched', function() { | it('should redirect to browse when archived URL is searched', function() { | ||||
cy.get('#swh-origins-url-patterns') | cy.get('#swh-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.location('pathname') | ||||
.should('be.visible'); | .should('eq', this.Urls.browse_origin_directory()); | ||||
cy.contains('tr', origin.url) | cy.location('search') | ||||
.should('be.visible') | .should('eq', `?origin_url=${origin.url}`); | ||||
.find('.swh-visit-status') | }); | ||||
.find('i') | |||||
.should('have.class', 'mdi-check-bold') | it('should not redirect for non valid URL', function() { | ||||
.and('have.attr', 'title', | cy.get('#swh-origins-url-patterns') | ||||
'Software origin has been archived by Software Heritage'); | .type('www.example'); // Invalid URL | ||||
cy.get('.swh-search-icon') | |||||
const browseOriginUrl = `${this.Urls.browse_origin()}?origin_url=${encodeURIComponent(origin.url)}`; | .click(); | ||||
cy.get('tr a') | |||||
.should('have.attr', 'href', browseOriginUrl); | cy.location('pathname') | ||||
.should('eq', this.Urls.browse_search()); // Stay in the current page | |||||
}); | |||||
it('should not redirect for valid non archived URL', function() { | |||||
cy.get('#swh-origins-url-patterns') | |||||
.type('http://eaxmple.com/test/'); // Valid URL, but not archived | |||||
cy.get('.swh-search-icon') | |||||
.click(); | |||||
cy.location('pathname') | |||||
.should('eq', this.Urls.browse_search()); // Stay in the current page | |||||
}); | }); | ||||
it('should remove origin URL with no archived content', function() { | it('should remove origin URL with no archived content', function() { | ||||
stubOriginVisitLatestRequests(404); | stubOriginVisitLatestRequests(404); | ||||
// Using a non full origin URL here | |||||
// This is because T3354 redirects to the origin in case of a valid, archived URL | |||||
cy.get('#swh-origins-url-patterns') | cy.get('#swh-origins-url-patterns') | ||||
.type(origin.url); | .type(origin.url.slice(0, -1)); | ||||
cy.get('.swh-search-icon') | cy.get('.swh-search-icon') | ||||
.click(); | .click(); | ||||
cy.wait('@originVisitLatest'); | cy.wait('@originVisitLatest'); | ||||
cy.get('#origin-search-results') | cy.get('#origin-search-results') | ||||
.should('be.visible') | .should('be.visible') | ||||
.find('tbody tr').should('have.length', 0); | .find('tbody tr').should('have.length', 0); | ||||
▲ Show 20 Lines • Show All 90 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.intercept(`${this.Urls.api_1_resolve_swhid('').slice(0, -1)}**`) | cy.intercept(`${this.Urls.api_1_resolve_swhid('').slice(0, -1)}**`) | ||||
.as('resolveSWHID'); | .as('resolveSWHID'); | ||||
cy.intercept(`${this.Urls.api_1_origin_search(origin.url)}**`) | cy.intercept(`${this.Urls.api_1_origin_search(origin.url.slice(0, -1))}**`) | ||||
.as('searchOrigin'); | .as('searchOrigin'); | ||||
cy.get('#swh-origins-url-patterns') | cy.get('#swh-origins-url-patterns') | ||||
.type(origin.url); | .type(origin.url.slice(0, -1)); | ||||
cy.get('.swh-search-icon') | cy.get('.swh-search-icon') | ||||
.click(); | .click(); | ||||
cy.wait('@searchOrigin'); | cy.wait('@searchOrigin'); | ||||
cy.xhrShouldBeCalled('resolveSWHID', 0); | cy.xhrShouldBeCalled('resolveSWHID', 0); | ||||
cy.xhrShouldBeCalled('searchOrigin', 1); | cy.xhrShouldBeCalled('searchOrigin', 1); | ||||
▲ Show 20 Lines • Show All 342 Lines • Show Last 20 Lines |