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

move tests to tests folder

rename util modules
rename DbUpload to DbUploader
add tests for DbUploader component #27
This commit is contained in:
lana-k
2021-04-21 11:05:56 +02:00
parent edd45b317a
commit 803622f18f
44 changed files with 333 additions and 157 deletions

View File

@@ -0,0 +1,68 @@
import { expect } from 'chai'
import sinon from 'sinon'
import { mount, shallowMount } from '@vue/test-utils'
import Chart from '@/components/Chart.vue'
import chart from '@/chart.js'
import * as dereference from 'react-chart-editor/lib/lib/dereference'
describe('Chart.vue', () => {
afterEach(() => {
sinon.restore()
})
it('getChartStateForSave called with proper arguments', () => {
// mount the component
const wrapper = shallowMount(Chart)
const vm = wrapper.vm
const stub = sinon.stub(chart, 'getChartStateForSave').returns('result')
const chartData = vm.getChartStateForSave()
expect(stub.calledOnceWith(vm.state, vm.dataSources)).to.equal(true)
expect(chartData).to.equal('result')
})
it('is not visible when visible is false', () => {
// mount the component
const wrapper = shallowMount(Chart, {
propsData: { visible: false }
})
expect(wrapper.find('.chart-container').isVisible()).to.equal(false)
})
it('is visible when visible is true', () => {
// mount the component
const wrapper = shallowMount(Chart, {
propsData: { visible: true }
})
expect(wrapper.find('.chart-container').isVisible()).to.equal(true)
})
it('emits update when plotly updates', async () => {
// mount the component
const wrapper = mount(Chart)
wrapper.findComponent({ ref: 'plotlyEditor' }).vm.$emit('onUpdate')
expect(wrapper.emitted('update')).to.have.lengthOf(1)
})
it('calls dereference when sqlResult is changed', async () => {
sinon.stub(dereference, 'default')
const sqlResult = {
columns: ['id', 'name'],
values: [[1, 'foo']]
}
// mount the component
const wrapper = shallowMount(Chart, {
propsData: { sqlResult: sqlResult }
})
const newSqlResult = {
columns: ['id', 'name'],
values: [[2, 'bar']]
}
await wrapper.setProps({ sqlResult: newSqlResult })
expect(dereference.default.called).to.equal(true)
})
})