diff --git a/src/components/charts/chart/chart.spec.js b/src/components/charts/chart/chart.spec.js index cf1744c8af3adb4cb22c85f55c04450a07919db1..0093f67a5cdb73b16d9239880d5379cf63b4d4b9 100644 --- a/src/components/charts/chart/chart.spec.js +++ b/src/components/charts/chart/chart.spec.js @@ -104,42 +104,88 @@ describe('chart component', () => { expect(wrapper.vm.chart).toBeDefined(); }); - describe('sets chart options', () => { - beforeEach(async () => { - createWrapper({ - options: { - title: { text: 'My chart title' }, - }, + describe('chart options', () => { + describe('when options are set', () => { + beforeEach(async () => { + createWrapper({ + options: { + title: { text: 'My chart title' }, + }, + }); + await nextTick(); }); - await nextTick(); - }); - it('inits chart options, adding aria.enabled', async () => { - expect(wrapper.vm.chart.setOption).toHaveBeenCalledTimes(1); - expect(wrapper.vm.chart.setOption).toHaveBeenCalledWith({ - title: { text: 'My chart title' }, - aria: { enabled: true }, + it('inits chart options, adding aria.enabled', async () => { + expect(wrapper.vm.chart.setOption).toHaveBeenCalledTimes(1); + expect(wrapper.vm.chart.setOption).toHaveBeenCalledWith({ + title: { text: 'My chart title' }, + aria: { enabled: true }, + }); + + expect(wrapper.emitted('updated').length).toEqual(1); }); - expect(wrapper.emitted('updated').length).toEqual(1); - }); + it('reacts to options changes by merging options', async () => { + wrapper.setProps({ + options: { + title: { text: 'My new chart title' }, + xAxis: { show: true }, + }, + }); + await nextTick(); - it('reacts to options changes by merging options', async () => { - wrapper.setProps({ - options: { + expect(wrapper.vm.chart.setOption).toHaveBeenCalledTimes(2); + expect(wrapper.vm.chart.setOption).toHaveBeenLastCalledWith({ + aria: { enabled: true }, title: { text: 'My new chart title' }, xAxis: { show: true }, - }, + }); + expect(wrapper.emitted('updated').length).toEqual(2); }); - await nextTick(); + }); + + describe('when aria is explicitly disabled', () => { + it('does not enable aria', async () => { + createWrapper({ + options: { aria: { enabled: false } }, + }); + await nextTick(); - expect(wrapper.vm.chart.setOption).toHaveBeenCalledTimes(2); - expect(wrapper.vm.chart.setOption).toHaveBeenLastCalledWith({ - title: { text: 'My new chart title' }, - xAxis: { show: true }, - aria: { enabled: true }, + expect(wrapper.vm.chart.setOption).toHaveBeenCalledWith({ + aria: { enabled: false }, + }); + }); + }); + + describe('when toolbox is enabled', () => { + it('sets grid top to `toolboxHeight`', async () => { + createWrapper({ + options: { toolbox: { show: true } }, + }); + await nextTick(); + + expect(wrapper.vm.chart.setOption).toHaveBeenCalledWith({ + aria: { enabled: true }, + toolbox: { show: true }, + grid: { top: toolboxHeight }, + }); + }); + + it('increases grid top by `toolboxHeight`', async () => { + createWrapper({ + options: { + toolbox: { show: true }, + grid: { top: 100 }, + }, + }); + await nextTick(); + + expect(wrapper.vm.chart.setOption).toHaveBeenCalledWith({ + aria: { enabled: true }, + toolbox: { show: true }, + grid: { top: 100 + toolboxHeight }, + }); }); - expect(wrapper.emitted('updated').length).toEqual(2); }); }); @@ -206,18 +252,4 @@ describe('chart component', () => { }); }); }); - - describe('with toolbox in options', () => { - it('increases grid top by `toolboxHeight`', async () => { - const optionsWithToolbox = { toolbox: { show: true } }; - wrapper = shallowMount(Chart, { propsData: { options: optionsWithToolbox } }); - await nextTick(); - - expect(wrapper.vm.chart.setOption).toHaveBeenCalledWith({ - ...optionsWithToolbox, - grid: { top: toolboxHeight }, - aria: { enabled: true }, - }); - }); - }); }); diff --git a/src/components/charts/chart/chart.vue b/src/components/charts/chart/chart.vue index c2e81dad29dfc6d3317db6f7a0b8e09c038b55f1..361d22ac81708e0a41064ae132e823c73a9ab1da 100644 --- a/src/components/charts/chart/chart.vue +++ b/src/components/charts/chart/chart.vue @@ -1,6 +1,7 @@