mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
lint fixes
This commit is contained in:
@@ -3,9 +3,9 @@ import { mount } from '@vue/test-utils'
|
|||||||
import SqlEditor from '@/components/SqlEditor.vue'
|
import SqlEditor from '@/components/SqlEditor.vue'
|
||||||
|
|
||||||
describe('SqlEditor.vue', () => {
|
describe('SqlEditor.vue', () => {
|
||||||
it('Emits input event when a query is changed', async() => {
|
it('Emits input event when a query is changed', async () => {
|
||||||
const wrapper = mount(SqlEditor)
|
const wrapper = mount(SqlEditor)
|
||||||
await wrapper.findComponent({ name: 'codemirror'}).vm.$emit('input', 'SELECT * FROM foo')
|
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
|
||||||
expect(wrapper.emitted('input')[0]).to.eql(['SELECT * FROM foo'])
|
expect(wrapper.emitted('input')[0]).to.eql(['SELECT * FROM foo'])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ describe('Tab.vue', () => {
|
|||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1,
|
id: 1,
|
||||||
initName: 'foo',
|
initName: 'foo',
|
||||||
initQuery: 'SELECT * FROM foo',
|
initQuery: 'SELECT * FROM foo',
|
||||||
initChart: [],
|
initChart: [],
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
isPredefined: false
|
isPredefined: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -43,7 +43,7 @@ describe('Tab.vue', () => {
|
|||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1
|
id: 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -62,7 +62,7 @@ describe('Tab.vue', () => {
|
|||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1
|
id: 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -73,7 +73,7 @@ describe('Tab.vue', () => {
|
|||||||
expect(wrapper.findComponent({ ref: 'chart' }).vm.visible).to.equal(true)
|
expect(wrapper.findComponent({ ref: 'chart' }).vm.visible).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Is not visible when not active", async () => {
|
it('Is not visible when not active', async () => {
|
||||||
// mock store state
|
// mock store state
|
||||||
const state = {
|
const state = {
|
||||||
currentTabId: 0
|
currentTabId: 0
|
||||||
@@ -85,7 +85,7 @@ describe('Tab.vue', () => {
|
|||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1
|
id: 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -93,7 +93,7 @@ describe('Tab.vue', () => {
|
|||||||
expect(wrapper.find('.tab-content-container').isVisible()).to.equal(false)
|
expect(wrapper.find('.tab-content-container').isVisible()).to.equal(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("Calls setCurrentTab when becomes active", async () => {
|
it('Calls setCurrentTab when becomes active', async () => {
|
||||||
// mock store state
|
// mock store state
|
||||||
const state = {
|
const state = {
|
||||||
currentTabId: 0
|
currentTabId: 0
|
||||||
@@ -105,12 +105,12 @@ describe('Tab.vue', () => {
|
|||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1
|
id: 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
state.currentTabId = 1
|
state.currentTabId = 1
|
||||||
expect(mutations.setCurrentTab.calledOnceWith(state, wrapper.vm)).to.equal(true)
|
expect(mutations.setCurrentTab.calledOnceWith(state, wrapper.vm)).to.equal(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -129,12 +129,12 @@ describe('Tab.vue', () => {
|
|||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1,
|
id: 1,
|
||||||
initName: 'foo',
|
initName: 'foo',
|
||||||
initQuery: 'SELECT * FROM foo',
|
initQuery: 'SELECT * FROM foo',
|
||||||
initChart: [],
|
initChart: [],
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
isPredefined: false
|
isPredefined: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -150,19 +150,19 @@ describe('Tab.vue', () => {
|
|||||||
|
|
||||||
const store = new Vuex.Store({ state, mutations })
|
const store = new Vuex.Store({ state, mutations })
|
||||||
const $db = {
|
const $db = {
|
||||||
execute() { return new Promise(() => {}) }
|
execute () { return new Promise(() => {}) }
|
||||||
}
|
}
|
||||||
// mount the component
|
// mount the component
|
||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
mocks: { $db },
|
mocks: { $db },
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1,
|
id: 1,
|
||||||
initName: 'foo',
|
initName: 'foo',
|
||||||
initQuery: 'SELECT * FROM foo',
|
initQuery: 'SELECT * FROM foo',
|
||||||
initChart: [],
|
initChart: [],
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
isPredefined: false
|
isPredefined: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -183,19 +183,19 @@ describe('Tab.vue', () => {
|
|||||||
|
|
||||||
const store = new Vuex.Store({ state, mutations })
|
const store = new Vuex.Store({ state, mutations })
|
||||||
const $db = {
|
const $db = {
|
||||||
execute() { return Promise.reject('There is no table foo') }
|
execute () { return Promise.reject('There is no table foo') }
|
||||||
}
|
}
|
||||||
// mount the component
|
// mount the component
|
||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
mocks: { $db },
|
mocks: { $db },
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1,
|
id: 1,
|
||||||
initName: 'foo',
|
initName: 'foo',
|
||||||
initQuery: 'SELECT * FROM foo',
|
initQuery: 'SELECT * FROM foo',
|
||||||
initChart: [],
|
initChart: [],
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
isPredefined: false
|
isPredefined: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -216,19 +216,19 @@ describe('Tab.vue', () => {
|
|||||||
const store = new Vuex.Store({ state, mutations })
|
const store = new Vuex.Store({ state, mutations })
|
||||||
const result = ['this is table result']
|
const result = ['this is table result']
|
||||||
const $db = {
|
const $db = {
|
||||||
execute() { return Promise.resolve(result) }
|
execute () { return Promise.resolve(result) }
|
||||||
}
|
}
|
||||||
// mount the component
|
// mount the component
|
||||||
const wrapper = mount(Tab, {
|
const wrapper = mount(Tab, {
|
||||||
store,
|
store,
|
||||||
stubs: ['chart'],
|
stubs: ['chart'],
|
||||||
mocks: { $db },
|
mocks: { $db },
|
||||||
propsData: {
|
propsData: {
|
||||||
id: 1,
|
id: 1,
|
||||||
initName: 'foo',
|
initName: 'foo',
|
||||||
initQuery: 'SELECT * FROM foo',
|
initQuery: 'SELECT * FROM foo',
|
||||||
initChart: [],
|
initChart: [],
|
||||||
tabIndex: 0,
|
tabIndex: 0,
|
||||||
isPredefined: false
|
isPredefined: false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ describe('Tabs.vue', () => {
|
|||||||
await firstTabCloseIcon.trigger('click')
|
await firstTabCloseIcon.trigger('click')
|
||||||
|
|
||||||
// check that the only one tab left and it's opened
|
// check that the only one tab left and it's opened
|
||||||
expect(wrapper.findAllComponents({name: 'Tab'})).to.have.lengthOf(1)
|
expect(wrapper.findAllComponents({ name: 'Tab' })).to.have.lengthOf(1)
|
||||||
|
|
||||||
const firstTab = wrapper.findAll('.tab').at(0)
|
const firstTab = wrapper.findAll('.tab').at(0)
|
||||||
expect(firstTab.text()).to.include('Untitled')
|
expect(firstTab.text()).to.include('Untitled')
|
||||||
|
|||||||
@@ -8,26 +8,26 @@ describe('hint.js', () => {
|
|||||||
it('Calculates table list for hint', () => {
|
it('Calculates table list for hint', () => {
|
||||||
// mock store state
|
// mock store state
|
||||||
const schema = [
|
const schema = [
|
||||||
{
|
{
|
||||||
name: 'foo',
|
name: 'foo',
|
||||||
columns: [
|
columns: [
|
||||||
{ name: 'fooId', type: 'INTEGER' },
|
{ name: 'fooId', type: 'INTEGER' },
|
||||||
{ name: 'name', type: 'NVARCHAR(20)' }
|
{ name: 'name', type: 'NVARCHAR(20)' }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'bar',
|
name: 'bar',
|
||||||
columns: [
|
columns: [
|
||||||
{ name: 'barId', type: 'INTEGER' }
|
{ name: 'barId', type: 'INTEGER' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
sinon.stub(state, 'schema').value(schema)
|
sinon.stub(state, 'schema').value(schema)
|
||||||
|
|
||||||
// mock showHint and editor
|
// mock showHint and editor
|
||||||
sinon.stub(CM, 'showHint')
|
sinon.stub(CM, 'showHint')
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt() {
|
getTokenAt () {
|
||||||
return {
|
return {
|
||||||
string: 'SELECT',
|
string: 'SELECT',
|
||||||
type: 'keyword'
|
type: 'keyword'
|
||||||
@@ -36,7 +36,7 @@ describe('hint.js', () => {
|
|||||||
getCursor: sinon.stub()
|
getCursor: sinon.stub()
|
||||||
}
|
}
|
||||||
|
|
||||||
const clock = sinon.useFakeTimers();
|
const clock = sinon.useFakeTimers()
|
||||||
hint.show(editor)
|
hint.show(editor)
|
||||||
clock.tick(500)
|
clock.tick(500)
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ describe('hint.js', () => {
|
|||||||
foo: ['fooId', 'name'],
|
foo: ['fooId', 'name'],
|
||||||
bar: ['barId']
|
bar: ['barId']
|
||||||
})
|
})
|
||||||
|
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ describe('hint.js', () => {
|
|||||||
// mock showHint and editor
|
// mock showHint and editor
|
||||||
sinon.stub(CM, 'showHint')
|
sinon.stub(CM, 'showHint')
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt() {
|
getTokenAt () {
|
||||||
return {
|
return {
|
||||||
string: 'foo',
|
string: 'foo',
|
||||||
type: 'string'
|
type: 'string'
|
||||||
@@ -65,9 +65,9 @@ describe('hint.js', () => {
|
|||||||
const clock = sinon.useFakeTimers()
|
const clock = sinon.useFakeTimers()
|
||||||
hint.show(editor)
|
hint.show(editor)
|
||||||
clock.tick(500)
|
clock.tick(500)
|
||||||
|
|
||||||
expect(CM.showHint.called).to.equal(false)
|
expect(CM.showHint.called).to.equal(false)
|
||||||
|
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ describe('hint.js', () => {
|
|||||||
// mock showHint and editor
|
// mock showHint and editor
|
||||||
sinon.stub(CM, 'showHint')
|
sinon.stub(CM, 'showHint')
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt() {
|
getTokenAt () {
|
||||||
return {
|
return {
|
||||||
string: ' ',
|
string: ' ',
|
||||||
type: null
|
type: null
|
||||||
@@ -87,9 +87,9 @@ describe('hint.js', () => {
|
|||||||
const clock = sinon.useFakeTimers()
|
const clock = sinon.useFakeTimers()
|
||||||
hint.show(editor)
|
hint.show(editor)
|
||||||
clock.tick(500)
|
clock.tick(500)
|
||||||
|
|
||||||
expect(CM.showHint.called).to.equal(false)
|
expect(CM.showHint.called).to.equal(false)
|
||||||
|
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ describe('hint.js', () => {
|
|||||||
// mock showHint and editor
|
// mock showHint and editor
|
||||||
sinon.stub(CM, 'showHint')
|
sinon.stub(CM, 'showHint')
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt() {
|
getTokenAt () {
|
||||||
return {
|
return {
|
||||||
string: ';',
|
string: ';',
|
||||||
type: 'punctuation'
|
type: 'punctuation'
|
||||||
@@ -109,17 +109,17 @@ describe('hint.js', () => {
|
|||||||
const clock = sinon.useFakeTimers()
|
const clock = sinon.useFakeTimers()
|
||||||
hint.show(editor)
|
hint.show(editor)
|
||||||
clock.tick(500)
|
clock.tick(500)
|
||||||
|
|
||||||
expect(CM.showHint.called).to.equal(false)
|
expect(CM.showHint.called).to.equal(false)
|
||||||
|
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("getHints returns [ ] if there is only one option and the token is already completed with this option", () => {
|
it('getHints returns [ ] if there is only one option and the token is already completed with this option', () => {
|
||||||
// mock CM.hint.sql and editor
|
// mock CM.hint.sql and editor
|
||||||
sinon.stub(CM.hint, 'sql').returns({ list: [{ text: 'SELECT' }] })
|
sinon.stub(CM.hint, 'sql').returns({ list: [{ text: 'SELECT' }] })
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt() {
|
getTokenAt () {
|
||||||
return {
|
return {
|
||||||
string: 'select',
|
string: 'select',
|
||||||
type: 'keyword'
|
type: 'keyword'
|
||||||
@@ -130,19 +130,19 @@ describe('hint.js', () => {
|
|||||||
|
|
||||||
const hints = getHints(editor, {})
|
const hints = getHints(editor, {})
|
||||||
expect(hints.list).to.eql([])
|
expect(hints.list).to.eql([])
|
||||||
|
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("getHints returns hints as is when there are more than one option", () => {
|
it('getHints returns hints as is when there are more than one option', () => {
|
||||||
// mock CM.hint.sql and editor
|
// mock CM.hint.sql and editor
|
||||||
let list = [
|
const list = [
|
||||||
{ text: 'SELECT' },
|
{ text: 'SELECT' },
|
||||||
{ text: 'ST' }
|
{ text: 'ST' }
|
||||||
]
|
]
|
||||||
sinon.stub(CM.hint, 'sql').returns({ list })
|
sinon.stub(CM.hint, 'sql').returns({ list })
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt() {
|
getTokenAt () {
|
||||||
return {
|
return {
|
||||||
string: 'se',
|
string: 'se',
|
||||||
type: 'keyword'
|
type: 'keyword'
|
||||||
@@ -153,16 +153,16 @@ describe('hint.js', () => {
|
|||||||
|
|
||||||
const hints = getHints(editor, {})
|
const hints = getHints(editor, {})
|
||||||
expect(hints.list).to.eql(list)
|
expect(hints.list).to.eql(list)
|
||||||
|
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("getHints returns hints as is when there only one option but the token is not cpmpleted", () => {
|
it('getHints returns hints as is when there only one option but the token is not cpmpleted', () => {
|
||||||
// mock CM.hint.sql and editor
|
// mock CM.hint.sql and editor
|
||||||
let list = [{ text: 'SELECT' }]
|
const list = [{ text: 'SELECT' }]
|
||||||
sinon.stub(CM.hint, 'sql').returns({ list })
|
sinon.stub(CM.hint, 'sql').returns({ list })
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt() {
|
getTokenAt () {
|
||||||
return {
|
return {
|
||||||
string: 'sele',
|
string: 'sele',
|
||||||
type: 'keyword'
|
type: 'keyword'
|
||||||
@@ -173,7 +173,7 @@ describe('hint.js', () => {
|
|||||||
|
|
||||||
const hints = getHints(editor, {})
|
const hints = getHints(editor, {})
|
||||||
expect(hints.list).to.eql(list)
|
expect(hints.list).to.eql(list)
|
||||||
|
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ describe('hint.js', () => {
|
|||||||
// mock showHint and editor
|
// mock showHint and editor
|
||||||
sinon.stub(CM, 'showHint')
|
sinon.stub(CM, 'showHint')
|
||||||
const editor = {
|
const editor = {
|
||||||
getTokenAt() {
|
getTokenAt () {
|
||||||
return {
|
return {
|
||||||
string: 'SELECT',
|
string: 'SELECT',
|
||||||
type: 'keyword'
|
type: 'keyword'
|
||||||
@@ -193,13 +193,13 @@ describe('hint.js', () => {
|
|||||||
getCursor: sinon.stub()
|
getCursor: sinon.stub()
|
||||||
}
|
}
|
||||||
|
|
||||||
const clock = sinon.useFakeTimers();
|
const clock = sinon.useFakeTimers()
|
||||||
hint.show(editor)
|
hint.show(editor)
|
||||||
clock.tick(500)
|
clock.tick(500)
|
||||||
|
|
||||||
expect(CM.showHint.called).to.equal(true)
|
expect(CM.showHint.called).to.equal(true)
|
||||||
expect(CM.showHint.firstCall.args[2].tables).to.eql({})
|
expect(CM.showHint.firstCall.args[2].tables).to.eql({})
|
||||||
|
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user