mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
format
This commit is contained in:
@@ -97,7 +97,8 @@ describe('chartHelper.js', () => {
|
||||
expect(doc.children[0].src).to.includes('plotly-latest.js')
|
||||
expect(doc.children[1].id).to.have.lengthOf(21)
|
||||
expect(doc.children[2].innerHTML).to.includes(doc.children[1].id)
|
||||
expect(doc.children[2].innerHTML)
|
||||
.to.includes('Plotly.newPlot(el, "plotly data", "plotly layout"')
|
||||
expect(doc.children[2].innerHTML).to.includes(
|
||||
'Plotly.newPlot(el, "plotly data", "plotly layout"'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -62,7 +62,9 @@ describe('_sql.js', () => {
|
||||
const data = tempDb.export()
|
||||
const sql = await Sql.build()
|
||||
sql.open(data)
|
||||
expect(() => { sql.exec() }).to.throw('exec: Missing query string')
|
||||
expect(() => {
|
||||
sql.exec()
|
||||
}).to.throw('exec: Missing query string')
|
||||
})
|
||||
|
||||
it('imports', async () => {
|
||||
|
||||
@@ -19,8 +19,9 @@ describe('_statements.js', () => {
|
||||
|
||||
it('getInsertStmt', () => {
|
||||
const columns = ['id', 'name']
|
||||
expect(stmts.getInsertStmt('foo', columns))
|
||||
.to.equal('INSERT INTO "foo" ("id", "name") VALUES (?, ?);')
|
||||
expect(stmts.getInsertStmt('foo', columns)).to.equal(
|
||||
'INSERT INTO "foo" ("id", "name") VALUES (?, ?);'
|
||||
)
|
||||
})
|
||||
|
||||
it('getCreateStatement', () => {
|
||||
|
||||
@@ -71,10 +71,12 @@ describe('database.js', () => {
|
||||
type: 'INTEGER'
|
||||
})
|
||||
|
||||
expect(schema[1].columns).to.eql([{
|
||||
name: 'amount',
|
||||
type: 'INTEGER'
|
||||
}])
|
||||
expect(schema[1].columns).to.eql([
|
||||
{
|
||||
name: 'amount',
|
||||
type: 'INTEGER'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('creates empty db with name database', async () => {
|
||||
@@ -114,7 +116,9 @@ describe('database.js', () => {
|
||||
buffer.name = 'foo.sqlite'
|
||||
|
||||
await db.loadDb(buffer)
|
||||
const result = await db.execute('SELECT * from test limit 1; SELECT * from test;')
|
||||
const result = await db.execute(
|
||||
'SELECT * from test limit 1; SELECT * from test;'
|
||||
)
|
||||
expect(result.values).to.eql({
|
||||
id: [1, 2],
|
||||
name: ['Harry Potter', 'Draco Malfoy'],
|
||||
@@ -141,7 +145,9 @@ describe('database.js', () => {
|
||||
const buffer = new Blob([data])
|
||||
buffer.name = 'foo.sqlite'
|
||||
await db.loadDb(buffer)
|
||||
await expect(db.execute('SELECT * from foo')).to.be.rejectedWith(/^no such table: foo$/)
|
||||
await expect(db.execute('SELECT * from foo')).to.be.rejectedWith(
|
||||
/^no such table: foo$/
|
||||
)
|
||||
})
|
||||
|
||||
it('adds table from csv', async () => {
|
||||
@@ -186,37 +192,44 @@ describe('database.js', () => {
|
||||
}
|
||||
const progressHandler = sinon.stub()
|
||||
const progressCounterId = db.createProgressCounter(progressHandler)
|
||||
await expect(db.addTableFromCsv('foo', data, progressCounterId)).to.be.rejected
|
||||
await expect(db.addTableFromCsv('foo', data, progressCounterId)).to.be
|
||||
.rejected
|
||||
})
|
||||
|
||||
it('progressCounters', () => {
|
||||
const firstHandler = sinon.stub()
|
||||
const firstId = db.createProgressCounter(firstHandler)
|
||||
db.worker.dispatchEvent(new MessageEvent('message', {
|
||||
data: {
|
||||
progress: 50,
|
||||
id: firstId
|
||||
}
|
||||
}))
|
||||
db.worker.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
data: {
|
||||
progress: 50,
|
||||
id: firstId
|
||||
}
|
||||
})
|
||||
)
|
||||
expect(firstHandler.calledOnceWith(50)).to.equal(true)
|
||||
|
||||
const secondHandler = sinon.stub()
|
||||
const secondId = db.createProgressCounter(secondHandler)
|
||||
db.worker.dispatchEvent(new MessageEvent('message', {
|
||||
data: {
|
||||
progress: 70,
|
||||
id: secondId
|
||||
}
|
||||
}))
|
||||
db.worker.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
data: {
|
||||
progress: 70,
|
||||
id: secondId
|
||||
}
|
||||
})
|
||||
)
|
||||
expect(firstId).to.not.equals(secondId)
|
||||
expect(secondHandler.calledOnceWith(70)).to.equal(true)
|
||||
|
||||
db.worker.dispatchEvent(new MessageEvent('message', {
|
||||
data: {
|
||||
progress: 80,
|
||||
id: firstId
|
||||
}
|
||||
}))
|
||||
db.worker.dispatchEvent(
|
||||
new MessageEvent('message', {
|
||||
data: {
|
||||
progress: 80,
|
||||
id: firstId
|
||||
}
|
||||
})
|
||||
)
|
||||
expect(firstHandler.calledTwice).to.equal(true)
|
||||
expect(firstHandler.secondCall.calledWith(80)).to.equal(true)
|
||||
|
||||
@@ -268,12 +281,17 @@ describe('database.js', () => {
|
||||
|
||||
it('validateTableName', async () => {
|
||||
await db.execute('CREATE TABLE foo(id)')
|
||||
await expect(db.validateTableName('foo')).to.be.rejectedWith('table "foo" already exists')
|
||||
await expect(db.validateTableName('1foo'))
|
||||
.to.be.rejectedWith("Table name can't start with a digit")
|
||||
await expect(db.validateTableName('foo(05.08.2020)'))
|
||||
.to.be.rejectedWith('Table name can contain only letters, digits and underscores')
|
||||
await expect(db.validateTableName('sqlite_foo'))
|
||||
.to.be.rejectedWith("Table name can't start with sqlite_")
|
||||
await expect(db.validateTableName('foo')).to.be.rejectedWith(
|
||||
'table "foo" already exists'
|
||||
)
|
||||
await expect(db.validateTableName('1foo')).to.be.rejectedWith(
|
||||
"Table name can't start with a digit"
|
||||
)
|
||||
await expect(db.validateTableName('foo(05.08.2020)')).to.be.rejectedWith(
|
||||
'Table name can contain only letters, digits and underscores'
|
||||
)
|
||||
await expect(db.validateTableName('sqlite_foo')).to.be.rejectedWith(
|
||||
"Table name can't start with sqlite_"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -80,7 +80,6 @@ describe('SQLite extensions', function () {
|
||||
'sqrt(square(16))': [16],
|
||||
'ceil(-1.95) + ceil(1.95)': [1],
|
||||
'floor(-1.95) + floor(1.95)': [-1]
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
@@ -452,7 +451,15 @@ describe('SQLite extensions', function () {
|
||||
FROM dataset;
|
||||
`)
|
||||
expect(actual.values).to.eql({
|
||||
xx: [1], xy: [0], xz: [1], yx: [0], yy: [1], yz: [1], zx: [1], zy: [1], zz: [1]
|
||||
xx: [1],
|
||||
xy: [0],
|
||||
xz: [1],
|
||||
yx: [0],
|
||||
yy: [1],
|
||||
yz: [1],
|
||||
zx: [1],
|
||||
zy: [1],
|
||||
zz: [1]
|
||||
})
|
||||
})
|
||||
|
||||
@@ -475,7 +482,10 @@ describe('SQLite extensions', function () {
|
||||
|
||||
SELECT lua_inline(1), lua_full(1) - 1 < 0.000001;
|
||||
`)
|
||||
expect(actual.values).to.eql({ 'lua_inline(1)': [2], 'lua_full(1) - 1 < 0.000001': [1] })
|
||||
expect(actual.values).to.eql({
|
||||
'lua_inline(1)': [2],
|
||||
'lua_full(1) - 1 < 0.000001': [1]
|
||||
})
|
||||
})
|
||||
|
||||
it('supports aggregate Lua functions', async function () {
|
||||
@@ -534,6 +544,9 @@ describe('SQLite extensions', function () {
|
||||
|
||||
SELECT * FROM lua_match('%w+', 'hello world from Lua');
|
||||
`)
|
||||
expect(actual.values).to.eql({ idx: [1, 2, 3, 4], elm: ['hello', 'world', 'from', 'Lua'] })
|
||||
expect(actual.values).to.eql({
|
||||
idx: [1, 2, 3, 4],
|
||||
elm: ['hello', 'world', 'from', 'Lua']
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -19,20 +19,23 @@ describe('storedInquiries.js', () => {
|
||||
})
|
||||
|
||||
it('getStoredInquiries migrate and returns inquiries of v1', () => {
|
||||
localStorage.setItem('myQueries', JSON.stringify([
|
||||
{
|
||||
id: '123',
|
||||
name: 'foo',
|
||||
query: 'SELECT * FROM foo',
|
||||
chart: { here_are: 'foo chart settings' }
|
||||
},
|
||||
{
|
||||
id: '456',
|
||||
name: 'bar',
|
||||
query: 'SELECT * FROM bar',
|
||||
chart: { here_are: 'bar chart settings' }
|
||||
}
|
||||
]))
|
||||
localStorage.setItem(
|
||||
'myQueries',
|
||||
JSON.stringify([
|
||||
{
|
||||
id: '123',
|
||||
name: 'foo',
|
||||
query: 'SELECT * FROM foo',
|
||||
chart: { here_are: 'foo chart settings' }
|
||||
},
|
||||
{
|
||||
id: '456',
|
||||
name: 'bar',
|
||||
query: 'SELECT * FROM bar',
|
||||
chart: { here_are: 'bar chart settings' }
|
||||
}
|
||||
])
|
||||
)
|
||||
const inquiries = storedInquiries.getStoredInquiries()
|
||||
expect(inquiries).to.eql([
|
||||
{
|
||||
@@ -53,10 +56,7 @@ describe('storedInquiries.js', () => {
|
||||
})
|
||||
|
||||
it('updateStorage and getStoredInquiries', () => {
|
||||
const data = [
|
||||
{ id: 1 },
|
||||
{ id: 2 }
|
||||
]
|
||||
const data = [{ id: 1 }, { id: 2 }]
|
||||
storedInquiries.updateStorage(data)
|
||||
const inquiries = storedInquiries.getStoredInquiries()
|
||||
expect(inquiries).to.eql(data)
|
||||
@@ -77,7 +77,9 @@ describe('storedInquiries.js', () => {
|
||||
|
||||
const copy = storedInquiries.duplicateInquiry(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('name')
|
||||
.which.equal(base.name + ' Copy')
|
||||
expect(copy).to.have.property('query').which.equal(base.query)
|
||||
expect(copy).to.have.property('viewType').which.equal(base.viewType)
|
||||
expect(copy).to.have.property('viewOptions').which.eql(base.viewOptions)
|
||||
@@ -197,14 +199,16 @@ describe('storedInquiries.js', () => {
|
||||
`
|
||||
|
||||
const inquiry = storedInquiries.deserialiseInquiries(str)
|
||||
expect(inquiry).to.eql([{
|
||||
id: 1,
|
||||
name: 'foo',
|
||||
query: 'select * from foo',
|
||||
viewType: 'chart',
|
||||
viewOptions: [],
|
||||
createdAt: '2020-11-03T14:17:49.524Z'
|
||||
}])
|
||||
expect(inquiry).to.eql([
|
||||
{
|
||||
id: 1,
|
||||
name: 'foo',
|
||||
query: 'select * from foo',
|
||||
viewType: 'chart',
|
||||
viewOptions: [],
|
||||
createdAt: '2020-11-03T14:17:49.524Z'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('deserialiseInquiries generates new id to avoid duplication', () => {
|
||||
@@ -256,14 +260,16 @@ describe('storedInquiries.js', () => {
|
||||
sinon.stub(fu, 'importFile').returns(Promise.resolve(str))
|
||||
const inquiries = await storedInquiries.importInquiries()
|
||||
|
||||
expect(inquiries).to.eql([{
|
||||
id: 1,
|
||||
name: 'foo',
|
||||
query: 'select * from foo',
|
||||
viewType: 'chart',
|
||||
viewOptions: [],
|
||||
createdAt: '2020-11-03T14:17:49.524Z'
|
||||
}])
|
||||
expect(inquiries).to.eql([
|
||||
{
|
||||
id: 1,
|
||||
name: 'foo',
|
||||
query: 'select * from foo',
|
||||
viewType: 'chart',
|
||||
viewOptions: [],
|
||||
createdAt: '2020-11-03T14:17:49.524Z'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('importInquiries', async () => {
|
||||
@@ -281,14 +287,16 @@ describe('storedInquiries.js', () => {
|
||||
sinon.stub(fu, 'importFile').returns(Promise.resolve(str))
|
||||
const inquiries = await storedInquiries.importInquiries()
|
||||
|
||||
expect(inquiries).to.eql([{
|
||||
id: 1,
|
||||
name: 'foo',
|
||||
query: 'select * from foo',
|
||||
viewType: 'chart',
|
||||
viewOptions: [],
|
||||
createdAt: '2020-11-03T14:17:49.524Z'
|
||||
}])
|
||||
expect(inquiries).to.eql([
|
||||
{
|
||||
id: 1,
|
||||
name: 'foo',
|
||||
query: 'select * from foo',
|
||||
viewType: 'chart',
|
||||
viewOptions: [],
|
||||
createdAt: '2020-11-03T14:17:49.524Z'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('readPredefinedInquiries old', async () => {
|
||||
@@ -312,7 +320,8 @@ describe('storedInquiries.js', () => {
|
||||
viewType: 'chart',
|
||||
viewOptions: [],
|
||||
createdAt: '2020-11-03T14:17:49.524Z'
|
||||
}])
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('readPredefinedInquiries', async () => {
|
||||
@@ -340,6 +349,7 @@ describe('storedInquiries.js', () => {
|
||||
viewType: 'chart',
|
||||
viewOptions: [],
|
||||
createdAt: '2020-11-03T14:17:49.524Z'
|
||||
}])
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -75,9 +75,11 @@ describe('tab.js', () => {
|
||||
currentTabId: 1,
|
||||
dbName: 'fooDb',
|
||||
db: {
|
||||
execute: sinon.stub().returns(new Promise(resolve => {
|
||||
resolveQuering = resolve
|
||||
})),
|
||||
execute: sinon.stub().returns(
|
||||
new Promise(resolve => {
|
||||
resolveQuering = resolve
|
||||
})
|
||||
),
|
||||
refreshSchema: sinon.stub().resolves()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ describe('fileIo.js', () => {
|
||||
|
||||
expect(document.createElement.calledOnceWith('a')).to.equal(true)
|
||||
|
||||
expect(window.Blob.calledOnceWith(['foo'], { type: 'octet/stream' })).to.equal(true)
|
||||
expect(
|
||||
window.Blob.calledOnceWith(['foo'], { type: 'octet/stream' })
|
||||
).to.equal(true)
|
||||
const blob = window.Blob.returnValues[0]
|
||||
expect(URL.createObjectURL.calledOnceWith(blob)).to.equal(true)
|
||||
|
||||
@@ -49,7 +51,9 @@ describe('fileIo.js', () => {
|
||||
|
||||
expect(document.createElement.calledOnceWith('a')).to.equal(true)
|
||||
|
||||
expect(window.Blob.calledOnceWith(['foo'], { type: 'text/html' })).to.equal(true)
|
||||
expect(window.Blob.calledOnceWith(['foo'], { type: 'text/html' })).to.equal(
|
||||
true
|
||||
)
|
||||
const blob = window.Blob.returnValues[0]
|
||||
expect(URL.createObjectURL.calledOnceWith(blob)).to.equal(true)
|
||||
|
||||
@@ -74,7 +78,9 @@ describe('fileIo.js', () => {
|
||||
|
||||
sinon.stub(document, 'createElement').returns(spyInput)
|
||||
|
||||
setTimeout(() => { spyInput.dispatchEvent(new Event('change')) })
|
||||
setTimeout(() => {
|
||||
spyInput.dispatchEvent(new Event('change'))
|
||||
})
|
||||
|
||||
const data = await fIo.importFile()
|
||||
expect(data).to.equal('foo')
|
||||
@@ -108,7 +114,9 @@ describe('fileIo.js', () => {
|
||||
sinon.stub(window, 'FileReader').returns(r)
|
||||
|
||||
const blob = new Blob(['foo'])
|
||||
await expect(fIo.readAsArrayBuffer(blob)).to.be.rejectedWith('Problem parsing input file.')
|
||||
await expect(fIo.readAsArrayBuffer(blob)).to.be.rejectedWith(
|
||||
'Problem parsing input file.'
|
||||
)
|
||||
})
|
||||
|
||||
it('isJSON', () => {
|
||||
|
||||
Reference in New Issue
Block a user