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

Pivot implementation and redesign (#69)

- Pivot support implementation 
- Rename queries into inquiries
- Rename editor into workspace
- Change result set format
- New JSON format for inquiries
- Redesign panels
This commit is contained in:
lana-k
2021-08-04 22:20:51 +02:00
committed by GitHub
parent 8d0bc6affe
commit 5017b55944
105 changed files with 4659 additions and 2021 deletions

View File

@@ -0,0 +1,44 @@
import { expect } from 'chai'
import { mount } from '@vue/test-utils'
import Vuex from 'vuex'
import SqlEditor from '@/views/Main/Workspace/Tabs/Tab/SqlEditor'
describe('SqlEditor.vue', () => {
it('Emits input event when a query is changed', async () => {
// mock store state
const state = {
db: {}
}
const store = new Vuex.Store({ state })
const wrapper = mount(SqlEditor, { store })
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
expect(wrapper.emitted('input')[0]).to.eql(['SELECT * FROM foo'])
})
it('Run is disabled if there is no db or no query or is getting result set', async () => {
const state = {
db: null
}
const store = new Vuex.Store({ state })
const wrapper = mount(SqlEditor, { store, propsData: { isGettingResults: false } })
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
const runButton = wrapper.findComponent({ name: 'RunIcon' }).vm.$parent
expect(runButton.disabled).to.equal(true)
await wrapper.vm.$set(store.state, 'db', {})
expect(runButton.disabled).to.equal(false)
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', '')
expect(runButton.disabled).to.equal(true)
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
expect(runButton.disabled).to.equal(false)
await wrapper.setProps({ isGettingResults: true })
expect(runButton.disabled).to.equal(true)
})
})

View File

@@ -0,0 +1,215 @@
import { expect } from 'chai'
import sinon from 'sinon'
import state from '@/store/state'
import showHint, { getHints } from '@/views/Main/Workspace/Tabs/Tab/SqlEditor/hint'
import CM from 'codemirror'
describe('hint.js', () => {
afterEach(() => {
sinon.restore()
})
it('Calculates table list for hint', () => {
// mock store state
const db = {
schema: [
{
name: 'foo',
columns: [
{ name: 'fooId', type: 'INTEGER' },
{ name: 'name', type: 'NVARCHAR(20)' }
]
},
{
name: 'bar',
columns: [
{ name: 'barId', type: 'INTEGER' }
]
}
]
}
sinon.stub(state, 'db').value(db)
// mock showHint and editor
sinon.stub(CM, 'showHint')
const editor = {
getTokenAt () {
return {
string: 'SELECT',
type: 'keyword'
}
},
getCursor: sinon.stub()
}
showHint(editor)
expect(CM.showHint.called).to.equal(true)
expect(CM.showHint.firstCall.args[2].tables).to.eql({
foo: ['fooId', 'name'],
bar: ['barId']
})
expect(CM.showHint.firstCall.args[2].defaultTable).to.equal(null)
})
it('Add default table if there is only one table in schema', () => {
// mock store state
const db = {
schema: [
{
name: 'foo',
columns: [
{ name: 'fooId', type: 'INTEGER' },
{ name: 'name', type: 'NVARCHAR(20)' }
]
}
]
}
sinon.stub(state, 'db').value(db)
// mock showHint and editor
sinon.stub(CM, 'showHint')
const editor = {
getTokenAt () {
return {
string: 'SELECT',
type: 'keyword'
}
},
getCursor: sinon.stub()
}
showHint(editor)
expect(CM.showHint.firstCall.args[2].defaultTable).to.equal('foo')
})
it("Doesn't show hint when in string or space, or ';'", () => {
// mock showHint and editor
sinon.stub(CM, 'showHint')
const editor = {
getTokenAt () {
return {
string: 'foo',
type: 'string'
}
},
getCursor: sinon.stub()
}
showHint(editor)
expect(CM.showHint.called).to.equal(false)
})
it("Doesn't show hint after space", () => {
// mock showHint and editor
sinon.stub(CM, 'showHint')
const editor = {
getTokenAt () {
return {
string: ' ',
type: null
}
},
getCursor: sinon.stub()
}
showHint(editor)
expect(CM.showHint.called).to.equal(false)
})
it("Doesn't show hint after ';'", () => {
// mock showHint and editor
sinon.stub(CM, 'showHint')
const editor = {
getTokenAt () {
return {
string: ';',
type: 'punctuation'
}
},
getCursor: sinon.stub()
}
showHint(editor)
expect(CM.showHint.called).to.equal(false)
})
it('getHints returns [ ] if there is only one option and the token is already completed with this option', () => {
// mock CM.hint.sql and editor
sinon.stub(CM.hint, 'sql').returns({ list: [{ text: 'SELECT' }] })
const editor = {
getTokenAt () {
return {
string: 'select',
type: 'keyword'
}
},
getCursor: sinon.stub()
}
const hints = getHints(editor, {})
expect(hints.list).to.eql([])
})
it('getHints returns hints as is when there are more than one option', () => {
// mock CM.hint.sql and editor
const list = [
{ text: 'SELECT' },
{ text: 'ST' }
]
sinon.stub(CM.hint, 'sql').returns({ list })
const editor = {
getTokenAt () {
return {
string: 'se',
type: 'keyword'
}
},
getCursor: sinon.stub()
}
const hints = getHints(editor, {})
expect(hints.list).to.eql(list)
sinon.restore()
})
it('getHints returns hints as is when there only one option but the token is not cpmpleted', () => {
// mock CM.hint.sql and editor
const list = [{ text: 'SELECT' }]
sinon.stub(CM.hint, 'sql').returns({ list })
const editor = {
getTokenAt () {
return {
string: 'sele',
type: 'keyword'
}
},
getCursor: sinon.stub()
}
const hints = getHints(editor, {})
expect(hints.list).to.eql(list)
})
it('tables is empty object when schema is null', () => {
// mock store state
sinon.stub(state, 'db').value({ schema: null })
// mock showHint and editor
sinon.stub(CM, 'showHint')
const editor = {
getTokenAt () {
return {
string: 'SELECT',
type: 'keyword'
}
},
getCursor: sinon.stub()
}
showHint(editor)
expect(CM.showHint.called).to.equal(true)
expect(CM.showHint.firstCall.args[2].tables).to.eql({})
})
})