diff --git a/client/containers/workflow-history/component.vue b/client/containers/workflow-history/component.vue index 20767ef9f..22f5cdb75 100644 --- a/client/containers/workflow-history/component.vue +++ b/client/containers/workflow-history/component.vue @@ -43,6 +43,8 @@ import { SelectInput, } from '~components'; +import { httpService } from '~services'; + export default { name: 'history', data() { @@ -88,7 +90,6 @@ export default { 'workflowHistoryEventHighlightList', 'workflowHistoryEventHighlightListEnabled', 'workflowId', - 'origin', ], created() { this.onResizeWindow = debounce(() => { @@ -314,6 +315,21 @@ export default { }); } }, + exportHistory(e) { + const target = e.target; + + httpService.get(this.baseAPIURL + '/export').then(historyJson => { + const blob = new Blob([JSON.stringify(historyJson)], { + type: 'application/json', + }); + + target.href = window.URL.createObjectURL(blob); + target.download = this.exportFilename; + target.click(); + }); + + return false; + }, }, watch: { eventId(eventId) { @@ -398,10 +414,7 @@ export default { class="show-timeline-btn" >{{ graphView === GRAPH_VIEW_TIMELINE ? 'hide' : 'show' }} timeline - Export diff --git a/client/containers/workflow-history/connector.js b/client/containers/workflow-history/connector.js index 0383954b2..ba22c0962 100644 --- a/client/containers/workflow-history/connector.js +++ b/client/containers/workflow-history/connector.js @@ -21,11 +21,9 @@ import { connect } from 'vuex-connect'; import { WORKFLOW_EXECUTION_PENDING_TASK_COUNT } from '../workflow/getter-types'; -import { DOMAIN_CROSS_ORIGIN } from '../domain/getter-types'; const gettersToProps = { pendingTaskCount: WORKFLOW_EXECUTION_PENDING_TASK_COUNT, - origin: DOMAIN_CROSS_ORIGIN, }; const stateToProps = { diff --git a/client/test/index.js b/client/test/index.js index 6a96d77a5..fc3d933d6 100644 --- a/client/test/index.js +++ b/client/test/index.js @@ -72,6 +72,7 @@ chai.should(); chai.use(require('chai-dom')); chai.use(require('chai-string')); chai.use(require('chai-things')); +chai.use(require('chai-spies')); require('nathanboktae-browser-test-utils'); diff --git a/client/test/scenario.js b/client/test/scenario.js index f83626035..62cc6936c 100644 --- a/client/test/scenario.js +++ b/client/test/scenario.js @@ -365,6 +365,14 @@ Scenario.prototype.withFullHistory = function withFullHistory(events, options) { .withHistory(parsedEvents.slice(third + third), false, options); }; +Scenario.prototype.withExportHistory = function withExportHistory(events) { + const jsonHistoryEvents = getFixture('history.emailRun1', events); + + this.api.getOnce(`${this.execApiBase()}/export`, jsonHistoryEvents); + + return this; +}; + Scenario.prototype.withQuery = function withQuery(query) { this.api.getOnce( `${this.execApiBase()}/query`, diff --git a/client/test/workflow.test.js b/client/test/workflow.test.js index 0755eb728..868ec1a19 100644 --- a/client/test/workflow.test.js +++ b/client/test/workflow.test.js @@ -505,13 +505,13 @@ describe('Workflow', () => { ...o, }); - scenario.withFullHistory(opts.events); + scenario.withFullHistory(opts.events).withExportHistory(opts.events); const historyEl = await scenario .render(opts.attach) .waitUntilExists('section.execution.ready'); - return [historyEl, scenario]; + return [historyEl, scenario, opts]; } it('should pick default view format from localstorage if exists ', async function test() { localStorage.setItem('ci-test:history-viewing-format', 'json'); @@ -570,19 +570,23 @@ describe('Workflow', () => { }); it('should allow downloading the full history via export', async function test() { - const [, scenario] = await historyTest(this.test); + const [, scenario, opts] = await historyTest(this.test); const exportEl = await scenario.vm.$el.waitUntilExists( 'section.history .controls a.export' ); + const downloadLink = 'javascript:void(0);'; //prevent createing a redirectable link - exportEl.should.have.attr( - 'href', - 'http://localhost:8090/api/domains/ci-test/workflows/email-daily-summaries/emailRun1/export' - ); - exportEl.should.have.attr( - 'download', - 'email daily summaries - emailRun1.json' - ); + chai.spy.on(window.URL, 'createObjectURL', () => downloadLink); + exportEl.trigger('click'); + + await retry(() => { + window.URL.createObjectURL.should.have.been.called(); + exportEl.should.have.attr('href', downloadLink); + exportEl.should.have.attr( + 'download', + 'email daily summaries - emailRun1.json' + ); + }); }); describe('Compact View', function describeTest() { diff --git a/package-lock.json b/package-lock.json index 7ba99f387..47d0c931f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3428,6 +3428,12 @@ "integrity": "sha512-ZzGlEfk1UhHH5+N0t9bDqstOxPEXmn3EyXvtsok5rfXVDOFDJbHVy12rED6ZwkJAUDs2w7/Da4Hlq2LB63kltg==", "dev": true }, + "chai-spies": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/chai-spies/-/chai-spies-1.1.0.tgz", + "integrity": "sha512-ikaUhQvQWchRYj2K54itFp3nrcxaFRpSDQxDlRzSn9aWgu9Pi7lD8yFxTso4WnQ39+WZ69oB/qOvqp+isJIIWA==", + "dev": true + }, "chai-string": { "version": "1.5.0", "resolved": "https://unpm.uberinternal.com/chai-string/-/chai-string-1.5.0.tgz", diff --git a/package.json b/package.json index aa861b6ef..640903514 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,7 @@ "babel-jest": "^24.9.0", "chai": "^4.1.2", "chai-dom": "^1.7.0", + "chai-spies": "^1.1.0", "chai-string": "^1.5.0", "chai-things": "^0.2.0", "eslint": "^7.32.0",