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

refactoring manipulations with My queries

This commit is contained in:
lana-k
2021-01-05 23:09:47 +01:00
parent 9035cae19f
commit 8d083a93c4
7 changed files with 207 additions and 176 deletions

View File

@@ -1,8 +1,7 @@
import { expect } from 'chai'
import { mutations } from '@/store'
import { mutations, actions } from '@/store'
const {
saveSchema,
addTab,
updateTab,
deleteTab,
setCurrentTabId,
@@ -10,6 +9,8 @@ const {
updatePredefinedQueries
} = mutations
const { addTab } = actions
describe('mutations', () => {
it('saveSchema', () => {
// mock state
@@ -28,75 +29,6 @@ describe('mutations', () => {
expect(state.schema).to.eql(schema)
})
it('addTab (new)', () => {
// mock state
const state = {
tabs: [],
untitledLastIndex: 0
}
const tab = {
id: 1,
name: null,
tempName: 'Untitled',
query: 'SELECT * from foo',
chart: {},
isUnsaved: true
}
addTab(state, tab)
expect(state.tabs[0]).to.eql(tab)
expect(state.untitledLastIndex).to.equal(1)
})
it('addTab (saved)', () => {
// mock state
const state = {
tabs: [],
untitledLastIndex: 0
}
const tab = {
id: 1,
name: 'test',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false
}
addTab(state, tab)
expect(state.tabs[0]).to.eql(tab)
expect(state.untitledLastIndex).to.equal(0)
})
it('addTab (existed)', () => {
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
}
// mock state
const state = {
tabs: [ tab1, tab2 ],
untitledLastIndex: 0,
}
addTab(state, tab1)
expect(state.tabs.length).to.equal(2)
expect(state.untitledLastIndex).to.equal(0)
})
it('updateTab (save)', () => {
const tab = {
id: 1,
@@ -438,4 +370,71 @@ describe('mutations', () => {
updatePredefinedQueries(state, queries)
expect(state.predefinedQueries).to.eql(queries)
})
})
describe('actions', () => {
it('addTab (new)', async () => {
// mock state
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 (saved)', async () => {
// mock state
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 (existed)', 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
}
// mock state
const state = {
tabs: [ tab1, tab2 ],
untitledLastIndex: 0,
}
await addTab({ state }, tab1)
expect(state.tabs.length).to.equal(2)
expect(state.untitledLastIndex).to.equal(0)
})
})