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

fix tests

This commit is contained in:
lana-k
2025-10-03 22:13:33 +02:00
parent d3fbf08569
commit 6fbf75b601
7 changed files with 45 additions and 33 deletions

View File

@@ -1,16 +1,13 @@
<template> <template>
<div id="app"> <div id="app">
<router-view /> <router-view />
<modals-container />
</div> </div>
</template> </template>
<script> <script>
import storedInquiries from '@/lib/storedInquiries' import storedInquiries from '@/lib/storedInquiries'
import { ModalsContainer } from 'vue-final-modal'
export default { export default {
components: { ModalsContainer },
computed: { computed: {
inquiries() { inquiries() {
return this.$store.state.inquiries return this.$store.state.inquiries

View File

@@ -30,14 +30,16 @@ export default {
let inquiryIndex let inquiryIndex
// Set createdAt // Set createdAt
if (newName) { if (newName) {
value.createdAt = new Date() value.createdAt = new Date().toJSON()
} else { } else {
inquiryIndex = myInquiries.findIndex( inquiryIndex = myInquiries.findIndex(
oldInquiry => oldInquiry.id === inquiryTab.id oldInquiry => oldInquiry.id === inquiryTab.id
) )
value.createdAt = value.createdAt =
inquiryIndex !== -1 ? myInquiries[inquiryIndex].createdAt : new Date() inquiryIndex !== -1
? myInquiries[inquiryIndex].createdAt
: new Date().toJSON()
} }
// Insert in inquiries list // Insert in inquiries list

View File

@@ -71,7 +71,7 @@ describe('storedInquiries.js', () => {
query: 'SELECT * from foo', query: 'SELECT * from foo',
viewType: 'chart', viewType: 'chart',
viewOptions: [], viewOptions: [],
createdAt: new Date(2021, 0, 1), createdAt: new Date(2021, 0, 1).toJSON(),
isPredefined: true isPredefined: true
} }
@@ -83,7 +83,8 @@ describe('storedInquiries.js', () => {
expect(copy).to.have.property('query').which.equal(base.query) expect(copy).to.have.property('query').which.equal(base.query)
expect(copy).to.have.property('viewType').which.equal(base.viewType) expect(copy).to.have.property('viewType').which.equal(base.viewType)
expect(copy).to.have.property('viewOptions').which.eql(base.viewOptions) expect(copy).to.have.property('viewOptions').which.eql(base.viewOptions)
expect(copy).to.have.property('createdAt').which.within(now, nowPlusMinute) expect(copy).to.have.property('createdAt')
expect(new Date(copy.createdAt)).within(now, nowPlusMinute)
expect(copy).to.not.have.property('isPredefined') expect(copy).to.not.have.property('isPredefined')
}) })

View File

@@ -166,11 +166,12 @@ describe('actions', () => {
newName: 'foo' newName: 'foo'
} }
) )
expect(value.id).to.equal(tab.id) expect(value.id).not.to.equal(tab.id)
expect(value.name).to.equal('foo') expect(value.name).to.equal('foo')
expect(value.query).to.equal(tab.query) expect(value.query).to.equal(tab.query)
expect(value.viewOptions).to.eql(['chart']) expect(value.viewOptions).to.eql(['chart'])
expect(value).to.have.property('createdAt').which.within(now, nowPlusMinute) expect(value).to.have.property('createdAt')
expect(new Date(value.createdAt)).within(now, nowPlusMinute)
expect(state.inquiries).to.eql([value]) expect(state.inquiries).to.eql([value])
}) })
@@ -202,7 +203,8 @@ describe('actions', () => {
) )
tab.name = 'foo' tab.name = 'foo'
tab.query = 'select * from foo' tab.query = 'select * from bar'
tab.id = first.id
await saveInquiry({ state }, { inquiryTab: tab }) await saveInquiry({ state }, { inquiryTab: tab })
const inquiries = state.inquiries const inquiries = state.inquiries
const second = inquiries[0] const second = inquiries[0]
@@ -211,9 +213,7 @@ describe('actions', () => {
expect(second.name).to.equal(first.name) expect(second.name).to.equal(first.name)
expect(second.query).to.equal(tab.query) expect(second.query).to.equal(tab.query)
expect(second.viewOptions).to.eql(['chart']) expect(second.viewOptions).to.eql(['chart'])
expect(new Date(second.createdAt).getTime()).to.equal( expect(second.createdAt).to.equal(first.createdAt)
first.createdAt.getTime()
)
}) })
it("save adds a new inquiry with new id if it's based on predefined inquiry", async () => { it("save adds a new inquiry with new id if it's based on predefined inquiry", async () => {

View File

@@ -332,7 +332,7 @@ describe('MainMenu.vue', () => {
expect(wrapper.vm.createNewInquiry.callCount).to.equal(4) expect(wrapper.vm.createNewInquiry.callCount).to.equal(4)
}) })
it('Ctrl S calls checkInquiryBeforeSave if the tab is unsaved and route path is /workspace', async () => { it('Ctrl S calls onSave if the tab is unsaved and route path is /workspace', async () => {
const tab = { const tab = {
query: 'SELECT * FROM foo', query: 'SELECT * FROM foo',
execute: sinon.stub(), execute: sinon.stub(),
@@ -353,30 +353,30 @@ describe('MainMenu.vue', () => {
plugins: [store] plugins: [store]
} }
}) })
sinon.stub(wrapper.vm, 'checkInquiryBeforeSave') sinon.stub(wrapper.vm, 'onSave')
const ctrlS = new KeyboardEvent('keydown', { key: 's', ctrlKey: true }) const ctrlS = new KeyboardEvent('keydown', { key: 's', ctrlKey: true })
const metaS = new KeyboardEvent('keydown', { key: 's', metaKey: true }) const metaS = new KeyboardEvent('keydown', { key: 's', metaKey: true })
// tab is unsaved and route is /workspace // tab is unsaved and route is /workspace
document.dispatchEvent(ctrlS) document.dispatchEvent(ctrlS)
expect(wrapper.vm.checkInquiryBeforeSave.calledOnce).to.equal(true) expect(wrapper.vm.onSave.calledOnce).to.equal(true)
document.dispatchEvent(metaS) document.dispatchEvent(metaS)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true) expect(wrapper.vm.onSave.calledTwice).to.equal(true)
// tab is saved and route is /workspace // tab is saved and route is /workspace
store.state.tabs[0].isSaved = true store.state.tabs[0].isSaved = true
document.dispatchEvent(ctrlS) document.dispatchEvent(ctrlS)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true) expect(wrapper.vm.onSave.calledTwice).to.equal(true)
document.dispatchEvent(metaS) document.dispatchEvent(metaS)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true) expect(wrapper.vm.onSave.calledTwice).to.equal(true)
// tab is unsaved and route is not /workspace // tab is unsaved and route is not /workspace
wrapper.vm.$route.path = '/inquiries' wrapper.vm.$route.path = '/inquiries'
store.state.tabs[0].isSaved = false store.state.tabs[0].isSaved = false
document.dispatchEvent(ctrlS) document.dispatchEvent(ctrlS)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true) expect(wrapper.vm.onSave.calledTwice).to.equal(true)
document.dispatchEvent(metaS) document.dispatchEvent(metaS)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true) expect(wrapper.vm.onSave.calledTwice).to.equal(true)
}) })
it('Saves the inquiry when no need the new name', async () => { it('Saves the inquiry when no need the new name', async () => {
@@ -384,11 +384,20 @@ describe('MainMenu.vue', () => {
id: 1, id: 1,
name: 'foo', name: 'foo',
query: 'SELECT * FROM foo', query: 'SELECT * FROM foo',
updatedAt: '2025-05-15T15:30:00Z',
execute: sinon.stub(), execute: sinon.stub(),
isSaved: false isSaved: false
} }
const state = { const state = {
currentTab: tab, currentTab: tab,
inquiries: [
{
id: 1,
name: 'foo',
query: 'SELECT * FROM foo',
updatedAt: '2025-05-15T15:30:00Z'
}
],
tabs: [tab], tabs: [tab],
db: {} db: {}
} }

View File

@@ -3,6 +3,7 @@ import { mount } from '@vue/test-utils'
import DataView from '@/views/MainView/Workspace/Tabs/Tab/DataView' import DataView from '@/views/MainView/Workspace/Tabs/Tab/DataView'
import sinon from 'sinon' import sinon from 'sinon'
import { nextTick } from 'vue' import { nextTick } from 'vue'
import cIo from '@/lib/utils/clipboardIo'
describe('DataView.vue', () => { describe('DataView.vue', () => {
const $store = { state: { isWorkspaceVisible: true } } const $store = { state: { isWorkspaceVisible: true } }
@@ -64,7 +65,7 @@ describe('DataView.vue', () => {
// Find chart and spy the method // Find chart and spy the method
const chart = wrapper.findComponent({ name: 'Chart' }).vm const chart = wrapper.findComponent({ name: 'Chart' }).vm
sinon.spy(chart, 'saveAsSvg') sinon.stub(chart, 'saveAsSvg')
// Export to svg // Export to svg
const svgBtn = wrapper.findComponent({ ref: 'svgExportBtn' }) const svgBtn = wrapper.findComponent({ ref: 'svgExportBtn' })
@@ -77,7 +78,7 @@ describe('DataView.vue', () => {
// Find pivot and spy the method // Find pivot and spy the method
const pivot = wrapper.findComponent({ name: 'pivot' }).vm const pivot = wrapper.findComponent({ name: 'pivot' }).vm
sinon.spy(pivot, 'saveAsSvg') sinon.stub(pivot, 'saveAsSvg')
// Switch to Custom Chart renderer // Switch to Custom Chart renderer
pivot.pivotOptions.rendererName = 'Custom chart' pivot.pivotOptions.rendererName = 'Custom chart'
@@ -146,6 +147,7 @@ describe('DataView.vue', () => {
it('copy to clipboard more than 1 sec', async () => { it('copy to clipboard more than 1 sec', async () => {
sinon.stub(window.navigator.clipboard, 'write').resolves() sinon.stub(window.navigator.clipboard, 'write').resolves()
sinon.stub(cIo, 'copyImage')
const clock = sinon.useFakeTimers() const clock = sinon.useFakeTimers()
const wrapper = mount(DataView, { const wrapper = mount(DataView, {
attachTo: document.body, attachTo: document.body,
@@ -165,7 +167,7 @@ describe('DataView.vue', () => {
await copyBtn.trigger('click') await copyBtn.trigger('click')
// The dialog is shown... // The dialog is shown...
expect(wrapper.find('.dialog.vfm').exists()).to.equal(true) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(true)
expect(wrapper.find('.dialog.vfm .dialog-header').text()).to.contain( expect(wrapper.find('.dialog.vfm .dialog-header').text()).to.contain(
'Copy to clipboard' 'Copy to clipboard'
) )
@@ -184,7 +186,7 @@ describe('DataView.vue', () => {
await nextTick() await nextTick()
// The dialog is shown... // The dialog is shown...
expect(wrapper.find('.dialog.vfm').exists()).to.equal(true) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(true)
// ... with Ready message... // ... with Ready message...
expect(wrapper.find('.dialog-body').text()).to.equal('Image is ready') expect(wrapper.find('.dialog-body').text()).to.equal('Image is ready')
@@ -196,12 +198,13 @@ describe('DataView.vue', () => {
// The dialog is not shown... // The dialog is not shown...
await clock.tick(100) await clock.tick(100)
expect(wrapper.find('.dialog.vfm').exists()).to.equal(false) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(false)
wrapper.unmount() wrapper.unmount()
}) })
it('copy to clipboard less than 1 sec', async () => { it('copy to clipboard less than 1 sec', async () => {
sinon.stub(window.navigator.clipboard, 'write').resolves() sinon.stub(window.navigator.clipboard, 'write').resolves()
sinon.stub(cIo, 'copyImage')
const clock = sinon.useFakeTimers() const clock = sinon.useFakeTimers()
const wrapper = mount(DataView, { const wrapper = mount(DataView, {
attachTo: document.body, attachTo: document.body,
@@ -229,7 +232,7 @@ describe('DataView.vue', () => {
await nextTick() await nextTick()
// The dialog is not shown... // The dialog is not shown...
await clock.tick(100) await clock.tick(100)
expect(wrapper.find('.dialog.vfm').exists()).to.equal(false) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(false)
// copyToClipboard is called // copyToClipboard is called
expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(true) expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(true)
wrapper.unmount() wrapper.unmount()
@@ -270,7 +273,7 @@ describe('DataView.vue', () => {
// The dialog is not shown... // The dialog is not shown...
await clock.tick(100) await clock.tick(100)
expect(wrapper.find('.dialog.vfm').exists()).to.equal(false) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(false)
// copyToClipboard is not called // copyToClipboard is not called
expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(false) expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(false)
wrapper.unmount() wrapper.unmount()

View File

@@ -78,7 +78,7 @@ describe('RunResult.vue', () => {
await nextTick() await nextTick()
// The dialog is shown... // The dialog is shown...
expect(wrapper.find('.dialog.vfm').exists()).to.equal(true) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(true)
expect(wrapper.find('.dialog.vfm .dialog-header').text()).to.contain( expect(wrapper.find('.dialog.vfm .dialog-header').text()).to.contain(
'Copy to clipboard' 'Copy to clipboard'
) )
@@ -91,7 +91,7 @@ describe('RunResult.vue', () => {
await nextTick() await nextTick()
// The dialog is shown... // The dialog is shown...
expect(wrapper.find('.dialog.vfm').exists()).to.equal(true) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(true)
// ... with Ready message... // ... with Ready message...
expect(wrapper.find('.dialog-body').text()).to.equal('CSV is ready') expect(wrapper.find('.dialog-body').text()).to.equal('CSV is ready')
@@ -104,7 +104,7 @@ describe('RunResult.vue', () => {
// The dialog is not shown... // The dialog is not shown...
await clock.tick(100) await clock.tick(100)
expect(wrapper.find('.dialog.vfm').exists()).to.equal(false) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(false)
wrapper.unmount() wrapper.unmount()
}) })
@@ -143,7 +143,7 @@ describe('RunResult.vue', () => {
// The dialog is not shown... // The dialog is not shown...
await clock.tick(100) await clock.tick(100)
expect(wrapper.find('.dialog.vfm').exists()).to.equal(false) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(false)
// copyToClipboard is called // copyToClipboard is called
expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(true) expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(true)
wrapper.unmount() wrapper.unmount()
@@ -188,7 +188,7 @@ describe('RunResult.vue', () => {
.trigger('click') .trigger('click')
// The dialog is not shown... // The dialog is not shown...
await clock.tick(100) await clock.tick(100)
expect(wrapper.find('.dialog.vfm').exists()).to.equal(false) expect(wrapper.find('.dialog.vfm .vfm__content').exists()).to.equal(false)
// copyToClipboard is not called // copyToClipboard is not called
expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(false) expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(false)
wrapper.unmount() wrapper.unmount()