Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-search.spec.js
/** | /** | ||||
* Copyright (C) 2019 The Software Heritage developers | * Copyright (C) 2019 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; | ||||
let url; | let url; | ||||
function searchShouldRedirect(searchText, redirectUrl) { | function doSearch(searchText) { | ||||
cy.get('#origins-url-patterns') | cy.get('#origins-url-patterns') | ||||
.type(searchText); | .type(searchText) | ||||
cy.get('.swh-search-icon') | .get('.swh-search-icon') | ||||
.click(); | .click(); | ||||
} | |||||
function searchShouldRedirect(searchText, redirectUrl) { | |||||
doSearch(searchText); | |||||
cy.location('pathname') | cy.location('pathname') | ||||
.should('equal', redirectUrl); | .should('equal', redirectUrl); | ||||
} | } | ||||
function searchShouldShowNotFound(searchText, msg) { | function searchShouldShowNotFound(searchText, msg) { | ||||
cy.get('#origins-url-patterns') | doSearch(searchText); | ||||
.type(searchText); | |||||
cy.get('.swh-search-icon') | |||||
.click(); | |||||
cy.get('#swh-no-result') | cy.get('#swh-no-result') | ||||
.should('be.visible') | .should('be.visible') | ||||
.and('contain', msg); | .and('contain', msg); | ||||
} | } | ||||
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 for any url substring', function() { | it('should show in result when url is searched', function() { | ||||
// Randomly select substring of origin url | |||||
const startIndex = Math.floor(Math.random() * origin.url.length); | |||||
const length = Math.floor(Math.random() * (origin.url.length - startIndex - 1)) + 1; | |||||
const originSubstring = origin.url.substr(startIndex, length); | |||||
cy.get('#origins-url-patterns') | cy.get('#origins-url-patterns') | ||||
.type(originSubstring); | .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', 'fa-check') | .should('have.class', 'fa-check') | ||||
.and('have.attr', 'title', | .and('have.attr', 'title', | ||||
'Origin has at least one full visit by Software Heritage'); | 'Origin has at least one full visit by Software Heritage'); | ||||
}); | }); | ||||
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() { | |||||
// Check all three checkboxes and check if | |||||
// correct url params are added | |||||
cy.get('#swh-search-origins-with-visit') | |||||
.check() | |||||
.get('#swh-filter-empty-visits') | |||||
.check() | |||||
.get('#swh-search-origin-metadata') | |||||
.check() | |||||
.then(() => { | |||||
const searchText = origin.url; | |||||
doSearch(searchText); | |||||
cy.location('search').then(locationSearch => { | |||||
const urlParams = new URLSearchParams(locationSearch); | |||||
const query = urlParams.get('q'); | |||||
const withVisit = urlParams.has('with_visit'); | |||||
const withContent = urlParams.has('with_content'); | |||||
const searchMetadata = urlParams.has('search_metadata'); | |||||
assert.strictEqual(query, searchText); | |||||
assert.strictEqual(withVisit, true); | |||||
assert.strictEqual(withContent, true); | |||||
assert.strictEqual(searchMetadata, true); | |||||
}); | |||||
}); | |||||
}); | |||||
context('Test valid persistent ids', function() { | context('Test valid persistent ids', 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 persistentId = `swh:1:dir:${origin.content[0].directory}`; | ||||
searchShouldRedirect(persistentId, redirectUrl); | searchShouldRedirect(persistentId, redirectUrl); | ||||
}); | }); | ||||
it('should resolve revision', function() { | it('should resolve revision', function() { | ||||
const redirectUrl = this.Urls.browse_revision(origin.revision); | const redirectUrl = this.Urls.browse_revision(origin.revision); | ||||
const persistentId = `swh:1:rev:${origin.revision}`; | const persistentId = `swh:1:rev:${origin.revision}`; | ||||
kalpitk: Depends on D1837 (revision[0] was added in it) | |||||
searchShouldRedirect(persistentId, redirectUrl); | searchShouldRedirect(persistentId, 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 persistentId = `swh:1:snp:${origin.snapshot}`; | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |
Depends on D1837 (revision[0] was added in it)