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

add tests in github actions

This commit is contained in:
lana-k
2021-01-13 21:51:04 +01:00
parent 3168c77c17
commit 6612f4444b
10 changed files with 191 additions and 154 deletions

View File

@@ -36,4 +36,4 @@ describe('CheckBox', () => {
expect(wrapper.emitted().click).to.have.lengthOf(2)
expect(wrapper.emitted().click[1]).to.eql([false])
})
})
})

View File

@@ -2,15 +2,15 @@ import { expect } from 'chai'
import initSqlJs from 'sql.js'
import db from '@/database.js'
const config = {
locateFile: filename => `js/sql-wasm.wasm`
locateFile: filename => 'js/sql-wasm.wasm'
}
describe('database.js', () => {
it('creates schema', () => {
return initSqlJs(config)
.then(SQL => {
const database = new SQL.Database()
database.run(`
.then(SQL => {
const database = new SQL.Database()
database.run(`
CREATE TABLE test (
col1,
col2 integer,
@@ -19,53 +19,53 @@ describe('database.js', () => {
)
`)
const data = database.export()
const buffer = new Blob([data])
return db.loadDb(buffer)
})
.then(({dbName, schema}) => {
expect(schema).to.have.lengthOf(1)
expect(schema[0].name).to.equal('test')
expect(schema[0].columns[0].name).to.equal('col1')
expect(schema[0].columns[0].type).to.equal('N/A')
expect(schema[0].columns[1].name).to.equal('col2')
expect(schema[0].columns[1].type).to.equal('integer')
expect(schema[0].columns[2].name).to.equal('col3')
expect(schema[0].columns[2].type).to.equal('decimal(5, 2)')
expect(schema[0].columns[3].name).to.equal('col4')
expect(schema[0].columns[3].type).to.equal('varchar(30)')
})
const data = database.export()
const buffer = new Blob([data])
return db.loadDb(buffer)
})
.then(({ dbName, schema }) => {
expect(schema).to.have.lengthOf(1)
expect(schema[0].name).to.equal('test')
expect(schema[0].columns[0].name).to.equal('col1')
expect(schema[0].columns[0].type).to.equal('N/A')
expect(schema[0].columns[1].name).to.equal('col2')
expect(schema[0].columns[1].type).to.equal('integer')
expect(schema[0].columns[2].name).to.equal('col3')
expect(schema[0].columns[2].type).to.equal('decimal(5, 2)')
expect(schema[0].columns[3].name).to.equal('col4')
expect(schema[0].columns[3].type).to.equal('varchar(30)')
})
})
it('creates schema with virtual table', () => {
return initSqlJs(config)
.then(SQL => {
const database = new SQL.Database()
database.run(`
.then(SQL => {
const database = new SQL.Database()
database.run(`
CREATE VIRTUAL TABLE test_virtual USING fts4(
col1, col2,
notindexed=col1, notindexed=col2,
tokenize=unicode61 "tokenchars=.+#")
`)
const data = database.export()
const buffer = new Blob([data])
return db.loadDb(buffer)
})
.then(({dbName, schema}) => {
expect(schema[0].name).to.equal('test_virtual')
expect(schema[0].columns[0].name).to.equal('col1')
expect(schema[0].columns[0].type).to.equal('N/A')
expect(schema[0].columns[1].name).to.equal('col2')
expect(schema[0].columns[1].type).to.equal('N/A')
})
const data = database.export()
const buffer = new Blob([data])
return db.loadDb(buffer)
})
.then(({ dbName, schema }) => {
expect(schema[0].name).to.equal('test_virtual')
expect(schema[0].columns[0].name).to.equal('col1')
expect(schema[0].columns[0].type).to.equal('N/A')
expect(schema[0].columns[1].name).to.equal('col2')
expect(schema[0].columns[1].type).to.equal('N/A')
})
})
it('returns a query result', () => {
return initSqlJs(config)
.then(SQL => {
const database = new SQL.Database()
database.run(`
.then(SQL => {
const database = new SQL.Database()
database.run(`
CREATE TABLE test (
id integer,
name varchar(100),
@@ -77,33 +77,33 @@ describe('database.js', () => {
( 2, 'Draco Malfoy', 'Slytherin');
`)
const data = database.export()
const buffer = new Blob([data])
return db.loadDb(buffer)
})
.then(({dbName, schema}) => {
return db.execute('SELECT * from test')
})
.then(result => {
expect(result.columns).to.have.lengthOf(3)
expect(result.columns[0]).to.equal('id')
expect(result.columns[1]).to.equal('name')
expect(result.columns[2]).to.equal('faculty')
expect(result.values).to.have.lengthOf(2)
expect(result.values[0][0]).to.equal(1)
expect(result.values[0][1]).to.equal('Harry Potter')
expect(result.values[0][2]).to.equal('Griffindor')
expect(result.values[1][0]).to.equal(2)
expect(result.values[1][1]).to.equal('Draco Malfoy')
expect(result.values[1][2]).to.equal('Slytherin')
})
const data = database.export()
const buffer = new Blob([data])
return db.loadDb(buffer)
})
.then(({ dbName, schema }) => {
return db.execute('SELECT * from test')
})
.then(result => {
expect(result.columns).to.have.lengthOf(3)
expect(result.columns[0]).to.equal('id')
expect(result.columns[1]).to.equal('name')
expect(result.columns[2]).to.equal('faculty')
expect(result.values).to.have.lengthOf(2)
expect(result.values[0][0]).to.equal(1)
expect(result.values[0][1]).to.equal('Harry Potter')
expect(result.values[0][2]).to.equal('Griffindor')
expect(result.values[1][0]).to.equal(2)
expect(result.values[1][1]).to.equal('Draco Malfoy')
expect(result.values[1][2]).to.equal('Slytherin')
})
})
it('returns an error', () => {
return initSqlJs(config)
.then(SQL => {
const database = new SQL.Database()
database.run(`
.then(SQL => {
const database = new SQL.Database()
database.run(`
CREATE TABLE test (
id integer,
name varchar(100),
@@ -115,16 +115,15 @@ describe('database.js', () => {
( 2, 'Draco Malfoy', 'Slytherin');
`)
const data = database.export()
const buffer = new Blob([data])
return db.loadDb(buffer)
})
.then(() => {
return db.execute('SELECT * from foo')
})
.catch(result => {
console.log(result)
expect(result).to.equal('no such table: foo')
})
const data = database.export()
const buffer = new Blob([data])
return db.loadDb(buffer)
})
.then(() => {
return db.execute('SELECT * from foo')
})
.catch(result => {
expect(result).to.equal('no such table: foo')
})
})
})
})

View File

@@ -1,6 +1,6 @@
import { expect } from 'chai'
import { mutations, actions } from '@/store'
const {
const {
saveSchema,
updateTab,
deleteTab,
@@ -15,11 +15,14 @@ describe('mutations', () => {
it('saveSchema', () => {
// mock state
const state = {}
const schema = [
{ name: 'table1', columns: [
{ name: 'id', type: 'INTEGER' }
]}
{
name: 'table1',
columns: [
{ name: 'id', type: 'INTEGER' }
]
}
]
saveSchema(state, {
dbName: 'test',
@@ -323,7 +326,7 @@ describe('mutations', () => {
it('setCurrentTab', () => {
// mock state
const state = {
currentTab: { id: 1}
currentTab: { id: 1 }
}
setCurrentTab(state, { id: 2 })
@@ -372,7 +375,6 @@ describe('mutations', () => {
})
})
describe('actions', () => {
it('addTab (new)', async () => {
// mock state
@@ -429,12 +431,12 @@ describe('actions', () => {
// mock state
const state = {
tabs: [ tab1, tab2 ],
untitledLastIndex: 0,
tabs: [tab1, tab2],
untitledLastIndex: 0
}
await addTab({ state }, tab1)
expect(state.tabs).to.have.lengthOf(2)
expect(state.untitledLastIndex).to.equal(0)
})
})
})

View File

@@ -2,35 +2,35 @@ import { expect } from 'chai'
import storedQueries from '@/storedQueries.js'
describe('storedQueries.js', () => {
beforeEach(()=> {
beforeEach(() => {
localStorage.removeItem('myQueries')
})
it('getStoredQueries(empty storage)', () => {
const queries = storedQueries.getStoredQueries()
const queries = storedQueries.getStoredQueries()
expect(queries).to.eql([])
})
})
it('getStoredQueries', () => {
const data = [
{ id: 1 },
{ id: 2 },
{ id: 2 }
]
storedQueries.updateStorage(data)
const queries = storedQueries.getStoredQueries()
const queries = storedQueries.getStoredQueries()
expect(queries).to.eql(data)
})
})
it('duplicateQuery', () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60*1000)
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
isPredefined: true
}
const copy = storedQueries.duplicateQuery(base)
@@ -43,14 +43,14 @@ describe('storedQueries.js', () => {
})
it('isTabNeedName returns false when the query has a name and is not predefined', () => {
let tab = {
const tab = {
initName: 'foo'
}
expect(storedQueries.isTabNeedName(tab)).to.be.false
})
it('isTabNeedName returns true when the query has no name and is not predefined', () => {
let tab = {
const tab = {
initName: null,
tempName: 'Untitled'
}
@@ -58,10 +58,10 @@ describe('storedQueries.js', () => {
})
it('isTabNeedName returns true when the qiery is predefined', () => {
let tab = {
const tab = {
initName: 'foo',
isPredefined: true
}
expect(storedQueries.isTabNeedName(tab)).to.be.true
})
})
})