mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
first test for storedQueries module
This commit is contained in:
@@ -73,7 +73,7 @@ export default {
|
||||
|
||||
// Create downloader
|
||||
const downloader = document.createElement('a')
|
||||
downloader.style.display = 'none'
|
||||
downloader.hidden = true
|
||||
document.body.appendChild(downloader)
|
||||
|
||||
// Prepare data
|
||||
@@ -106,7 +106,7 @@ export default {
|
||||
uploader.id = 'file-uploader'
|
||||
uploader.type = 'file'
|
||||
uploader.accept = '.json'
|
||||
uploader.style.display = 'none'
|
||||
uploader.hidden = true
|
||||
|
||||
uploader.addEventListener('change', () => {
|
||||
const file = uploader.files[0]
|
||||
|
||||
44
tests/unit/storedQueries.spec.js
Normal file
44
tests/unit/storedQueries.spec.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { expect } from 'chai'
|
||||
import storedQueries from '@/storedQueries.js'
|
||||
|
||||
describe('storedQueries.js', () => {
|
||||
beforeEach(()=> {
|
||||
localStorage.removeItem('myQueries')
|
||||
})
|
||||
|
||||
it('getStoredQueries(empty storage)', () => {
|
||||
const queries = storedQueries.getStoredQueries()
|
||||
expect(queries).to.eql([])
|
||||
})
|
||||
|
||||
it('getStoredQueries', () => {
|
||||
const data = [
|
||||
{ id: 1 },
|
||||
{ id: 2 },
|
||||
]
|
||||
storedQueries.updateStorage(data)
|
||||
const queries = storedQueries.getStoredQueries()
|
||||
expect(queries).to.eql(data)
|
||||
})
|
||||
|
||||
it('duplicateQuery', () => {
|
||||
const now = new Date()
|
||||
const nowPlusMinute = new Date(now.getTime() + 60*1000)
|
||||
const base = {
|
||||
id: 1,
|
||||
name: 'foo',
|
||||
query: 'SELECT * from foo',
|
||||
chart: [],
|
||||
createdAt: new Date(2021, 0, 1),
|
||||
isPredefined: true
|
||||
}
|
||||
|
||||
const copy = storedQueries.duplicateQuery(base)
|
||||
expect(copy).to.have.property('id').which.not.equal(base.id)
|
||||
expect(copy).to.have.property('name').which.equal(base.name + ' Copy')
|
||||
expect(copy).to.have.property('query').which.equal(base.query)
|
||||
expect(copy).to.have.property('chart').which.eql(base.chart)
|
||||
expect(copy).to.have.property('createdAt').which.within(now, nowPlusMinute)
|
||||
expect(copy).to.not.have.property('isPredefined')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user