mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-07 18:48:55 +08:00
add CSV support #27
This commit is contained in:
@@ -4,6 +4,7 @@ import Vuex from 'vuex'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import DbUpload from '@/components/DbUpload.vue'
|
||||
import fu from '@/fileUtils'
|
||||
import database from '@/database.js'
|
||||
|
||||
describe('DbUploader.vue', () => {
|
||||
afterEach(() => {
|
||||
@@ -24,7 +25,10 @@ describe('DbUploader.vue', () => {
|
||||
|
||||
// mock db loading
|
||||
const schema = {}
|
||||
const $db = { loadDb: sinon.stub().resolves(schema) }
|
||||
const db = {
|
||||
loadDb: sinon.stub().resolves(schema)
|
||||
}
|
||||
database.getNewDatabase = sinon.stub().returns(db)
|
||||
|
||||
// mock router
|
||||
const $router = { push: sinon.stub() }
|
||||
@@ -33,12 +37,12 @@ describe('DbUploader.vue', () => {
|
||||
// mount the component
|
||||
const wrapper = shallowMount(DbUpload, {
|
||||
store,
|
||||
mocks: { $db, $router, $route }
|
||||
mocks: { $router, $route }
|
||||
})
|
||||
|
||||
await wrapper.find('.drop-area').trigger('click')
|
||||
expect($db.loadDb.calledOnceWith(file)).to.equal(true)
|
||||
await $db.loadDb.returnValues[0]
|
||||
expect(db.loadDb.calledOnceWith(file)).to.equal(true)
|
||||
await db.loadDb.returnValues[0]
|
||||
expect(mutations.saveSchema.calledOnceWith(state, schema)).to.equal(true)
|
||||
expect($router.push.calledOnceWith('/editor')).to.equal(true)
|
||||
})
|
||||
@@ -53,7 +57,10 @@ describe('DbUploader.vue', () => {
|
||||
|
||||
// mock db loading
|
||||
const schema = {}
|
||||
const $db = { loadDb: sinon.stub().resolves(schema) }
|
||||
const db = {
|
||||
loadDb: sinon.stub().resolves(schema)
|
||||
}
|
||||
database.getNewDatabase = sinon.stub().returns(db)
|
||||
|
||||
// mock router
|
||||
const $router = { push: sinon.stub() }
|
||||
@@ -62,7 +69,7 @@ describe('DbUploader.vue', () => {
|
||||
// mount the component
|
||||
const wrapper = shallowMount(DbUpload, {
|
||||
store,
|
||||
mocks: { $db, $router, $route }
|
||||
mocks: { $router, $route }
|
||||
})
|
||||
|
||||
// mock a file dropped by a user
|
||||
@@ -74,8 +81,8 @@ describe('DbUploader.vue', () => {
|
||||
})
|
||||
|
||||
await wrapper.find('.drop-area').trigger('drop', dropData)
|
||||
expect($db.loadDb.calledOnceWith(file)).to.equal(true)
|
||||
await $db.loadDb.returnValues[0]
|
||||
expect(db.loadDb.calledOnceWith(file)).to.equal(true)
|
||||
await db.loadDb.returnValues[0]
|
||||
expect(mutations.saveSchema.calledOnceWith(state, schema)).to.equal(true)
|
||||
expect($router.push.calledOnceWith('/editor')).to.equal(true)
|
||||
})
|
||||
@@ -94,7 +101,10 @@ describe('DbUploader.vue', () => {
|
||||
|
||||
// mock db loading
|
||||
const schema = {}
|
||||
const $db = { loadDb: sinon.stub().resolves(schema) }
|
||||
const db = {
|
||||
loadDb: sinon.stub().resolves(schema)
|
||||
}
|
||||
database.getNewDatabase = sinon.stub().returns(db)
|
||||
|
||||
// mock router
|
||||
const $router = { push: sinon.stub() }
|
||||
@@ -103,11 +113,11 @@ describe('DbUploader.vue', () => {
|
||||
// mount the component
|
||||
const wrapper = shallowMount(DbUpload, {
|
||||
store,
|
||||
mocks: { $db, $router, $route }
|
||||
mocks: { $router, $route }
|
||||
})
|
||||
|
||||
await wrapper.find('.drop-area').trigger('click')
|
||||
await $db.loadDb.returnValues[0]
|
||||
await db.loadDb.returnValues[0]
|
||||
expect($router.push.called).to.equal(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -184,7 +184,6 @@ describe('MainMenu.vue', () => {
|
||||
|
||||
it('Ctrl R calls currentTab.execute if running is enabled and route.path is "/editor"',
|
||||
async () => {
|
||||
console.log('ctrl r')
|
||||
const state = {
|
||||
currentTab: {
|
||||
query: 'SELECT * FROM foo',
|
||||
|
||||
@@ -4,7 +4,6 @@ import { mount, createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import Schema from '@/components/Schema.vue'
|
||||
import TableDescription from '@/components/TableDescription.vue'
|
||||
import fu from '@/fileUtils.js'
|
||||
|
||||
const localVue = createLocalVue()
|
||||
localVue.use(Vuex)
|
||||
@@ -99,75 +98,4 @@ describe('Schema.vue', () => {
|
||||
expect(tables.at(1).vm.name).to.equal('bar')
|
||||
expect(tables.at(2).vm.name).to.equal('foobar')
|
||||
})
|
||||
|
||||
it('Change DB', async () => {
|
||||
// mock store state and mutations
|
||||
const mutations = {
|
||||
saveSchema: sinon.stub()
|
||||
}
|
||||
|
||||
const state = {
|
||||
dbName: 'fooDB',
|
||||
schema: [
|
||||
{
|
||||
name: 'foo',
|
||||
columns: [
|
||||
{ name: 'foo_id', type: 'INTEGER' },
|
||||
{ name: 'foo_title', type: 'NVARCHAR(24)' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'foo_prices',
|
||||
columns: [
|
||||
{ name: 'foo_id', type: 'INTEGER' },
|
||||
{ name: 'foo_price', type: 'INTEGER' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const store = new Vuex.Store({ state, mutations })
|
||||
|
||||
// stub getFileFromUser
|
||||
const file = { file: 'hello' }
|
||||
sinon.stub(fu, 'getFileFromUser').resolves(file)
|
||||
|
||||
// mock $db.loadDb()
|
||||
const newSchema = {
|
||||
dbName: 'barDB',
|
||||
schema: [
|
||||
{
|
||||
name: 'bar',
|
||||
columns: [
|
||||
{ name: 'bar_id', type: 'INTEGER' },
|
||||
{ name: 'bar_title', type: 'NVARCHAR(24)' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'bar_prices',
|
||||
columns: [
|
||||
{ name: 'bar_id', type: 'INTEGER' },
|
||||
{ name: 'bar_price', type: 'INTEGER' }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
const $db = {
|
||||
loadDb: sinon.stub().resolves(newSchema)
|
||||
}
|
||||
|
||||
// mount the component
|
||||
const wrapper = mount(Schema, { store, localVue, mocks: { $db } })
|
||||
|
||||
// trigger the event
|
||||
await wrapper.find('#db-edit').trigger('click')
|
||||
|
||||
expect(fu.getFileFromUser.calledOnceWith('.db,.sqlite,.sqlite3')).to.equal(true)
|
||||
|
||||
await fu.getFileFromUser.returnValues[0]
|
||||
expect($db.loadDb.calledOnceWith(file)).to.equal(true)
|
||||
|
||||
await $db.loadDb.returnValues[0]
|
||||
expect(mutations.saveSchema.calledOnceWith(state, newSchema)).to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -145,18 +145,17 @@ describe('Tab.vue', () => {
|
||||
it('Shows .result-in-progress message when executing query', (done) => {
|
||||
// mock store state
|
||||
const state = {
|
||||
currentTabId: 1
|
||||
currentTabId: 1,
|
||||
db: {
|
||||
execute () { return new Promise(() => {}) }
|
||||
}
|
||||
}
|
||||
|
||||
const store = new Vuex.Store({ state, mutations })
|
||||
const $db = {
|
||||
execute () { return new Promise(() => {}) }
|
||||
}
|
||||
// mount the component
|
||||
const wrapper = mount(Tab, {
|
||||
store,
|
||||
stubs: ['chart'],
|
||||
mocks: { $db },
|
||||
propsData: {
|
||||
id: 1,
|
||||
initName: 'foo',
|
||||
@@ -178,18 +177,17 @@ describe('Tab.vue', () => {
|
||||
it('Shows error when executing query ends with error', async () => {
|
||||
// mock store state
|
||||
const state = {
|
||||
currentTabId: 1
|
||||
currentTabId: 1,
|
||||
db: {
|
||||
execute () { return Promise.reject(new Error('There is no table foo')) }
|
||||
}
|
||||
}
|
||||
|
||||
const store = new Vuex.Store({ state, mutations })
|
||||
const $db = {
|
||||
execute () { return Promise.reject(new Error('There is no table foo')) }
|
||||
}
|
||||
// mount the component
|
||||
const wrapper = mount(Tab, {
|
||||
store,
|
||||
stubs: ['chart'],
|
||||
mocks: { $db },
|
||||
propsData: {
|
||||
id: 1,
|
||||
initName: 'foo',
|
||||
@@ -210,7 +208,10 @@ describe('Tab.vue', () => {
|
||||
it('Passes result to sql-table component', async () => {
|
||||
// mock store state
|
||||
const state = {
|
||||
currentTabId: 1
|
||||
currentTabId: 1,
|
||||
db: {
|
||||
execute () { return Promise.resolve(result) }
|
||||
}
|
||||
}
|
||||
|
||||
const store = new Vuex.Store({ state, mutations })
|
||||
@@ -221,14 +222,11 @@ describe('Tab.vue', () => {
|
||||
[2, 'bar']
|
||||
]
|
||||
}
|
||||
const $db = {
|
||||
execute () { return Promise.resolve(result) }
|
||||
}
|
||||
|
||||
// mount the component
|
||||
const wrapper = mount(Tab, {
|
||||
store,
|
||||
stubs: ['chart'],
|
||||
mocks: { $db },
|
||||
propsData: {
|
||||
id: 1,
|
||||
initName: 'foo',
|
||||
|
||||
Reference in New Issue
Block a user