mirror of
https://github.com/lana-k/sqliteviz.git
synced 2026-02-04 15:38:55 +08:00
change repo structure
This commit is contained in:
61
tests/components/SqlEditor/SqlEditor.spec.js
Normal file
61
tests/components/SqlEditor/SqlEditor.spec.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import { expect } from 'chai'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createStore } from 'vuex'
|
||||
import SqlEditor from '@/components/SqlEditor'
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
describe('SqlEditor.vue', () => {
|
||||
it('Emits update:modelValue event when a query is changed', async () => {
|
||||
// mock store state
|
||||
const state = {
|
||||
db: {}
|
||||
}
|
||||
|
||||
const store = createStore({ state })
|
||||
|
||||
const wrapper = mount(SqlEditor, {
|
||||
global: {
|
||||
plugins: [store]
|
||||
}
|
||||
})
|
||||
await wrapper
|
||||
.findComponent({ ref: 'cm' })
|
||||
.setValue('SELECT * FROM foo', 'value')
|
||||
expect(wrapper.emitted()['update:modelValue'][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 = createStore({ state })
|
||||
|
||||
const wrapper = mount(SqlEditor, {
|
||||
global: { plugins: [store] },
|
||||
props: { isGettingResults: false }
|
||||
})
|
||||
await wrapper
|
||||
.findComponent({ ref: 'cm' })
|
||||
.setValue('SELECT * FROM foo', 'value')
|
||||
const runButton = wrapper.findComponent({ ref: 'runBtn' })
|
||||
|
||||
expect(runButton.props('disabled')).to.equal(true)
|
||||
|
||||
store.state.db = {}
|
||||
await nextTick()
|
||||
expect(runButton.props('disabled')).to.equal(false)
|
||||
|
||||
await wrapper.findComponent({ ref: 'cm' }).setValue('', 'value')
|
||||
expect(runButton.props('disabled')).to.equal(true)
|
||||
|
||||
await wrapper
|
||||
.findComponent({ ref: 'cm' })
|
||||
.setValue('SELECT * FROM foo', 'value')
|
||||
expect(runButton.props('disabled')).to.equal(false)
|
||||
|
||||
await wrapper.setProps({ isGettingResults: true })
|
||||
expect(runButton.props('disabled')).to.equal(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user