Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-search.spec.js
/** | /** | ||||
* Copyright (C) 2019 The Software Heritage developers | * Copyright (C) 2019-2020 The Software Heritage developers | ||||
anlambert: (C) 2019-2020 | |||||
* 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 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | it('should show in result when url is searched', function() { | ||||
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() { | 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 | ||||
cy.get('#swh-search-origins-with-visit') | cy.get('#swh-search-origins-with-visit') | ||||
.check() | .check() | ||||
.get('#swh-filter-empty-visits') | .get('#swh-filter-empty-visits') | ||||
Show All 13 Lines | cy.get('#swh-search-origins-with-visit') | ||||
assert.strictEqual(query, searchText); | assert.strictEqual(query, searchText); | ||||
assert.strictEqual(withVisit, true); | assert.strictEqual(withVisit, true); | ||||
assert.strictEqual(withContent, true); | assert.strictEqual(withContent, true); | ||||
assert.strictEqual(searchMetadata, true); | assert.strictEqual(searchMetadata, true); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
it('should not send request to the resolve endpoint', function() { | |||||
cy.server(); | |||||
cy.route({ | |||||
method: 'GET', | |||||
Done Inline ActionsUse ${this.Urls.api_1_resolve()}** here instead of harcoding the url anlambert: Use `${this.Urls.api_1_resolve()}**` here instead of harcoding the url | |||||
url: `${this.Urls.api_1_resolve()}**`, | |||||
}).as('resolvePid'); | |||||
Done Inline ActionsI have executed the test without your modifications in the swh/web/assets/src/bundles/browse/origin-search.js file. There is indeed an assertion raised but cypress does not report the test as failed. So we will have to use another approach to check the request is not sent. it('should not send request to the resolve endpoint', function() { cy.server(); cy.route({ method: 'GET', url: `${this.Urls.api_1_resolve()}**`, }).as('resolvePid'); cy.route({ method: 'GET', url: `${this.Urls.api_1_origin_search()}**`, }).as('searchOrigin'); cy.get('#origins-url-patterns') .type(origin.url); cy.get('.swh-search-icon') .click(); cy.wait('@searchOrigin'); cy.xhrShouldBeCalled('resolvePid', 0); cy.xhrShouldBeCalled('searchOrigin', 1); }); The other test should also be rewritten this way. anlambert: I have executed the test without your modifications in the… | |||||
cy.route({ | |||||
method: 'GET', | |||||
url: `${this.Urls.api_1_origin_search()}**`, | |||||
Done Inline ActionsUse single quotes for string litterals anlambert: Use single quotes for string litterals | |||||
}).as('searchOrigin'); | |||||
cy.get('#origins-url-patterns') | |||||
.type(origin.url); | |||||
cy.get('.swh-search-icon') | |||||
.click(); | |||||
cy.wait('@searchOrigin'); | |||||
cy.xhrShouldBeCalled('resolvePid', 0); | |||||
cy.xhrShouldBeCalled('searchOrigin', 1); | |||||
}); | |||||
context('Test pagination', function() { | context('Test pagination', function() { | ||||
it('should not paginate if there are not many results', function() { | it('should not paginate if there are not many results', function() { | ||||
// Setup search | // Setup search | ||||
cy.get('#swh-search-origins-with-visit') | cy.get('#swh-search-origins-with-visit') | ||||
.uncheck() | .uncheck() | ||||
.get('#swh-filter-empty-visits') | .get('#swh-filter-empty-visits') | ||||
.uncheck() | .uncheck() | ||||
.then(() => { | .then(() => { | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | context('Test valid persistent ids', function() { | ||||
}); | }); | ||||
it('should resolve content', function() { | it('should resolve content', function() { | ||||
const redirectUrl = this.Urls.browse_content(`sha1_git:${origin.content[0].sha1git}`); | const redirectUrl = this.Urls.browse_content(`sha1_git:${origin.content[0].sha1git}`); | ||||
const persistentId = `swh:1:cnt:${origin.content[0].sha1git}`; | const persistentId = `swh:1:cnt:${origin.content[0].sha1git}`; | ||||
searchShouldRedirect(persistentId, redirectUrl); | searchShouldRedirect(persistentId, redirectUrl); | ||||
}); | }); | ||||
Done Inline Actionsit('should not send request to the search endpoint', function() anlambert: `it('should not send request to the search endpoint', function()` | |||||
it('should not send request to the search endpoint', function() { | |||||
cy.server(); | |||||
const persistentId = `swh:1:rev:${origin.revisions[0]}`; | |||||
cy.route({ | |||||
Done Inline ActionsUse `${this.Urls.api_1_origin_search()}**` here instead of harcoding the url anlambert: Use ``${this.Urls.api_1_origin_search()}**`` here instead of harcoding the url | |||||
method: 'GET', | |||||
url: `${this.Urls.api_1_resolve()}**`, | |||||
}).as('resolvePid'); | |||||
cy.route({ | |||||
method: 'GET', | |||||
url: `${this.Urls.api_1_origin_search()}**`, | |||||
}).as('searchOrigin'); | |||||
cy.get('#origins-url-patterns') | |||||
.type(persistentId); | |||||
cy.get('.swh-search-icon') | |||||
.click(); | |||||
cy.wait('@resolvePid'); | |||||
cy.xhrShouldBeCalled('resolvePid', 1); | |||||
cy.xhrShouldBeCalled('searchOrigin', 0); | |||||
}); | |||||
}); | }); | ||||
context('Test invalid persistent ids', function() { | context('Test invalid persistent ids', function() { | ||||
it('should show not found for directory', function() { | it('should show not found for directory', function() { | ||||
const persistentId = `swh:1:dir:${this.unarchivedRepo.rootDirectory}`; | const persistentId = `swh:1:dir:${this.unarchivedRepo.rootDirectory}`; | ||||
const msg = `Directory with sha1_git ${this.unarchivedRepo.rootDirectory} not found`; | const msg = `Directory with sha1_git ${this.unarchivedRepo.rootDirectory} not found`; | ||||
searchShouldShowNotFound(persistentId, msg); | searchShouldShowNotFound(persistentId, msg); | ||||
Show All 16 Lines | context('Test invalid persistent ids', function() { | ||||
it('should show not found for content', function() { | it('should show not found for content', function() { | ||||
const persistentId = `swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`; | const persistentId = `swh:1:cnt:${this.unarchivedRepo.content[0].sha1git}`; | ||||
const msg = `Content with sha1_git checksum equals to ${this.unarchivedRepo.content[0].sha1git} not found!`; | const msg = `Content with sha1_git checksum equals to ${this.unarchivedRepo.content[0].sha1git} not found!`; | ||||
searchShouldShowNotFound(persistentId, msg); | searchShouldShowNotFound(persistentId, msg); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
No newline at end of file |
(C) 2019-2020