Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/vault.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 | ||||
*/ | */ | ||||
let vaultItems = []; | let vaultItems = []; | ||||
const progressbarColors = { | const progressbarColors = { | ||||
'new': 'rgba(128, 128, 128, 0.5)', | 'new': 'rgba(128, 128, 128, 0.5)', | ||||
'pending': 'rgba(0, 0, 255, 0.5)', | 'pending': 'rgba(0, 0, 255, 0.5)', | ||||
'done': 'rgb(92, 184, 92)' | 'done': 'rgb(92, 184, 92)' | ||||
}; | }; | ||||
function createVaultCookingTask(objectType) { | function checkVaultCookingTask(objectType) { | ||||
cy.contains('button', 'Actions') | cy.contains('button', 'Actions') | ||||
.click(); | .click(); | ||||
cy.contains('.dropdown-item', 'Download') | cy.contains('.dropdown-item', 'Download') | ||||
.click(); | .click(); | ||||
cy.contains('.dropdown-item', objectType) | cy.contains('.dropdown-item', objectType) | ||||
.click(); | .click(); | ||||
cy.get('.modal-dialog') | cy.wait('@checkVaultCookingTask'); | ||||
.contains('button:visible', 'Ok') | |||||
.click(); | |||||
} | } | ||||
function updateVaultItemList(vaultUrl, vaultItems) { | function updateVaultItemList(vaultUrl, vaultItems) { | ||||
cy.visit(vaultUrl) | cy.visit(vaultUrl) | ||||
.then(() => { | .then(() => { | ||||
// Add uncooked task to localStorage | // Add uncooked task to localStorage | ||||
// which updates it in vault items list | // which updates it in vault items list | ||||
window.localStorage.setItem('swh-vault-cooking-tasks', JSON.stringify(vaultItems)); | window.localStorage.setItem('swh-vault-cooking-tasks', JSON.stringify(vaultItems)); | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | describe('Vault Cooking User Interface Tests', function() { | ||||
it('should create a directory cooking task and report its status', function() { | it('should create a directory cooking task and report its status', function() { | ||||
// Browse a directory | // Browse a directory | ||||
cy.visit(this.directoryUrl); | cy.visit(this.directoryUrl); | ||||
// Stub responses when requesting the vault API to simulate | // Stub responses when requesting the vault API to simulate | ||||
// a task has been created | // a task has been created | ||||
cy.route({ | |||||
method: 'GET', | |||||
url: this.vaultDirectoryUrl, | |||||
response: {'exception': 'NotFoundExc'} | |||||
}).as('checkVaultCookingTask'); | |||||
cy.route({ | cy.route({ | ||||
method: 'POST', | method: 'POST', | ||||
url: this.vaultDirectoryUrl, | url: this.vaultDirectoryUrl, | ||||
response: this.genVaultDirCookingResponse('new') | response: this.genVaultDirCookingResponse('new') | ||||
}).as('createVaultCookingTask'); | }).as('createVaultCookingTask'); | ||||
checkVaultCookingTask('as tarball'); | |||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: this.vaultDirectoryUrl, | url: this.vaultDirectoryUrl, | ||||
response: this.genVaultDirCookingResponse('new') | response: this.genVaultDirCookingResponse('new') | ||||
}).as('checkVaultCookingTask'); | }).as('checkVaultCookingTask'); | ||||
// Create a vault cooking task through the GUI | // Create a vault cooking task through the GUI | ||||
createVaultCookingTask('Directory'); | cy.get('.modal-dialog') | ||||
.contains('button:visible', 'Ok') | |||||
.click(); | |||||
cy.wait('@createVaultCookingTask'); | cy.wait('@createVaultCookingTask'); | ||||
// Check that a redirection to the vault UI has been performed | // Check that a redirection to the vault UI has been performed | ||||
cy.url().should('eq', Cypress.config().baseUrl + this.Urls.browse_vault()); | cy.url().should('eq', Cypress.config().baseUrl + this.Urls.browse_vault()); | ||||
cy.wait('@checkVaultCookingTask').then(() => { | cy.wait('@checkVaultCookingTask').then(() => { | ||||
testStatus(this.directory, progressbarColors['new'], 'new', 'new'); | testStatus(this.directory, progressbarColors['new'], 'new', 'new'); | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | describe('Vault Cooking User Interface Tests', function() { | ||||
}); | }); | ||||
it('should create a revision cooking task and report its status', function() { | it('should create a revision cooking task and report its status', function() { | ||||
// Browse a revision | // Browse a revision | ||||
cy.visit(this.revisionUrl); | cy.visit(this.revisionUrl); | ||||
// Stub responses when requesting the vault API to simulate | // Stub responses when requesting the vault API to simulate | ||||
// a task has been created | // a task has been created | ||||
cy.route({ | |||||
method: 'GET', | |||||
url: this.vaultRevisionUrl, | |||||
response: {'exception': 'NotFoundExc'} | |||||
}).as('checkVaultCookingTask'); | |||||
cy.route({ | cy.route({ | ||||
method: 'POST', | method: 'POST', | ||||
url: this.vaultRevisionUrl, | url: this.vaultRevisionUrl, | ||||
response: this.genVaultRevCookingResponse('new') | response: this.genVaultRevCookingResponse('new') | ||||
}).as('createVaultCookingTask'); | }).as('createVaultCookingTask'); | ||||
// Create a vault cooking task through the GUI | |||||
checkVaultCookingTask('as git'); | |||||
cy.route({ | cy.route({ | ||||
method: 'GET', | method: 'GET', | ||||
url: this.vaultRevisionUrl, | url: this.vaultRevisionUrl, | ||||
response: this.genVaultRevCookingResponse('new') | response: this.genVaultRevCookingResponse('new') | ||||
}).as('checkVaultCookingTask'); | }).as('checkVaultCookingTask'); | ||||
// Create a vault cooking task through the GUI | // Create a vault cooking task through the GUI | ||||
createVaultCookingTask('Revision'); | cy.get('.modal-dialog') | ||||
.contains('button:visible', 'Ok') | |||||
.click(); | |||||
cy.wait('@createVaultCookingTask'); | cy.wait('@createVaultCookingTask'); | ||||
// Check that a redirection to the vault UI has been performed | // Check that a redirection to the vault UI has been performed | ||||
cy.url().should('eq', Cypress.config().baseUrl + this.Urls.browse_vault()); | cy.url().should('eq', Cypress.config().baseUrl + this.Urls.browse_vault()); | ||||
cy.wait('@checkVaultCookingTask').then(() => { | cy.wait('@checkVaultCookingTask').then(() => { | ||||
testStatus(this.revision, progressbarColors['new'], 'new', 'new'); | testStatus(this.revision, progressbarColors['new'], 'new', 'new'); | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | cy.get(`#vault-task-${this.revision}`) | ||||
.find('input[type="checkbox"]') | .find('input[type="checkbox"]') | ||||
.click(); | .click(); | ||||
cy.contains('button', 'Remove selected tasks') | cy.contains('button', 'Remove selected tasks') | ||||
.click(); | .click(); | ||||
cy.get(`#vault-task-${this.revision}`) | cy.get(`#vault-task-${this.revision}`) | ||||
.should('not.exist'); | .should('not.exist'); | ||||
}); | }); | ||||
it('should offer to immediately download a directory tarball if already cooked', function() { | |||||
// Browse a directory | |||||
cy.visit(this.directoryUrl); | |||||
// Stub responses when requesting the vault API to simulate | |||||
// the directory tarball has already been cooked | |||||
cy.route({ | |||||
method: 'GET', | |||||
url: this.vaultDirectoryUrl, | |||||
response: this.genVaultDirCookingResponse('done') | |||||
}).as('checkVaultCookingTask'); | |||||
// Stub response to the vault API to simulate archive download | |||||
cy.route({ | |||||
method: 'GET', | |||||
url: this.vaultFetchDirectoryUrl, | |||||
response: `fx:${this.directory}.tar.gz,binary`, | |||||
headers: { | |||||
'Content-disposition': `attachment; filename=${this.directory}.tar.gz`, | |||||
'Content-Type': 'application/gzip' | |||||
} | |||||
}).as('fetchCookedArchive'); | |||||
// Create a vault cooking task through the GUI | |||||
checkVaultCookingTask('as tarball'); | |||||
// Start archive download through the GUI | |||||
cy.get('.modal-dialog') | |||||
.contains('button:visible', 'Ok') | |||||
.click(); | |||||
cy.wait('@fetchCookedArchive'); | |||||
}); | |||||
it('should offer to immediately download a revision gitfast archive if already cooked', function() { | |||||
// Browse a directory | |||||
cy.visit(this.revisionUrl); | |||||
// Stub responses when requesting the vault API to simulate | |||||
// the directory tarball has already been cooked | |||||
cy.route({ | |||||
method: 'GET', | |||||
url: this.vaultRevisionUrl, | |||||
response: this.genVaultRevCookingResponse('done') | |||||
}).as('checkVaultCookingTask'); | |||||
// Stub response to the vault API to simulate archive download | |||||
cy.route({ | |||||
method: 'GET', | |||||
url: this.vaultFetchRevisionUrl, | |||||
response: `fx:${this.revision}.gitfast.gz,binary`, | |||||
headers: { | |||||
'Content-disposition': `attachment; filename=${this.revision}.gitfast.gz`, | |||||
'Content-Type': 'application/gzip' | |||||
} | |||||
}).as('fetchCookedArchive'); | |||||
checkVaultCookingTask('as git'); | |||||
// Start archive download through the GUI | |||||
cy.get('.modal-dialog') | |||||
.contains('button:visible', 'Ok') | |||||
.click(); | |||||
cy.wait('@fetchCookedArchive'); | |||||
}); | |||||
}); | }); |