diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/DataView.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/DataView.spec.js deleted file mode 100644 index e0d9ab6..0000000 --- a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/DataView.spec.js +++ /dev/null @@ -1,32 +0,0 @@ -import { expect } from 'chai' -import { mount, createWrapper } from '@vue/test-utils' -import DataView from '@/views/Main/Workspace/Tabs/Tab/DataView' -import sinon from 'sinon' - -describe('DataView.vue', () => { - it('emits update on mode changing', async () => { - const wrapper = mount(DataView) - - const pivotBtn = createWrapper(wrapper.findComponent({ name: 'pivotIcon' }).vm.$parent) - await pivotBtn.trigger('click') - - expect(wrapper.emitted('update')).to.have.lengthOf(1) - }) - - it('method getOptionsForSave call the same method of the current view component', async () => { - const wrapper = mount(DataView) - - const chart = wrapper.findComponent({ name: 'Chart' }).vm - sinon.stub(chart, 'getOptionsForSave').returns({ here_are: 'chart_settings' }) - - expect(wrapper.vm.getOptionsForSave()).to.eql({ here_are: 'chart_settings' }) - - const pivotBtn = createWrapper(wrapper.findComponent({ name: 'pivotIcon' }).vm.$parent) - await pivotBtn.trigger('click') - - const pivot = wrapper.findComponent({ name: 'pivot' }).vm - sinon.stub(pivot, 'getOptionsForSave').returns({ here_are: 'pivot_settings' }) - - expect(wrapper.vm.getOptionsForSave()).to.eql({ here_are: 'pivot_settings' }) - }) -}) diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/DataView.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/DataView.spec.js new file mode 100644 index 0000000..15a8402 --- /dev/null +++ b/tests/views/Main/Workspace/Tabs/Tab/DataView/DataView.spec.js @@ -0,0 +1,81 @@ +import { expect } from 'chai' +import { mount, createWrapper } from '@vue/test-utils' +import DataView from '@/views/Main/Workspace/Tabs/Tab/DataView' +import sinon from 'sinon' + +describe('DataView.vue', () => { + afterEach(() => { + sinon.restore() + }) + + it('emits update on mode changing', async () => { + const wrapper = mount(DataView) + + const pivotBtn = createWrapper(wrapper.findComponent({ name: 'pivotIcon' }).vm.$parent) + await pivotBtn.trigger('click') + + expect(wrapper.emitted('update')).to.have.lengthOf(1) + }) + + it('method getOptionsForSave calls the same method of the current view component', async () => { + const wrapper = mount(DataView) + + const chart = wrapper.findComponent({ name: 'Chart' }).vm + sinon.stub(chart, 'getOptionsForSave').returns({ here_are: 'chart_settings' }) + + expect(wrapper.vm.getOptionsForSave()).to.eql({ here_are: 'chart_settings' }) + + const pivotBtn = createWrapper(wrapper.findComponent({ name: 'pivotIcon' }).vm.$parent) + await pivotBtn.trigger('click') + + const pivot = wrapper.findComponent({ name: 'pivot' }).vm + sinon.stub(pivot, 'getOptionsForSave').returns({ here_are: 'pivot_settings' }) + + expect(wrapper.vm.getOptionsForSave()).to.eql({ here_are: 'pivot_settings' }) + }) + + it('method saveAsSvg calls the same method of the current view component', async () => { + const wrapper = mount(DataView) + + // Find chart and spy the method + const chart = wrapper.findComponent({ name: 'Chart' }).vm + sinon.spy(chart, 'saveAsSvg') + + // Export to svg + const svgBtn = createWrapper(wrapper.findComponent({ name: 'exportToSvgIcon' }).vm.$parent) + await svgBtn.trigger('click') + expect(chart.saveAsSvg.calledOnce).to.equal(true) + + // Switch to pivot + const pivotBtn = createWrapper(wrapper.findComponent({ name: 'pivotIcon' }).vm.$parent) + await pivotBtn.trigger('click') + + // Find pivot and spy the method + const pivot = wrapper.findComponent({ name: 'pivot' }).vm + sinon.spy(pivot, 'saveAsSvg') + + // Export to svg + await svgBtn.trigger('click') + expect(pivot.saveAsSvg.calledOnce).to.equal(true) + }) + + it('shows alert when ClipboardItem is not supported', async () => { + const ClipboardItem = window.ClipboardItem + delete window.ClipboardItem + sinon.spy(window, 'alert') + const wrapper = mount(DataView) + + const copyBtn = createWrapper(wrapper.findComponent({ name: 'clipboardIcon' }).vm.$parent) + await copyBtn.trigger('click') + + expect( + window.alert.calledOnceWith( + "Your browser doesn't support copying images into the clipboard. " + + 'If you use Firefox you can enable it ' + + 'by setting dom.events.asyncClipboard.clipboardItem to true.' + ) + ).to.equal(true) + + window.ClipboardItem = ClipboardItem + }) +}) diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/Pivot.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Pivot/Pivot.spec.js similarity index 100% rename from tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/Pivot.spec.js rename to tests/views/Main/Workspace/Tabs/Tab/DataView/Pivot/Pivot.spec.js diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotSortBtn.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/PivotSortBtn.spec.js similarity index 100% rename from tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotSortBtn.spec.js rename to tests/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/PivotSortBtn.spec.js diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotUi.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/PivotUi.spec.js similarity index 100% rename from tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotUi.spec.js rename to tests/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/PivotUi.spec.js diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/pivotHelper.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Pivot/pivotHelper.spec.js similarity index 100% rename from tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/pivotHelper.spec.js rename to tests/views/Main/Workspace/Tabs/Tab/DataView/Pivot/pivotHelper.spec.js