Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/vault.spec.js
Show All 19 Lines | function checkVaultCookingTask(objectType) { | ||||
cy.wait('@checkVaultCookingTask'); | cy.wait('@checkVaultCookingTask'); | ||||
} | } | ||||
function getVaultItemList() { | function getVaultItemList() { | ||||
return JSON.parse(window.localStorage.getItem('swh-vault-cooking-tasks')); | return JSON.parse(window.localStorage.getItem('swh-vault-cooking-tasks')); | ||||
} | } | ||||
function updateVaultItemList(vaultUrl, vaultItems) { | function updateVaultItemList(vaultItems) { | ||||
cy.visit(vaultUrl) | |||||
.then(() => { | |||||
// Add uncooked task to localStorage | |||||
// 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)); | ||||
}); | |||||
} | } | ||||
// Mocks API response : /api/1/vault/(:bundleType)/(:swhid) | // Mocks API response : /api/1/vault/(:bundleType)/(:swhid) | ||||
// bundleType : {'flat', 'gitfast'} | // bundleType : {'flat', 'gitfast'} | ||||
function genVaultCookingResponse(bundleType, swhid, status, message, fetchUrl) { | function genVaultCookingResponse(bundleType, swhid, status, message, fetchUrl) { | ||||
return { | return { | ||||
'bundle_type': bundleType, | 'bundle_type': bundleType, | ||||
'id': 1, | 'id': 1, | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | it('should report an error when a cooking task creation failed', function() { | ||||
// Check error alert is displayed | // Check error alert is displayed | ||||
cy.get('.alert-danger') | cy.get('.alert-danger') | ||||
.should('be.visible') | .should('be.visible') | ||||
.should('contain', 'Archive cooking request submission failed.'); | .should('contain', 'Archive cooking request submission failed.'); | ||||
}); | }); | ||||
it('should display previous cooking tasks', function() { | it('should display previous cooking tasks', function() { | ||||
updateVaultItemList(this.Urls.browse_vault(), this.vaultItems); | updateVaultItemList(this.vaultItems); | ||||
cy.visit(this.Urls.browse_vault()); | cy.visit(this.Urls.browse_vault()); | ||||
cy.contains(`#vault-task-${CSS.escape(this.revision)} button`, 'Download') | cy.contains(`#vault-task-${CSS.escape(this.revision)} button`, 'Download') | ||||
.click(); | .click(); | ||||
}); | }); | ||||
it('should display and upgrade previous cooking tasks from the legacy format', function() { | it('should display and upgrade previous cooking tasks from the legacy format', function() { | ||||
updateVaultItemList(this.Urls.browse_vault(), this.legacyVaultItems); | updateVaultItemList(this.legacyVaultItems); | ||||
// updateVaultItemList doesn't work in this test?!?! | |||||
window.localStorage.setItem('swh-vault-cooking-tasks', JSON.stringify(this.vaultItems)); | |||||
cy.visit(this.Urls.browse_vault()); | cy.visit(this.Urls.browse_vault()); | ||||
// Check it is displayed | // Check it is displayed | ||||
cy.contains(`#vault-task-${CSS.escape(this.revision)} button`, 'Download') | cy.contains(`#vault-task-${CSS.escape(this.revision)} button`, 'Download') | ||||
.click(); | .then(() => { | ||||
// Check the LocalStorage was upgraded | // Check the LocalStorage was upgraded | ||||
expect(getVaultItemList()).to.deep.equal(this.vaultItems); | expect(getVaultItemList()).to.deep.equal(this.vaultItems); | ||||
}); | }); | ||||
}); | |||||
it('should create a directory cooking task and report the success', function() { | it('should create a directory cooking task and report the success', function() { | ||||
// Browse a directory | // Browse a directory | ||||
cy.visit(this.directoryUrl); | cy.visit(this.directoryUrl); | ||||
// Stub response to the vault API to simulate archive download | // Stub response to the vault API to simulate archive download | ||||
cy.intercept('GET', this.vaultFetchDirectoryUrl, { | cy.intercept('GET', this.vaultFetchDirectoryUrl, { | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | it('should create a directory cooking task from the release view', function() { | ||||
// Check success alert is displayed | // Check success alert is displayed | ||||
cy.get('.alert-success') | cy.get('.alert-success') | ||||
.should('be.visible') | .should('be.visible') | ||||
.should('contain', 'Archive cooking request successfully submitted.'); | .should('contain', 'Archive cooking request successfully submitted.'); | ||||
}); | }); | ||||
it('should offer to recook an archive if no more available to download', function() { | it('should offer to recook an archive if no more available to download', function() { | ||||
updateVaultItemList(this.Urls.browse_vault(), this.vaultItems); | updateVaultItemList(this.vaultItems); | ||||
// Send 404 when fetching vault item | // Send 404 when fetching vault item | ||||
cy.intercept({url: this.vaultFetchRevisionUrl}, { | cy.intercept({url: this.vaultFetchRevisionUrl}, { | ||||
statusCode: 404, | statusCode: 404, | ||||
body: { | body: { | ||||
'exception': 'NotFoundExc', | 'exception': 'NotFoundExc', | ||||
'reason': `Revision with ID '${this.revision}' not found.` | 'reason': `Revision with ID '${this.revision}' not found.` | ||||
}, | }, | ||||
headers: { | headers: { | ||||
'Content-Type': 'json' | 'Content-Type': 'json' | ||||
} | } | ||||
}).as('fetchCookedArchive'); | }).as('fetchCookedArchive'); | ||||
cy.get(`#vault-task-${CSS.escape(this.revision)} .vault-dl-link button`) | cy.visit(this.Urls.browse_vault()) | ||||
.get(`#vault-task-${CSS.escape(this.revision)} .vault-dl-link button`) | |||||
.click(); | .click(); | ||||
cy.wait('@fetchCookedArchive').then(() => { | cy.wait('@fetchCookedArchive').then(() => { | ||||
cy.intercept('POST', this.vaultRevisionUrl, { | cy.intercept('POST', this.vaultRevisionUrl, { | ||||
body: this.genVaultRevCookingResponse('new') | body: this.genVaultRevCookingResponse('new') | ||||
}).as('createVaultCookingTask'); | }).as('createVaultCookingTask'); | ||||
cy.intercept(this.vaultRevisionUrl, { | cy.intercept(this.vaultRevisionUrl, { | ||||
Show All 9 Lines | cy.wait('@fetchCookedArchive').then(() => { | ||||
.then(() => { | .then(() => { | ||||
testStatus(this.revision, progressbarColors['new'], 'new', 'new'); | testStatus(this.revision, progressbarColors['new'], 'new', 'new'); | ||||
}); | }); | ||||
}); | }); | ||||
}); | }); | ||||
it('should remove selected vault items', function() { | it('should remove selected vault items', function() { | ||||
updateVaultItemList(this.Urls.browse_vault(), this.vaultItems); | updateVaultItemList(this.vaultItems); | ||||
cy.get(`#vault-task-${CSS.escape(this.revision)}`) | cy.visit(this.Urls.browse_vault()) | ||||
.get(`#vault-task-${CSS.escape(this.revision)}`) | |||||
.find('input[type="checkbox"]') | .find('input[type="checkbox"]') | ||||
.click({force: true}); | .click({force: true}); | ||||
cy.contains('button', 'Remove selected tasks') | cy.contains('button', 'Remove selected tasks') | ||||
.click(); | .click(); | ||||
cy.get(`#vault-task-${CSS.escape(this.revision)}`) | cy.get(`#vault-task-${CSS.escape(this.revision)}`) | ||||
.should('not.exist'); | .should('not.exist'); | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |