diff --git a/cypress/integration/vault.spec.js b/cypress/integration/vault.spec.js --- a/cypress/integration/vault.spec.js +++ b/cypress/integration/vault.spec.js @@ -67,8 +67,10 @@ describe('Vault Cooking User Interface Tests', function() { before(function() { - this.directory = this.origin[0].directory[0].id; - this.directoryUrl = this.Urls.browse_directory(this.directory); + const dirInfo = this.origin[0].directory[0]; + this.directory = dirInfo.id; + this.directoryUrl = this.Urls.browse_origin_directory() + + `?origin_url=${this.origin[0].url}&path=${dirInfo.path}`; this.vaultDirectoryUrl = this.Urls.api_1_vault_cook_directory(this.directory); this.vaultFetchDirectoryUrl = this.Urls.api_1_vault_fetch_directory(this.directory); @@ -130,70 +132,82 @@ response: this.genVaultDirCookingResponse('new') }).as('checkVaultCookingTask'); - // Create a vault cooking task through the GUI - cy.get('.modal-dialog') - .contains('button:visible', 'Ok') - .click(); + cy.window().then(win => { + const swhIdsContext = win.swh.webapp.getSwhIdsContext(); + const browseDirectoryUrl = swhIdsContext.directory.swhid_with_context_url; - cy.wait('@createVaultCookingTask'); + // Create a vault cooking task through the GUI + cy.get('.modal-dialog') + .contains('button:visible', 'Ok') + .click(); - // Check that a redirection to the vault UI has been performed - cy.url().should('eq', Cypress.config().baseUrl + this.Urls.browse_vault()); + cy.wait('@createVaultCookingTask'); - cy.wait('@checkVaultCookingTask').then(() => { - testStatus(this.directory, progressbarColors['new'], 'new', 'new'); - }); + // Check that a redirection to the vault UI has been performed + cy.url().should('eq', Cypress.config().baseUrl + this.Urls.browse_vault()); - // Stub response to the vault API indicating the task is processing - cy.route({ - method: 'GET', - url: this.vaultDirectoryUrl, - response: this.genVaultDirCookingResponse('pending', 'Processing...') - }).as('checkVaultCookingTask'); + cy.wait('@checkVaultCookingTask').then(() => { + testStatus(this.directory, progressbarColors['new'], 'new', 'new'); + }); - cy.wait('@checkVaultCookingTask').then(() => { - testStatus(this.directory, progressbarColors['pending'], 'Processing...', 'pending'); - }); + // Stub response to the vault API indicating the task is processing + cy.route({ + method: 'GET', + url: this.vaultDirectoryUrl, + response: this.genVaultDirCookingResponse('pending', 'Processing...') + }).as('checkVaultCookingTask'); - // Stub response to the vault API indicating the task is finished - cy.route({ - method: 'GET', - url: this.vaultDirectoryUrl, - response: this.genVaultDirCookingResponse('done') - }).as('checkVaultCookingTask'); + cy.wait('@checkVaultCookingTask').then(() => { + testStatus(this.directory, progressbarColors['pending'], 'Processing...', 'pending'); + }); - cy.wait('@checkVaultCookingTask').then(() => { - testStatus(this.directory, progressbarColors['done'], 'done', 'done'); - }); + // Stub response to the vault API indicating the task is finished + 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'); + cy.wait('@checkVaultCookingTask').then(() => { + testStatus(this.directory, progressbarColors['done'], 'done', 'done'); + }); - cy.get(`#vault-task-${this.directory} .vault-dl-link button`) - .click(); + // 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'); + + cy.get(`#vault-task-${this.directory} .vault-origin a`) + .should('have.text', this.origin[0].url) + .should('have.attr', 'href', `${this.Urls.browse_origin()}?origin_url=${this.origin[0].url}`); + + cy.get(`#vault-task-${this.directory} .vault-object-info a`) + .should('have.text', this.directory) + .should('have.attr', 'href', browseDirectoryUrl); + + cy.get(`#vault-task-${this.directory} .vault-dl-link button`) + .click(); - cy.wait('@fetchCookedArchive').then((xhr) => { - assert.isNotNull(xhr.response.body); + cy.wait('@fetchCookedArchive').then((xhr) => { + assert.isNotNull(xhr.response.body); + }); }); - }); it('should create a revision cooking task and report its status', function() { cy.adminLogin(); + // Browse a revision cy.visit(this.revisionUrl); // Stub responses when requesting the vault API to simulate // a task has been created - cy.route({ method: 'GET', url: this.vaultRevisionUrl, @@ -215,59 +229,71 @@ response: this.genVaultRevCookingResponse('new') }).as('checkVaultCookingTask'); - // Create a vault cooking task through the GUI - cy.get('.modal-dialog') - .contains('button:visible', 'Ok') - .click(); + cy.window().then(win => { + const swhIdsContext = win.swh.webapp.getSwhIdsContext(); + const browseRevisionUrl = swhIdsContext.revision.swhid_url; - cy.wait('@createVaultCookingTask'); + // Create a vault cooking task through the GUI + cy.get('.modal-dialog') + .contains('button:visible', 'Ok') + .click(); - // Check that a redirection to the vault UI has been performed - cy.url().should('eq', Cypress.config().baseUrl + this.Urls.browse_vault()); + cy.wait('@createVaultCookingTask'); - cy.wait('@checkVaultCookingTask').then(() => { - testStatus(this.revision, progressbarColors['new'], 'new', 'new'); - }); + // Check that a redirection to the vault UI has been performed + cy.url().should('eq', Cypress.config().baseUrl + this.Urls.browse_vault()); - // Stub response to the vault API indicating the task is processing - cy.route({ - method: 'GET', - url: this.vaultRevisionUrl, - response: this.genVaultRevCookingResponse('pending', 'Processing...') - }).as('checkVaultCookingTask'); + cy.wait('@checkVaultCookingTask').then(() => { + testStatus(this.revision, progressbarColors['new'], 'new', 'new'); + }); - cy.wait('@checkVaultCookingTask').then(() => { - testStatus(this.revision, progressbarColors['pending'], 'Processing...', 'pending'); - }); + // Stub response to the vault API indicating the task is processing + cy.route({ + method: 'GET', + url: this.vaultRevisionUrl, + response: this.genVaultRevCookingResponse('pending', 'Processing...') + }).as('checkVaultCookingTask'); - // Stub response to the vault API indicating the task is finished - cy.route({ - method: 'GET', - url: this.vaultRevisionUrl, - response: this.genVaultRevCookingResponse('done') - }).as('checkVaultCookingTask'); + cy.wait('@checkVaultCookingTask').then(() => { + testStatus(this.revision, progressbarColors['pending'], 'Processing...', 'pending'); + }); - cy.wait('@checkVaultCookingTask').then(() => { - testStatus(this.revision, progressbarColors['done'], 'done', 'done'); - }); + // Stub response to the vault API indicating the task is finished + cy.route({ + method: 'GET', + url: this.vaultRevisionUrl, + response: this.genVaultRevCookingResponse('done') + }).as('checkVaultCookingTask'); - // Stub response to the vault API indicating 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'); + cy.wait('@checkVaultCookingTask').then(() => { + testStatus(this.revision, progressbarColors['done'], 'done', 'done'); + }); - cy.get(`#vault-task-${this.revision} .vault-dl-link button`) - .click(); + // Stub response to the vault API indicating 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'); + + cy.get(`#vault-task-${this.revision} .vault-origin`) + .should('have.text', 'unknown'); + + cy.get(`#vault-task-${this.revision} .vault-object-info a`) + .should('have.text', this.revision) + .should('have.attr', 'href', browseRevisionUrl); + + cy.get(`#vault-task-${this.revision} .vault-dl-link button`) + .click(); - cy.wait('@fetchCookedArchive').then((xhr) => { - assert.isNotNull(xhr.response.body); + cy.wait('@fetchCookedArchive').then((xhr) => { + assert.isNotNull(xhr.response.body); + }); }); }); diff --git a/swh/web/assets/src/bundles/vault/vault-create-tasks.js b/swh/web/assets/src/bundles/vault/vault-create-tasks.js --- a/swh/web/assets/src/bundles/vault/vault-create-tasks.js +++ b/swh/web/assets/src/bundles/vault/vault-create-tasks.js @@ -33,6 +33,15 @@ } function addVaultCookingTask(cookingTask) { + + const swhidsContext = swh.webapp.getSwhIdsContext(); + cookingTask.origin = swhidsContext[cookingTask.object_type].context.origin; + cookingTask.path = swhidsContext[cookingTask.object_type].context.path; + cookingTask.browse_url = swhidsContext[cookingTask.object_type].swhid_with_context_url; + if (!cookingTask.browse_url) { + cookingTask.browse_url = swhidsContext[cookingTask.object_type].swhid_url; + } + let vaultCookingTasks = JSON.parse(localStorage.getItem('swh-vault-cooking-tasks')); if (!vaultCookingTasks) { vaultCookingTasks = []; diff --git a/swh/web/assets/src/bundles/vault/vault-ui.js b/swh/web/assets/src/bundles/vault/vault-ui.js --- a/swh/web/assets/src/bundles/vault/vault-ui.js +++ b/swh/web/assets/src/bundles/vault/vault-ui.js @@ -7,12 +7,13 @@ import {handleFetchError, handleFetchErrors, csrfPost} from 'utils/functions'; -let progress = `
-
-
-
;`; +let progress = + `
+
+
+
;`; let pollingInterval = 5000; let checkVaultId; @@ -133,7 +134,7 @@ } } $('.swh-vault-table tbody tr').each((i, row) => { - let objectId = $(row).find('.vault-object-id').data('object-id'); + let objectId = $(row).find('.vault-object-info').data('object-id'); if ($.inArray(objectId, currentObjectIds) === -1) { $(row).remove(); } @@ -154,14 +155,15 @@ let rowTask = $('#vault-task-' + cookingTask.object_id); - let downloadLinkWait = 'Waiting for download link to be available'; if (!rowTask.length) { - let browseUrl; - if (cookingTask.object_type === 'directory') { - browseUrl = Urls.browse_directory(cookingTask.object_id); - } else { - browseUrl = Urls.browse_revision(cookingTask.object_id); + let browseUrl = cookingTask.browse_url; + if (!browseUrl) { + if (cookingTask.object_type === 'directory') { + browseUrl = Urls.browse_directory(cookingTask.object_id); + } else { + browseUrl = Urls.browse_revision(cookingTask.object_id); + } } let progressBar = $.parseHTML(progress)[0]; @@ -169,26 +171,49 @@ updateProgressBar(progressBarContent, cookingTask); let tableRow; if (cookingTask.object_type === 'directory') { - tableRow = ``; + tableRow = + ``; } else { - tableRow = ``; + tableRow = + `'; } tableRow += '
'; - tableRow += ``; - tableRow += ``; - tableRow += `${cookingTask.object_type}`; - tableRow += `${cookingTask.object_id}`; - tableRow += `${progressBar.outerHTML}`; - let downloadLink = downloadLinkWait; + tableRow += + '`; + tableRow += + '`; + if (cookingTask.origin) { + tableRow += `` + + `` + + `${cookingTask.origin}`; + } else { + tableRow += `unknown`; + } + tableRow += + `` + + `${cookingTask.object_type}`; + tableRow += `` + + `id: ${cookingTask.object_id}`; + if (cookingTask.path) { + tableRow += `
path: ${cookingTask.path}`; + } + tableRow += ''; + tableRow += `${progressBar.outerHTML}`; + let downloadLink = ''; if (cookingTask.status === 'done') { - downloadLink = `'; - } else if (cookingTask.status === 'failed') { - downloadLink = ''; + downloadLink = + ''; } - tableRow += `${downloadLink}`; + tableRow += `${downloadLink}`; tableRow += ''; table.prepend(tableRow); } else { @@ -196,12 +221,12 @@ updateProgressBar(progressBar, cookingTask); let downloadLink = rowTask.find('.vault-dl-link'); if (cookingTask.status === 'done') { - downloadLink[0].innerHTML = `'; - } else if (cookingTask.status === 'failed') { + downloadLink[0].innerHTML = + ''; + } else { downloadLink[0].innerHTML = ''; - } else if (cookingTask.status === 'new') { - downloadLink[0].innerHTML = downloadLinkWait; } } } @@ -234,7 +259,7 @@ $('.swh-vault-table tbody tr').each((i, row) => { let taskSelected = $(row).find('.vault-task-toggle-selection').prop('checked'); if (taskSelected) { - let objectId = $(row).find('.vault-object-id').data('object-id'); + let objectId = $(row).find('.vault-object-info').data('object-id'); tasksToRemove.push(objectId); $(row).remove(); } diff --git a/swh/web/templates/browse/vault-ui.html b/swh/web/templates/browse/vault-ui.html --- a/swh/web/templates/browse/vault-ui.html +++ b/swh/web/templates/browse/vault-ui.html @@ -33,10 +33,11 @@
+ Origin Object type - Object id - Cooking status - + Object info + Cooking status +