1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 10:08:52 +08:00

#63 test for chart updating

This commit is contained in:
lana-k
2025-03-29 13:32:20 +01:00
parent 108ae454c1
commit f49fa0ea96
3 changed files with 56 additions and 14 deletions

View File

@@ -1,5 +1,5 @@
{ {
"include": ["src/**/*"], "include": ["src/**/*", "tests/**/*"],
"exclude": ["node_modules", "dist"], "exclude": ["node_modules", "dist"],
"compilerOptions": { "compilerOptions": {
"baseUrl": "./", "baseUrl": "./",

View File

@@ -99,6 +99,10 @@ export default {
mounted() { mounted() {
this.resizeObserver = new ResizeObserver(this.handleResize) this.resizeObserver = new ResizeObserver(this.handleResize)
this.resizeObserver.observe(this.$refs.chartContainer) this.resizeObserver.observe(this.$refs.chartContainer)
if (this.dataSources) {
dereference.default(this.state.data, this.dataSources)
this.updatePlotly()
}
}, },
activated() { activated() {
this.useResizeHandler = true this.useResizeHandler = true

View File

@@ -1,7 +1,7 @@
import { expect } from 'chai' import { expect } from 'chai'
import sinon from 'sinon' import sinon from 'sinon'
import { mount, shallowMount } from '@vue/test-utils' import { mount } from '@vue/test-utils'
import Chart from '@/views/Main/Workspace/Tabs/Tab/DataView/Chart' import Chart from '@/views/Main/Workspace/Tabs/Tab/DataView/Chart/index.vue'
import chartHelper from '@/lib/chartHelper' import chartHelper from '@/lib/chartHelper'
import * as dereference from 'react-chart-editor/lib/lib/dereference' import * as dereference from 'react-chart-editor/lib/lib/dereference'
import fIo from '@/lib/utils/fileIo' import fIo from '@/lib/utils/fileIo'
@@ -16,7 +16,7 @@ describe('Chart.vue', () => {
it('getOptionsForSave called with proper arguments', () => { it('getOptionsForSave called with proper arguments', () => {
// mount the component // mount the component
const wrapper = shallowMount(Chart, { const wrapper = mount(Chart, {
global: { global: {
mocks: { $store } mocks: { $store }
} }
@@ -41,28 +41,66 @@ describe('Chart.vue', () => {
wrapper.unmount() wrapper.unmount()
}) })
it('calls dereference when dataSources is changed', async () => { it('calls dereference and updates chart when dataSources is changed', async () => {
sinon.stub(dereference, 'default') sinon.spy(dereference, 'default')
const dataSources = { const dataSources = {
id: [1], name: ['Gryffindor'],
name: ['foo'] points: [80]
} }
// mount the component // mount the component
const wrapper = shallowMount(Chart, { const wrapper = mount(Chart, {
props: { dataSources }, appendTo: document.body,
props: {
dataSources,
initOptions: {
data: [
{
type: 'bar',
mode: 'markers',
x: null,
xsrc: 'name',
meta: {
columnNames: {
x: 'name',
y: 'points',
text: 'points'
}
},
orientation: 'v',
y: null,
ysrc: 'points',
text: null,
textsrc: 'points'
}
],
layout: {},
frames: []
}
},
global: { global: {
mocks: { $store } mocks: { $store }
} }
}) })
await nextTick()
await nextTick()
expect(wrapper.find('svg.main-svg .overplot text').text()).to.equal('80')
const newDataSources = { const newDataSources = {
id: [2], name: ['Gryffindor'],
name: ['bar'] points: [100]
} }
await wrapper.setProps({ dataSources: newDataSources }) await wrapper.setProps({ dataSources: newDataSources })
await nextTick()
await nextTick()
await nextTick()
await nextTick()
await nextTick()
await nextTick()
expect(dereference.default.called).to.equal(true) expect(dereference.default.called).to.equal(true)
expect(wrapper.find('svg.main-svg .overplot text').text()).to.equal('100')
wrapper.unmount() wrapper.unmount()
}) })
@@ -74,7 +112,7 @@ describe('Chart.vue', () => {
} }
// mount the component // mount the component
const wrapper = shallowMount(Chart, { const wrapper = mount(Chart, {
props: { dataSources }, props: { dataSources },
global: { global: {
mocks: { $store } mocks: { $store }
@@ -82,7 +120,7 @@ describe('Chart.vue', () => {
}) })
await wrapper.setProps({ dataSources: null }) await wrapper.setProps({ dataSources: null })
expect(dereference.default.called).to.equal(false) expect(dereference.default.calledOnce).to.equal(true)
wrapper.unmount() wrapper.unmount()
}) })