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-03-09 21:57:36 +01:00
parent 828cad6439
commit b5504b91ce
48 changed files with 7871 additions and 29372 deletions

View File

@@ -1,10 +1,12 @@
import { expect } from 'chai'
import sinon from 'sinon'
import Vuex from 'vuex'
import { createStore } from 'vuex'
import { shallowMount, mount } from '@vue/test-utils'
import DbUploader from '@/components/DbUploader'
import fu from '@/lib/utils/fileIo'
import database from '@/lib/database'
import { nextTick } from 'vue'
describe('DbUploader.vue', () => {
let state = {}
@@ -18,7 +20,7 @@ describe('DbUploader.vue', () => {
mutations = {
setDb: sinon.stub()
}
store = new Vuex.Store({ state, mutations })
store = createStore({ state, mutations })
place = document.createElement('div')
document.body.appendChild(place)
@@ -47,9 +49,9 @@ describe('DbUploader.vue', () => {
// mount the component
const wrapper = shallowMount(DbUploader, {
attachTo: place,
store,
global: {
mocks: { $router, $route }
mocks: { $router, $route },
plugins: [store]
},
props: {
type: 'illustrated'
@@ -60,7 +62,7 @@ describe('DbUploader.vue', () => {
expect(db.loadDb.calledOnceWith(file)).to.equal(true)
await db.loadDb.returnValues[0]
await wrapper.vm.animationPromise
await wrapper.vm.$nextTick()
await nextTick()
expect($router.push.calledOnceWith('/workspace')).to.equal(true)
wrapper.unmount()
})
@@ -79,9 +81,9 @@ describe('DbUploader.vue', () => {
// mount the component
const wrapper = shallowMount(DbUploader, {
attachTo: place,
store,
global: {
mocks: { $router, $route }
mocks: { $router, $route },
plugins: [store]
},
props: {
type: 'illustrated'
@@ -100,7 +102,7 @@ describe('DbUploader.vue', () => {
expect(db.loadDb.calledOnceWith(file)).to.equal(true)
await db.loadDb.returnValues[0]
await wrapper.vm.animationPromise
await wrapper.vm.$nextTick()
await nextTick()
expect($router.push.calledOnceWith('/workspace')).to.equal(true)
wrapper.unmount()
})
@@ -123,9 +125,9 @@ describe('DbUploader.vue', () => {
// mount the component
const wrapper = shallowMount(DbUploader, {
attachTo: place,
store,
global: {
mocks: { $router, $route }
mocks: { $router, $route },
plugins: [store]
},
props: {
type: 'illustrated'
@@ -135,7 +137,7 @@ describe('DbUploader.vue', () => {
await wrapper.find('.drop-area').trigger('click')
await db.loadDb.returnValues[0]
await wrapper.vm.animationPromise
await wrapper.vm.$nextTick()
await nextTick()
expect($router.push.called).to.equal(false)
wrapper.unmount()
})
@@ -152,9 +154,9 @@ describe('DbUploader.vue', () => {
// mount the component
const wrapper = mount(DbUploader, {
attachTo: place,
store,
global: {
mocks: { $router, $route }
mocks: { $router, $route },
plugins: [store]
},
props: {
type: 'illustrated'
@@ -167,11 +169,11 @@ describe('DbUploader.vue', () => {
sinon.stub(CsvImport, 'open')
await wrapper.find('.drop-area').trigger('click')
await wrapper.vm.$nextTick()
await nextTick()
expect(CsvImport.reset.calledOnce).to.equal(true)
await wrapper.vm.animationPromise
expect(CsvImport.preview.calledOnce).to.equal(true)
await wrapper.vm.$nextTick()
await nextTick()
expect(CsvImport.open.calledOnce).to.equal(true)
wrapper.unmount()
})
@@ -188,9 +190,9 @@ describe('DbUploader.vue', () => {
// mount the component
const wrapper = mount(DbUploader, {
attachTo: place,
store,
global: {
mocks: { $router, $route }
mocks: { $router, $route },
plugins: [store]
},
props: {
type: 'illustrated'
@@ -203,11 +205,11 @@ describe('DbUploader.vue', () => {
sinon.stub(JsonImport, 'open')
await wrapper.find('.drop-area').trigger('click')
await wrapper.vm.$nextTick()
await nextTick()
expect(JsonImport.reset.calledOnce).to.equal(true)
await wrapper.vm.animationPromise
expect(JsonImport.preview.calledOnce).to.equal(true)
await wrapper.vm.$nextTick()
await nextTick()
expect(JsonImport.open.calledOnce).to.equal(true)
wrapper.unmount()
})
@@ -224,9 +226,9 @@ describe('DbUploader.vue', () => {
// mount the component
const wrapper = mount(DbUploader, {
attachTo: place,
store,
global: {
mocks: { $router, $route }
mocks: { $router, $route },
plugins: [store]
},
props: {
type: 'illustrated'
@@ -239,11 +241,11 @@ describe('DbUploader.vue', () => {
sinon.stub(JsonImport, 'open')
await wrapper.find('.drop-area').trigger('click')
await wrapper.vm.$nextTick()
await nextTick()
expect(JsonImport.reset.calledOnce).to.equal(true)
await wrapper.vm.animationPromise
expect(JsonImport.preview.calledOnce).to.equal(true)
await wrapper.vm.$nextTick()
await nextTick()
expect(JsonImport.open.calledOnce).to.equal(true)
wrapper.unmount()
})
@@ -259,9 +261,9 @@ describe('DbUploader.vue', () => {
// mount the component
const wrapper = mount(DbUploader, {
store,
global: {
mocks: { $router, $route }
mocks: { $router, $route },
plugins: [store]
},
props: {
type: 'illustrated'
@@ -274,7 +276,7 @@ describe('DbUploader.vue', () => {
sinon.stub(CsvImport, 'open')
await wrapper.find('.drop-area').trigger('click')
await wrapper.vm.$nextTick()
await nextTick()
await CsvImport.$emit('cancel')
expect(wrapper.vm.newDb).to.equal(null)
})