1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-07 02:28:54 +08:00

fix tests

This commit is contained in:
lana-k
2025-03-09 21:57:36 +01:00
parent 828cad6439
commit b5504b91ce
48 changed files with 7871 additions and 29372 deletions

View File

@@ -123,7 +123,7 @@ describe('Pivot.vue', () => {
}
})
await wrapper.findComponent({ name: 'pivotUi' }).vm.$emit('input', {
await wrapper.findComponent({ name: 'pivotUi' }).setValue({
rows: ['year'],
cols: ['item'],
colOrder: 'value_a_to_z',
@@ -132,9 +132,10 @@ describe('Pivot.vue', () => {
aggregatorName: 'Count',
renderer: $.pivotUtilities.renderers.Table,
rendererName: 'Table',
rendererOptions: undefined,
vals: []
})
sinon.stub(wrapper.findComponent({ref: "customChart"}).vm, 'getOptionsForSave')
.returns({ here_are: 'custom chart settings' })
let optionsForSave = wrapper.vm.getOptionsForSave()
@@ -147,7 +148,7 @@ describe('Pivot.vue', () => {
expect(optionsForSave.rendererOptions).to.equal(undefined)
expect(optionsForSave.vals).to.eql([])
await wrapper.findComponent({ name: 'pivotUi' }).vm.$emit('input', {
await wrapper.findComponent({ name: 'pivotUi' }).setValue({
rows: ['item'],
cols: ['year'],
colOrder: 'value_a_to_z',
@@ -156,14 +157,6 @@ describe('Pivot.vue', () => {
aggregatorName: 'Count',
renderer: $.pivotUtilities.renderers['Custom chart'],
rendererName: 'Custom chart',
rendererOptions: {
customChartComponent: {
$mount: sinon.stub(),
getOptionsForSave () {
return { here_are: 'custom chart settings' }
}
}
},
vals: []
})
@@ -202,7 +195,10 @@ describe('Pivot.vue', () => {
expect(await wrapper.vm.prepareCopy()).to.be.instanceof(HTMLCanvasElement)
await wrapper.findComponent({ name: 'pivotUi' }).vm.$emit('input', {
sinon.stub(wrapper.findComponent({ref: "customChart"}).vm, 'prepareCopy')
.returns(URL.createObjectURL(new Blob()))
await wrapper.findComponent({ name: 'pivotUi' }).setValue({
rows: ['item'],
cols: ['year'],
colOrder: 'value_a_to_z',
@@ -211,18 +207,12 @@ describe('Pivot.vue', () => {
aggregatorName: 'Count',
renderer: $.pivotUtilities.renderers['Custom chart'],
rendererName: 'Custom chart',
rendererOptions: {
customChartComponent: {
$mount: sinon.stub(),
prepareCopy: sinon.stub().returns(URL.createObjectURL(new Blob()))
}
},
vals: []
})
expect(await wrapper.vm.prepareCopy()).to.be.a('string')
await wrapper.findComponent({ name: 'pivotUi' }).vm.$emit('input', {
await wrapper.findComponent({ name: 'pivotUi' }).setValue({
rows: ['item'],
cols: ['year'],
colOrder: 'value_a_to_z',
@@ -265,7 +255,7 @@ describe('Pivot.vue', () => {
attachTo: container
})
const chartComponent = wrapper.vm.pivotOptions.rendererOptions.customChartComponent
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
sinon.stub(chartComponent, 'saveAsSvg')
await wrapper.vm.saveAsSvg()
@@ -300,7 +290,7 @@ describe('Pivot.vue', () => {
attachTo: container
})
const chartComponent = wrapper.vm.pivotOptions.rendererOptions.customChartComponent
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
sinon.stub(chartComponent, 'saveAsHtml')
await wrapper.vm.saveAsHtml()
@@ -335,7 +325,7 @@ describe('Pivot.vue', () => {
attachTo: container
})
const chartComponent = wrapper.vm.pivotOptions.rendererOptions.customChartComponent
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
sinon.stub(chartComponent, 'saveAsPng')
await wrapper.vm.saveAsPng()

View File

@@ -4,18 +4,23 @@ import PivotSortBtn from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi
describe('PivotSortBtn.vue', () => {
it('switches order', async () => {
const wrapper = shallowMount(PivotSortBtn, { props: { value: 'key_a_to_z' } })
const wrapper = shallowMount(PivotSortBtn, {
props: {
modelValue: 'key_a_to_z',
'onUpdate:modelValue': (e) => wrapper.setProps({ modelValue: e })
}
})
expect(wrapper.vm.value).to.equal('key_a_to_z')
expect(wrapper.props('modelValue')).to.equal('key_a_to_z')
await wrapper.find('.pivot-sort-btn').trigger('click')
expect(wrapper.emitted('input')[0]).to.eql(['value_a_to_z'])
expect(wrapper.props('modelValue')).to.equal('value_a_to_z')
await wrapper.setProps({ value: 'value_a_to_z' })
await wrapper.setValue('value_a_to_z')
await wrapper.find('.pivot-sort-btn').trigger('click')
expect(wrapper.emitted('input')[1]).to.eql(['value_z_to_a'])
expect(wrapper.props('modelValue')).to.equal('value_z_to_a')
await wrapper.setProps({ value: 'value_z_to_a' })
await wrapper.setValue('value_z_to_a')
await wrapper.find('.pivot-sort-btn').trigger('click')
expect(wrapper.emitted('input')[2]).to.eql(['key_a_to_z'])
expect(wrapper.props('modelValue')).to.equal('key_a_to_z')
})
})

View File

@@ -6,7 +6,8 @@ describe('PivotUi.vue', () => {
it('returns value when settings changed', async () => {
const wrapper = mount(PivotUi, {
props: {
keyNames: ['foo', 'bar']
keyNames: ['foo', 'bar'],
'onUpdate:modelValue': (e) => wrapper.setProps({ modelValue: e })
}
})
@@ -15,68 +16,74 @@ describe('PivotUi.vue', () => {
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(1)
expect(wrapper.emitted().input[0][0].rows).to.eql([])
expect(wrapper.emitted().input[0][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[0][0].colOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[0][0].rowOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[0][0].aggregatorName).to.equal('Count')
expect(wrapper.emitted().input[0][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[0][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[0][0].vals).to.eql([])
let value = wrapper.props('modelValue')
expect(value.rows).to.eql([])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('key_a_to_z')
expect(value.rowOrder).to.equal('key_a_to_z')
expect(value.aggregatorName).to.equal('Count')
expect(value.rendererName).to.equal('Table')
expect(value.rendererOptions).to.equal(undefined)
expect(value.vals).to.eql([])
// choose rows
await wrapper.findAll('.sqliteviz-select.rows .multiselect__element > span')[0]
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(2)
expect(wrapper.emitted().input[1][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[1][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[1][0].colOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[1][0].rowOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[1][0].aggregatorName).to.equal('Count')
expect(wrapper.emitted().input[1][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[1][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[1][0].vals).to.eql([])
value = wrapper.props('modelValue')
expect(value.rows).to.eql(['bar'])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('key_a_to_z')
expect(value.rowOrder).to.equal('key_a_to_z')
expect(value.aggregatorName).to.equal('Count')
expect(value.rendererName).to.equal('Table')
expect(value.rendererOptions).to.equal(undefined)
expect(value.vals).to.eql([])
// change column order
await wrapper.find('.pivot-sort-btn.col').trigger('click')
expect(wrapper.emitted().update.length).to.equal(3)
expect(wrapper.emitted().input[2][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[2][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[2][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[2][0].rowOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[2][0].aggregatorName).to.equal('Count')
expect(wrapper.emitted().input[2][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[2][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[2][0].vals).to.eql([])
value = wrapper.props('modelValue')
expect(value.rows).to.eql(['bar'])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('value_a_to_z')
expect(value.rowOrder).to.equal('key_a_to_z')
expect(value.aggregatorName).to.equal('Count')
expect(value.rendererName).to.equal('Table')
expect(value.rendererOptions).to.equal(undefined)
expect(value.vals).to.eql([])
// change row order
await wrapper.find('.pivot-sort-btn.row').trigger('click')
expect(wrapper.emitted().update.length).to.equal(4)
expect(wrapper.emitted().input[3][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[3][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[3][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[3][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[3][0].aggregatorName).to.equal('Count')
expect(wrapper.emitted().input[3][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[3][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[3][0].vals).to.eql([])
value = wrapper.props('modelValue')
expect(value.rows).to.eql(['bar'])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('value_a_to_z')
expect(value.rowOrder).to.equal('value_a_to_z')
expect(value.aggregatorName).to.equal('Count')
expect(value.rendererName).to.equal('Table')
expect(value.rendererOptions).to.equal(undefined)
expect(value.vals).to.eql([])
// change aggregator
await wrapper.findAll('.sqliteviz-select.aggregator .multiselect__element > span')[12]
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(5)
expect(wrapper.emitted().input[4][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[4][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[4][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[4][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[4][0].aggregatorName).to.equal('Sum over Sum')
expect(wrapper.emitted().input[4][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[4][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[4][0].vals).to.eql(['', ''])
value = wrapper.props('modelValue')
expect(value.rows).to.eql(['bar'])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('value_a_to_z')
expect(value.rowOrder).to.equal('value_a_to_z')
expect(value.aggregatorName).to.equal('Sum over Sum')
expect(value.rendererName).to.equal('Table')
expect(value.rendererOptions).to.equal(undefined)
expect(value.vals).to.eql(['', ''])
// set first aggregator argument
await wrapper
@@ -85,14 +92,15 @@ describe('PivotUi.vue', () => {
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(6)
expect(wrapper.emitted().input[5][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[5][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[5][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[5][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[5][0].aggregatorName).to.equal('Sum over Sum')
expect(wrapper.emitted().input[5][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[5][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[5][0].vals).to.eql(['foo', ''])
value = wrapper.props('modelValue')
expect(value.rows).to.eql(['bar'])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('value_a_to_z')
expect(value.rowOrder).to.equal('value_a_to_z')
expect(value.aggregatorName).to.equal('Sum over Sum')
expect(value.rendererName).to.equal('Table')
expect(value.rendererOptions).to.equal(undefined)
expect(value.vals).to.eql(['foo', ''])
// set second aggregator argument
await wrapper
@@ -101,43 +109,42 @@ describe('PivotUi.vue', () => {
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(7)
expect(wrapper.emitted().input[6][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[6][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[6][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[6][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[6][0].aggregatorName).to.equal('Sum over Sum')
expect(wrapper.emitted().input[6][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[6][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[6][0].vals).to.eql(['foo', 'bar'])
value = wrapper.props('modelValue')
expect(value.rows).to.eql(['bar'])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('value_a_to_z')
expect(value.rowOrder).to.equal('value_a_to_z')
expect(value.aggregatorName).to.equal('Sum over Sum')
expect(value.rendererName).to.equal('Table')
expect(value.rendererOptions).to.equal(undefined)
expect(value.vals).to.eql(['foo', 'bar'])
// change renderer
await wrapper.findAll('.sqliteviz-select.renderer .multiselect__element > span')[13]
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(8)
expect(wrapper.emitted().input[7][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[7][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[7][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[7][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[7][0].aggregatorName).to.equal('Sum over Sum')
expect(wrapper.emitted().input[7][0].rendererName).to.equal('Custom chart')
expect(wrapper.emitted().input[7][0].rendererOptions.customChartComponent)
.to.not.equal(undefined)
expect(wrapper.emitted().input[7][0].vals).to.eql(['foo', 'bar'])
value = wrapper.props('modelValue')
expect(value.rows).to.eql(['bar'])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('value_a_to_z')
expect(value.rowOrder).to.equal('value_a_to_z')
expect(value.aggregatorName).to.equal('Sum over Sum')
expect(value.rendererName).to.equal('Custom chart')
expect(value.vals).to.eql(['foo', 'bar'])
// change aggregator again
await wrapper.findAll('.sqliteviz-select.aggregator .multiselect__element > span')[3]
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(9)
expect(wrapper.emitted().input[8][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[8][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[8][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[8][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[8][0].aggregatorName).to.equal('Sum')
expect(wrapper.emitted().input[8][0].rendererName).to.equal('Custom chart')
expect(wrapper.emitted().input[8][0].rendererOptions.customChartComponent)
.to.not.equal(undefined)
expect(wrapper.emitted().input[8][0].vals).to.eql(['foo'])
value = wrapper.props('modelValue')
expect(value.rows).to.eql(['bar'])
expect(value.cols).to.eql(['foo'])
expect(value.colOrder).to.equal('value_a_to_z')
expect(value.rowOrder).to.equal('value_a_to_z')
expect(value.aggregatorName).to.equal('Sum')
expect(value.rendererName).to.equal('Custom chart')
expect(value.vals).to.eql(['foo'])
})
})