mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
change code structure
This commit is contained in:
@@ -2,10 +2,10 @@ import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import Vuex from 'vuex'
|
||||
import { shallowMount, mount } from '@vue/test-utils'
|
||||
import DbUploader from '@/components/DbUploader.vue'
|
||||
import fu from '@/file.utils'
|
||||
import database from '@/database'
|
||||
import csv from '@/csv'
|
||||
import DbUploader from '@/components/DbUploader'
|
||||
import fu from '@/lib/utils/fileIo'
|
||||
import database from '@/lib/database'
|
||||
import csv from '@/components/DbUploader/csv'
|
||||
|
||||
describe('DbUploader.vue', () => {
|
||||
let state = {}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import { mount, shallowMount } from '@vue/test-utils'
|
||||
import DelimiterSelector from '@/components/DelimiterSelector'
|
||||
import DelimiterSelector from '@/components/DbUploader/DelimiterSelector'
|
||||
|
||||
describe('DelimiterSelector', async () => {
|
||||
it('shows the name of value', async () => {
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import csv from '@/csv'
|
||||
import csv from '@/components/DbUploader/csv'
|
||||
import Papa from 'papaparse'
|
||||
|
||||
describe('csv.js', () => {
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import LoadingIndicator from '@/components/LoadingIndicator.vue'
|
||||
import LoadingIndicator from '@/components/LoadingIndicator'
|
||||
|
||||
describe('LoadingIndicator.vue', () => {
|
||||
it('Calculates animation class', async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import Logs from '@/components/Logs.vue'
|
||||
import Logs from '@/components/Logs'
|
||||
|
||||
let place
|
||||
describe('Logs.vue', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import Splitpanes from '@/components/Splitpanes.vue'
|
||||
import Splitpanes from '@/components/Splitpanes'
|
||||
|
||||
describe('Splitpanes.vue', () => {
|
||||
it('renders correctly - vertical', () => {
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import splitter from '@/splitter'
|
||||
import splitter from '@/components/Splitpanes/splitter'
|
||||
|
||||
describe('splitter.js', () => {
|
||||
afterEach(() => {
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import Pager from '@/components/Pager.vue'
|
||||
import Pager from '@/components/SqlTable/Pager'
|
||||
|
||||
describe('Pager.vue', () => {
|
||||
afterEach(() => {
|
||||
@@ -2,14 +2,14 @@ import chai from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import initSqlJs from 'sql.js'
|
||||
import Sql from '@/sql'
|
||||
import Sql from '@/lib/database/_sql'
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
chai.should()
|
||||
|
||||
const getSQL = initSqlJs()
|
||||
|
||||
describe('sql.js', () => {
|
||||
describe('_sql.js', () => {
|
||||
afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect } from 'chai'
|
||||
import dbUtils from '@/db.utils'
|
||||
import dbUtils from '@/lib/database/_statements'
|
||||
|
||||
describe('db.utils.js', () => {
|
||||
describe('_statements.js', () => {
|
||||
it('generateChunks', () => {
|
||||
const arr = ['1', '2', '3', '4', '5']
|
||||
const size = 2
|
||||
@@ -2,8 +2,8 @@ import chai from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import chaiAsPromised from 'chai-as-promised'
|
||||
import initSqlJs from 'sql.js'
|
||||
import database from '@/database'
|
||||
import fu from '@/file.utils'
|
||||
import database from '@/lib/database'
|
||||
import fu from '@/lib/utils/fileIo'
|
||||
|
||||
chai.use(chaiAsPromised)
|
||||
const expect = chai.expect
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import storedQueries from '@/storedQueries.js'
|
||||
import fu from '@/file.utils'
|
||||
import storedQueries from '@/lib/storedQueries'
|
||||
import fu from '@/lib/utils/fileIo'
|
||||
|
||||
describe('storedQueries.js', () => {
|
||||
beforeEach(() => {
|
||||
@@ -1,8 +1,8 @@
|
||||
import { expect } from 'chai'
|
||||
import fu from '@/file.utils'
|
||||
import fu from '@/lib/utils/fileIo'
|
||||
import sinon from 'sinon'
|
||||
|
||||
describe('file.utils.js', () => {
|
||||
describe('fileIo.js', () => {
|
||||
afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
@@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai'
|
||||
import time from '@/time'
|
||||
import time from '@/lib/utils/time'
|
||||
|
||||
describe('time.js', () => {
|
||||
it('getPeriod', () => {
|
||||
67
tests/store/actions.spec.js
Normal file
67
tests/store/actions.spec.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import { expect } from 'chai'
|
||||
import actions from '@/store/actions'
|
||||
|
||||
const { addTab } = actions
|
||||
|
||||
describe('actions', () => {
|
||||
it('addTab adds new blank tab', async () => {
|
||||
const state = {
|
||||
tabs: [],
|
||||
untitledLastIndex: 0
|
||||
}
|
||||
|
||||
const id = await addTab({ state })
|
||||
expect(state.tabs[0].id).to.eql(id)
|
||||
expect(state.tabs[0].name).to.eql(null)
|
||||
expect(state.tabs[0].tempName).to.eql('Untitled')
|
||||
expect(state.tabs[0].isUnsaved).to.eql(true)
|
||||
expect(state.untitledLastIndex).to.equal(1)
|
||||
})
|
||||
|
||||
it('addTab adds tab from saved queries', async () => {
|
||||
const state = {
|
||||
tabs: [],
|
||||
untitledLastIndex: 0
|
||||
}
|
||||
const tab = {
|
||||
id: 1,
|
||||
name: 'test',
|
||||
tempName: null,
|
||||
query: 'SELECT * from foo',
|
||||
chart: {},
|
||||
isUnsaved: false
|
||||
}
|
||||
await addTab({ state }, tab)
|
||||
expect(state.tabs[0]).to.eql(tab)
|
||||
expect(state.untitledLastIndex).to.equal(0)
|
||||
})
|
||||
|
||||
it("addTab doesn't add anything when the query is already opened", async () => {
|
||||
const tab1 = {
|
||||
id: 1,
|
||||
name: 'test',
|
||||
tempName: null,
|
||||
query: 'SELECT * from foo',
|
||||
chart: {},
|
||||
isUnsaved: false
|
||||
}
|
||||
|
||||
const tab2 = {
|
||||
id: 2,
|
||||
name: 'bar',
|
||||
tempName: null,
|
||||
query: 'SELECT * from bar',
|
||||
chart: {},
|
||||
isUnsaved: false
|
||||
}
|
||||
|
||||
const state = {
|
||||
tabs: [tab1, tab2],
|
||||
untitledLastIndex: 0
|
||||
}
|
||||
|
||||
await addTab({ state }, tab1)
|
||||
expect(state.tabs).to.have.lengthOf(2)
|
||||
expect(state.untitledLastIndex).to.equal(0)
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { mutations, actions } from '@/store'
|
||||
import mutations from '@/store/mutations'
|
||||
const {
|
||||
saveSchema,
|
||||
updateTab,
|
||||
@@ -11,8 +11,6 @@ const {
|
||||
setDb
|
||||
} = mutations
|
||||
|
||||
const { addTab } = actions
|
||||
|
||||
describe('mutations', () => {
|
||||
it('setDb', () => {
|
||||
const state = {
|
||||
@@ -376,66 +374,3 @@ describe('mutations', () => {
|
||||
expect(state.predefinedQueries).to.eql(queries)
|
||||
})
|
||||
})
|
||||
|
||||
describe('actions', () => {
|
||||
it('addTab adds new blank tab', async () => {
|
||||
const state = {
|
||||
tabs: [],
|
||||
untitledLastIndex: 0
|
||||
}
|
||||
|
||||
const id = await addTab({ state })
|
||||
expect(state.tabs[0].id).to.eql(id)
|
||||
expect(state.tabs[0].name).to.eql(null)
|
||||
expect(state.tabs[0].tempName).to.eql('Untitled')
|
||||
expect(state.tabs[0].isUnsaved).to.eql(true)
|
||||
expect(state.untitledLastIndex).to.equal(1)
|
||||
})
|
||||
|
||||
it('addTab adds tab from saved queries', async () => {
|
||||
const state = {
|
||||
tabs: [],
|
||||
untitledLastIndex: 0
|
||||
}
|
||||
const tab = {
|
||||
id: 1,
|
||||
name: 'test',
|
||||
tempName: null,
|
||||
query: 'SELECT * from foo',
|
||||
chart: {},
|
||||
isUnsaved: false
|
||||
}
|
||||
await addTab({ state }, tab)
|
||||
expect(state.tabs[0]).to.eql(tab)
|
||||
expect(state.untitledLastIndex).to.equal(0)
|
||||
})
|
||||
|
||||
it("addTab doesn't add anything when the query is already opened", async () => {
|
||||
const tab1 = {
|
||||
id: 1,
|
||||
name: 'test',
|
||||
tempName: null,
|
||||
query: 'SELECT * from foo',
|
||||
chart: {},
|
||||
isUnsaved: false
|
||||
}
|
||||
|
||||
const tab2 = {
|
||||
id: 2,
|
||||
name: 'bar',
|
||||
tempName: null,
|
||||
query: 'SELECT * from bar',
|
||||
chart: {},
|
||||
isUnsaved: false
|
||||
}
|
||||
|
||||
const state = {
|
||||
tabs: [tab1, tab2],
|
||||
untitledLastIndex: 0
|
||||
}
|
||||
|
||||
await addTab({ state }, tab1)
|
||||
expect(state.tabs).to.have.lengthOf(2)
|
||||
expect(state.untitledLastIndex).to.equal(0)
|
||||
})
|
||||
})
|
||||
@@ -1,8 +1,8 @@
|
||||
import { expect } from 'chai'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import tooltipMixin from '@/mixins/tooltips.js'
|
||||
import tooltipMixin from '@/tooltipMixin'
|
||||
|
||||
describe('tooltips.js', () => {
|
||||
describe('tooltipMixin.js', () => {
|
||||
it('tooltip is hidden in initial', () => {
|
||||
const component = {
|
||||
template: '<div :style="tooltipStyle"></div>',
|
||||
@@ -2,8 +2,8 @@ import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { mount, createLocalVue } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import Schema from '@/components/Schema.vue'
|
||||
import TableDescription from '@/components/TableDescription.vue'
|
||||
import Schema from '@/views/Main/Editor/Schema'
|
||||
import TableDescription from '@/views/Main/Editor/Schema/TableDescription'
|
||||
|
||||
const localVue = createLocalVue()
|
||||
localVue.use(Vuex)
|
||||
@@ -1,6 +1,6 @@
|
||||
import { expect } from 'chai'
|
||||
import { shallowMount } from '@vue/test-utils'
|
||||
import TableDescription from '@/components/TableDescription.vue'
|
||||
import TableDescription from '@/views/Main/Editor/Schema/TableDescription'
|
||||
|
||||
describe('TableDescription.vue', () => {
|
||||
it('Initially the columns are hidden and table name is rendered', () => {
|
||||
@@ -1,8 +1,8 @@
|
||||
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 Chart from '@/views/Main/Editor/Tabs/Tab/Chart'
|
||||
import chartHelper from '@/views/Main/Editor/Tabs/Tab/Chart/chartHelper'
|
||||
import * as dereference from 'react-chart-editor/lib/lib/dereference'
|
||||
|
||||
describe('Chart.vue', () => {
|
||||
@@ -14,7 +14,7 @@ describe('Chart.vue', () => {
|
||||
// mount the component
|
||||
const wrapper = shallowMount(Chart)
|
||||
const vm = wrapper.vm
|
||||
const stub = sinon.stub(chart, 'getChartStateForSave').returns('result')
|
||||
const stub = sinon.stub(chartHelper, 'getChartStateForSave').returns('result')
|
||||
const chartData = vm.getChartStateForSave()
|
||||
expect(stub.calledOnceWith(vm.state, vm.dataSources)).to.equal(true)
|
||||
expect(chartData).to.equal('result')
|
||||
@@ -1,9 +1,9 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import * as chart from '@/chart'
|
||||
import * as chartHelper from '@/views/Main/Editor/Tabs/Tab/Chart/chartHelper'
|
||||
import * as dereference from 'react-chart-editor/lib/lib/dereference'
|
||||
|
||||
describe('chart.js', () => {
|
||||
describe('chartHelper.js', () => {
|
||||
afterEach(() => {
|
||||
sinon.restore()
|
||||
})
|
||||
@@ -17,7 +17,7 @@ describe('chart.js', () => {
|
||||
]
|
||||
}
|
||||
|
||||
const ds = chart.getDataSourcesFromSqlResult(sqlResult)
|
||||
const ds = chartHelper.getDataSourcesFromSqlResult(sqlResult)
|
||||
expect(ds).to.eql({
|
||||
id: [1, 2],
|
||||
name: ['foo', 'bar']
|
||||
@@ -30,7 +30,7 @@ describe('chart.js', () => {
|
||||
name: ['foo', 'bar']
|
||||
}
|
||||
|
||||
const ds = chart.getOptionsFromDataSources(dataSources)
|
||||
const ds = chartHelper.getOptionsFromDataSources(dataSources)
|
||||
expect(ds).to.eql([
|
||||
{ value: 'id', label: 'id' },
|
||||
{ value: 'name', label: 'name' }
|
||||
@@ -53,7 +53,7 @@ describe('chart.js', () => {
|
||||
sinon.stub(dereference, 'default')
|
||||
sinon.spy(JSON, 'parse')
|
||||
|
||||
const ds = chart.getChartStateForSave(state, dataSources)
|
||||
const ds = chartHelper.getChartStateForSave(state, dataSources)
|
||||
|
||||
expect(dereference.default.calledOnce).to.equal(true)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { expect } from 'chai'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import SqlEditor from '@/components/SqlEditor.vue'
|
||||
import SqlEditor from '@/views/Main/Editor/Tabs/Tab/SqlEditor'
|
||||
|
||||
describe('SqlEditor.vue', () => {
|
||||
it('Emits input event when a query is changed', async () => {
|
||||
const wrapper = mount(SqlEditor)
|
||||
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
|
||||
expect(wrapper.emitted('input')[0]).to.eql(['SELECT * FROM foo'])
|
||||
// Take a pause to keep proper state in debounced '@/views/Main/Editor/Tabs/Tab/SqlEditor/hint'
|
||||
})
|
||||
})
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { state } from '@/store'
|
||||
import hint, { getHints } from '@/hint'
|
||||
import state from '@/store/state'
|
||||
import showHint, { getHints } from '@/views/Main/Editor/Tabs/Tab/SqlEditor/hint'
|
||||
import CM from 'codemirror'
|
||||
|
||||
describe('hint.js', () => {
|
||||
@@ -40,9 +40,7 @@ describe('hint.js', () => {
|
||||
getCursor: sinon.stub()
|
||||
}
|
||||
|
||||
const clock = sinon.useFakeTimers()
|
||||
hint.show(editor)
|
||||
clock.tick(500)
|
||||
showHint(editor)
|
||||
|
||||
expect(CM.showHint.called).to.equal(true)
|
||||
expect(CM.showHint.firstCall.args[2].tables).to.eql({
|
||||
@@ -77,10 +75,7 @@ describe('hint.js', () => {
|
||||
getCursor: sinon.stub()
|
||||
}
|
||||
|
||||
const clock = sinon.useFakeTimers()
|
||||
hint.show(editor)
|
||||
clock.tick(500)
|
||||
|
||||
showHint(editor)
|
||||
expect(CM.showHint.firstCall.args[2].defaultTable).to.equal('foo')
|
||||
})
|
||||
|
||||
@@ -97,10 +92,7 @@ describe('hint.js', () => {
|
||||
getCursor: sinon.stub()
|
||||
}
|
||||
|
||||
const clock = sinon.useFakeTimers()
|
||||
hint.show(editor)
|
||||
clock.tick(500)
|
||||
|
||||
showHint(editor)
|
||||
expect(CM.showHint.called).to.equal(false)
|
||||
})
|
||||
|
||||
@@ -117,10 +109,7 @@ describe('hint.js', () => {
|
||||
getCursor: sinon.stub()
|
||||
}
|
||||
|
||||
const clock = sinon.useFakeTimers()
|
||||
hint.show(editor)
|
||||
clock.tick(500)
|
||||
|
||||
showHint(editor)
|
||||
expect(CM.showHint.called).to.equal(false)
|
||||
})
|
||||
|
||||
@@ -137,10 +126,7 @@ describe('hint.js', () => {
|
||||
getCursor: sinon.stub()
|
||||
}
|
||||
|
||||
const clock = sinon.useFakeTimers()
|
||||
hint.show(editor)
|
||||
clock.tick(500)
|
||||
|
||||
showHint(editor)
|
||||
expect(CM.showHint.called).to.equal(false)
|
||||
})
|
||||
|
||||
@@ -218,10 +204,7 @@ describe('hint.js', () => {
|
||||
getCursor: sinon.stub()
|
||||
}
|
||||
|
||||
const clock = sinon.useFakeTimers()
|
||||
hint.show(editor)
|
||||
clock.tick(500)
|
||||
|
||||
showHint(editor)
|
||||
expect(CM.showHint.called).to.equal(true)
|
||||
expect(CM.showHint.firstCall.args[2].tables).to.eql({})
|
||||
})
|
||||
@@ -1,9 +1,9 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { mutations } from '@/store'
|
||||
import mutations from '@/store/mutations'
|
||||
import Vuex from 'vuex'
|
||||
import Tab from '@/components/Tab.vue'
|
||||
import Tab from '@/views/Main/Editor/Tabs/Tab'
|
||||
|
||||
describe('Tab.vue', () => {
|
||||
afterEach(() => {
|
||||
@@ -1,9 +1,9 @@
|
||||
import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { shallowMount, mount, createWrapper } from '@vue/test-utils'
|
||||
import { mutations } from '@/store'
|
||||
import mutations from '@/store/mutations'
|
||||
import Vuex from 'vuex'
|
||||
import Tabs from '@/components/Tabs.vue'
|
||||
import Tabs from '@/views/Main/Editor/Tabs'
|
||||
|
||||
describe('Tabs.vue', () => {
|
||||
afterEach(() => {
|
||||
@@ -2,8 +2,8 @@ import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { mount, shallowMount, createWrapper } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import MainMenu from '@/components/MainMenu.vue'
|
||||
import storedQueries from '@/storedQueries.js'
|
||||
import MainMenu from '@/views/Main/MainMenu'
|
||||
import storedQueries from '@/lib/storedQueries'
|
||||
|
||||
let wrapper = null
|
||||
|
||||
@@ -2,10 +2,10 @@ import { expect } from 'chai'
|
||||
import sinon from 'sinon'
|
||||
import { mount, shallowMount } from '@vue/test-utils'
|
||||
import Vuex from 'vuex'
|
||||
import MyQueries from '@/views/MyQueries.vue'
|
||||
import storedQueries from '@/storedQueries'
|
||||
import { mutations } from '@/store'
|
||||
import fu from '@/file.utils'
|
||||
import MyQueries from '@/views/Main/MyQueries'
|
||||
import storedQueries from '@/lib/storedQueries'
|
||||
import mutations from '@/store/mutations'
|
||||
import fu from '@/lib/utils/fileIo'
|
||||
|
||||
describe('MyQueries.vue', () => {
|
||||
afterEach(() => {
|
||||
Reference in New Issue
Block a user