1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00

Pivot implementation and redesign (#69)

- Pivot support implementation 
- Rename queries into inquiries
- Rename editor into workspace
- Change result set format
- New JSON format for inquiries
- Redesign panels
This commit is contained in:
lana-k
2021-08-04 22:20:51 +02:00
committed by GitHub
parent 8d0bc6affe
commit 5017b55944
105 changed files with 4659 additions and 2021 deletions

View File

@@ -58,12 +58,10 @@ describe('CsvImport.vue', () => {
sinon.stub(csv, 'parse').resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar']
]
col1: [1, 2],
col2: ['foo', 'bar']
},
rowCount: 2,
messages: [{
code: 'UndetectableDelimiter',
message: 'Comma was used as a standart delimiter',
@@ -101,11 +99,10 @@ describe('CsvImport.vue', () => {
parse.onCall(0).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
}
col1: [1],
col2: ['foo']
},
rowCount: 1
})
wrapper.vm.previewCsv()
@@ -116,11 +113,10 @@ describe('CsvImport.vue', () => {
parse.onCall(1).resolves({
delimiter: ',',
data: {
columns: ['col1', 'col2'],
values: [
[2, 'bar']
]
col1: [2],
col2: ['bar']
},
rowCount: 1,
hasErrors: false
})
await wrapper.find('.delimiter-selector-container input').setValue(',')
@@ -137,11 +133,10 @@ describe('CsvImport.vue', () => {
parse.onCall(2).resolves({
delimiter: ',',
data: {
columns: ['col1', 'col2'],
values: [
[3, 'baz']
]
col1: [3],
col2: ['baz']
},
rowCount: 1,
hasErrors: true,
messages: [{
code: 'MissingQuotes',
@@ -167,11 +162,10 @@ describe('CsvImport.vue', () => {
parse.onCall(3).resolves({
delimiter: ',',
data: {
columns: ['col1', 'col2'],
values: [
[4, 'qux']
]
col1: [4],
col2: ['qux']
},
rowCount: 1,
hasErrors: false
})
await wrapper.find('#escape-char input').setValue("'")
@@ -187,11 +181,10 @@ describe('CsvImport.vue', () => {
parse.onCall(4).resolves({
delimiter: ',',
data: {
columns: ['col1', 'col2'],
values: [
[5, 'corge']
]
col1: [5],
col2: ['corge']
},
rowCount: 1,
hasErrors: false
})
await wrapper.findComponent({ name: 'check-box' }).trigger('click')
@@ -210,11 +203,10 @@ describe('CsvImport.vue', () => {
parse.onCall(0).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
}
col1: [1],
col2: ['foo']
},
rowCount: 1
})
wrapper.vm.previewCsv()
@@ -264,11 +256,10 @@ describe('CsvImport.vue', () => {
parse.onCall(0).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
rowCount: 1,
hasErrors: false,
messages: []
})
@@ -276,12 +267,10 @@ describe('CsvImport.vue', () => {
parse.onCall(1).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar']
]
col1: [1, 2],
col2: ['foo', 'bar']
},
rowCount: 2,
hasErrors: false,
messages: []
})
@@ -322,11 +311,10 @@ describe('CsvImport.vue', () => {
parse.onCall(0).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
rowCount: 1,
hasErrors: false,
messages: []
})
@@ -334,12 +322,10 @@ describe('CsvImport.vue', () => {
parse.onCall(1).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar']
]
col1: [1, 2],
col2: ['foo', 'bar']
},
rowCount: 2,
hasErrors: false,
messages: [{
code: 'UndetectableDelimiter',
@@ -387,11 +373,10 @@ describe('CsvImport.vue', () => {
parse.onCall(0).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
rowCount: 1,
hasErrors: false,
messages: []
})
@@ -399,12 +384,10 @@ describe('CsvImport.vue', () => {
parse.onCall(1).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar']
]
col1: [1, 2],
col2: ['foo', 'bar']
},
rowCount: 2,
hasErrors: true,
messages: [{
code: 'Error',
@@ -446,11 +429,10 @@ describe('CsvImport.vue', () => {
parse.onCall(0).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
rowCount: 1,
hasErrors: false,
messages: []
})
@@ -458,12 +440,10 @@ describe('CsvImport.vue', () => {
parse.onCall(1).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar']
]
col1: [1, 2],
col2: ['foo', 'bar']
},
rowCount: 2,
hasErrors: false,
messages: []
})
@@ -516,11 +496,10 @@ describe('CsvImport.vue', () => {
parse.onCall(0).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
rowCount: 1,
hasErrors: false,
messages: []
})
@@ -528,12 +507,10 @@ describe('CsvImport.vue', () => {
parse.onCall(1).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar']
]
col1: [1, 2],
col2: ['foo', 'bar']
},
rowCount: 2,
hasErrors: false,
messages: []
})
@@ -568,11 +545,10 @@ describe('CsvImport.vue', () => {
parse.onCall(0).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
rowCount: 1,
hasErrors: false,
messages: []
})
@@ -580,12 +556,10 @@ describe('CsvImport.vue', () => {
parse.onCall(1).resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar']
]
col1: [1, 2],
col2: ['foo', 'bar']
},
rowCount: 2,
hasErrors: false,
messages: []
})
@@ -622,11 +596,10 @@ describe('CsvImport.vue', () => {
sinon.stub(csv, 'parse').resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
rowCount: 1,
hasErrors: false,
messages: []
})
@@ -651,11 +624,10 @@ describe('CsvImport.vue', () => {
sinon.stub(csv, 'parse').resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
rowCount: 1,
hasErrors: false,
messages: []
})

View File

@@ -19,11 +19,9 @@ describe('csv.js', () => {
}
}
expect(csv.getResult(source)).to.eql({
columns: ['id', 'name', 'date'],
values: [
[1, 'foo', '2021-06-30T14:10:24.717Z'],
[2, 'bar', '2021-07-30T14:10:15.717Z']
]
id: [1, 2],
name: ['foo', 'bar'],
date: ['2021-06-30T14:10:24.717Z', '2021-07-30T14:10:15.717Z']
})
})
@@ -36,11 +34,9 @@ describe('csv.js', () => {
meta: {}
}
expect(csv.getResult(source)).to.eql({
columns: ['col1', 'col2', 'col3'],
values: [
[1, 'foo', '2021-06-30T14:10:24.717Z'],
[2, 'bar', '2021-07-30T14:10:15.717Z']
]
col1: [1, 2],
col2: ['foo', 'bar'],
col3: ['2021-06-30T14:10:24.717Z', '2021-07-30T14:10:15.717Z']
})
})
@@ -77,13 +73,11 @@ describe('csv.js', () => {
const result = await csv.parse(file)
expect(result).to.eql({
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo'],
[2, 'bar']
]
col1: [1, 2],
col2: ['foo', 'bar']
},
delimiter: ',',
rowCount: 2,
hasErrors: true,
messages: [
{

View File

@@ -29,7 +29,7 @@ describe('DbUploader.vue', () => {
place.remove()
})
it('loads db on click and redirects to /editor', async () => {
it('loads db on click and redirects to /workspace', async () => {
// mock getting a file from user
const file = { name: 'test.db' }
sinon.stub(fu, 'getFileFromUser').resolves(file)
@@ -59,11 +59,11 @@ describe('DbUploader.vue', () => {
await db.loadDb.returnValues[0]
await wrapper.vm.animationPromise
await wrapper.vm.$nextTick()
expect($router.push.calledOnceWith('/editor')).to.equal(true)
expect($router.push.calledOnceWith('/workspace')).to.equal(true)
wrapper.destroy()
})
it('loads db on drop and redirects to /editor', async () => {
it('loads db on drop and redirects to /workspace', async () => {
// mock db loading
const db = {
loadDb: sinon.stub().resolves()
@@ -97,11 +97,11 @@ describe('DbUploader.vue', () => {
await db.loadDb.returnValues[0]
await wrapper.vm.animationPromise
await wrapper.vm.$nextTick()
expect($router.push.calledOnceWith('/editor')).to.equal(true)
expect($router.push.calledOnceWith('/workspace')).to.equal(true)
wrapper.destroy()
})
it("doesn't redirect if already on /editor", async () => {
it("doesn't redirect if already on /workspace", async () => {
// mock getting a file from user
const file = { name: 'test.db' }
sinon.stub(fu, 'getFileFromUser').resolves(file)
@@ -114,7 +114,7 @@ describe('DbUploader.vue', () => {
// mock router
const $router = { push: sinon.stub() }
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
// mount the component
const wrapper = shallowMount(DbUploader, {
@@ -141,7 +141,7 @@ describe('DbUploader.vue', () => {
// mock router
const $router = { push: sinon.stub() }
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
// mount the component
const wrapper = mount(DbUploader, {
@@ -175,7 +175,7 @@ describe('DbUploader.vue', () => {
// mock router
const $router = { push: sinon.stub() }
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
// mount the component
const wrapper = mount(DbUploader, {

View File

@@ -8,6 +8,7 @@ describe('Logs.vue', () => {
place = document.createElement('div')
document.body.appendChild(place)
})
afterEach(() => {
place.remove()
})

View File

@@ -34,10 +34,11 @@ describe('_sql.js', () => {
sql.open(data)
const result = sql.exec('SELECT * from test')
expect(result).to.have.lengthOf(1)
expect(result[0].columns).to.eql(['id', 'name', 'faculty'])
expect(result[0].values).to.have.lengthOf(2)
expect(result[0].values[0]).to.eql([1, 'Harry Potter', 'Griffindor'])
expect(result[0].values[1]).to.eql([2, 'Draco Malfoy', 'Slytherin'])
expect(result[0]).to.eql({
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
})
})
it('throws an error if query is empty', async () => {
@@ -63,26 +64,21 @@ describe('_sql.js', () => {
it('imports', async () => {
const data = {
columns: ['id', 'name'],
values: [
[1, 'Harry Potter'],
[2, 'Draco Malfoy'],
[3, 'Hermione Granger'],
[4, 'Ron Weasley']
id: [1, 2, 3, 4],
name: [
'Harry Potter',
'Draco Malfoy',
'Hermione Granger',
'Ron Weasley'
]
}
const progressCallback = sinon.stub()
const progressCounterId = 1
const sql = await Sql.build()
sql.import('foo', data.columns, data.values, progressCounterId, progressCallback, 2)
sql.import('foo', data, progressCounterId, progressCallback, 2)
const result = sql.exec('SELECT * from foo')
expect(result).to.have.lengthOf(1)
expect(result[0].columns).to.eql(['id', 'name'])
expect(result[0].values).to.have.lengthOf(4)
expect(result[0].values[0]).to.eql([1, 'Harry Potter'])
expect(result[0].values[1]).to.eql([2, 'Draco Malfoy'])
expect(result[0].values[2]).to.eql([3, 'Hermione Granger'])
expect(result[0].values[3]).to.eql([4, 'Ron Weasley'])
expect(result[0]).to.eql(data)
expect(progressCallback.calledThrice).to.equal(true)
expect(progressCallback.getCall(0).args[0]).to.eql({ progress: 0, id: 1 })
@@ -108,10 +104,11 @@ describe('_sql.js', () => {
anotherSql.open(data)
const result = anotherSql.exec('SELECT * from test')
expect(result).to.have.lengthOf(1)
expect(result[0].columns).to.eql(['id', 'name', 'faculty'])
expect(result[0].values).to.have.lengthOf(2)
expect(result[0].values[0]).to.eql([1, 'Harry Potter', 'Griffindor'])
expect(result[0].values[1]).to.eql([2, 'Draco Malfoy', 'Slytherin'])
expect(result[0]).to.eql({
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
})
})
it('closes', async () => {
@@ -149,22 +146,28 @@ describe('_sql.js', () => {
`)
let result = sql.exec('SELECT * from test')
expect(result[0].values).to.have.lengthOf(2)
expect(result[0]).to.eql({
id: [1, 2],
name: ['foo', 'bar']
})
const data = {
columns: ['id', 'name'],
values: [
[1, 'Harry Potter'],
[2, 'Draco Malfoy'],
[3, 'Hermione Granger'],
[4, 'Ron Weasley']
id: [1, 2, 3, 4],
name: [
'Harry Potter',
'Draco Malfoy',
'Hermione Granger',
'Ron Weasley'
]
}
// import adds table
sql.import('foo', data.columns, data.values, 1, sinon.stub(), 2)
sql.import('foo', data, 1, sinon.stub(), 2)
result = sql.exec('SELECT * from foo')
expect(result[0].values).to.have.lengthOf(4)
expect(result[0]).to.eql(data)
result = sql.exec('SELECT * from test')
expect(result[0].values).to.have.lengthOf(2)
expect(result[0]).to.eql({
id: [1, 2],
name: ['foo', 'bar']
})
})
})

View File

@@ -3,16 +3,18 @@ import stmts from '@/lib/database/_statements'
describe('_statements.js', () => {
it('generateChunks', () => {
const arr = ['1', '2', '3', '4', '5']
const source = {
id: ['1', '2', '3', '4', '5']
}
const size = 2
const chunks = stmts.generateChunks(arr, size)
const chunks = stmts.generateChunks(source, size)
const output = []
for (const chunk of chunks) {
output.push(chunk)
}
expect(output[0]).to.eql(['1', '2'])
expect(output[1]).to.eql(['3', '4'])
expect(output[2]).to.eql(['5'])
expect(output[0]).to.eql([['1'], ['2']])
expect(output[1]).to.eql([['3'], ['4']])
expect(output[2]).to.eql([['5']])
})
it('getInsertStmt', () => {
@@ -22,12 +24,14 @@ describe('_statements.js', () => {
})
it('getCreateStatement', () => {
const columns = ['id', 'name', 'isAdmin', 'startDate']
const values = [
[1, 'foo', true, new Date()],
[2, 'bar', false, new Date()]
]
expect(stmts.getCreateStatement('foo', columns, values)).to.equal(
const data = {
id: [1, 2],
name: ['foo', 'bar'],
isAdmin: [true, false],
startDate: [new Date(), new Date()]
}
expect(stmts.getCreateStatement('foo', data)).to.equal(
'CREATE table "foo"("id" REAL, "name" TEXT, "isAdmin" INTEGER, "startDate" TEXT);'
)
})

View File

@@ -25,10 +25,7 @@ describe('database.js', () => {
it('creates schema', async () => {
const SQL = await getSQL
const tempDb = new SQL.Database()
tempDb.run(`CREATE TABLE test (
col1,
col2 integer
)`)
tempDb.run('CREATE TABLE test (col1, col2 integer)')
const data = tempDb.export()
const buffer = new Blob([data])
@@ -88,11 +85,11 @@ describe('database.js', () => {
await db.loadDb(buffer)
const result = await db.execute('SELECT * from test limit 1; SELECT * from test;')
expect(result.columns).to.have.lengthOf(3)
expect(result.columns).to.eql(['id', 'name', 'faculty'])
expect(result.values).to.have.lengthOf(2)
expect(result.values[0]).to.eql([1, 'Harry Potter', 'Griffindor'])
expect(result.values[1]).to.eql([2, 'Draco Malfoy', 'Slytherin'])
expect(result).to.eql({
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
})
})
it('returns an error', async () => {
@@ -119,11 +116,9 @@ describe('database.js', () => {
it('adds table from csv', async () => {
const data = {
columns: ['id', 'name', 'faculty'],
values: [
[1, 'Harry Potter', 'Griffindor'],
[2, 'Draco Malfoy', 'Slytherin']
]
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: ['Griffindor', 'Slytherin']
}
const progressHandler = sinon.spy()
const progressCounterId = db.createProgressCounter(progressHandler)
@@ -140,8 +135,7 @@ describe('database.js', () => {
expect(db.schema[0].columns[2]).to.eql({ name: 'faculty', type: 'text' })
const result = await db.execute('SELECT * from foo')
expect(result.columns).to.eql(data.columns)
expect(result.values).to.eql(data.values)
expect(result).to.eql(data)
expect(progressHandler.calledTwice).to.equal(true)
expect(progressHandler.firstCall.calledWith(0)).to.equal(true)
@@ -150,16 +144,13 @@ describe('database.js', () => {
it('addTableFromCsv throws errors', async () => {
const data = {
columns: ['id', 'name'],
values: [
[1, 'Harry Potter', 'Griffindor'],
[2, 'Draco Malfoy', 'Slytherin']
]
id: [1, 2],
name: ['Harry Potter', 'Draco Malfoy'],
faculty: null
}
const progressHandler = sinon.stub()
const progressCounterId = db.createProgressCounter(progressHandler)
await expect(db.addTableFromCsv('foo', data, progressCounterId))
.to.be.rejectedWith('column index out of range')
await expect(db.addTableFromCsv('foo', data, progressCounterId)).to.be.rejected
})
it('progressCounters', () => {
@@ -222,9 +213,10 @@ describe('database.js', () => {
// check that new db works and has the same table and data
result = await anotherDb.execute('SELECT * from foo')
expect(result.columns).to.eql(['id', 'name'])
expect(result.values).to.have.lengthOf(1)
expect(result.values[0]).to.eql([1, 'Harry Potter'])
expect(result).to.eql({
id: [1],
name: ['Harry Potter']
})
})
it('sanitizeTableName', () => {

View File

@@ -36,7 +36,27 @@ describe('SQLite extensions', function () {
abs(pi() - radians(180)) < 0.000001,
abs(pi() / 2 - atan2(1, 0)) < 0.000001
`)
expect(actual.values).to.eql([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
expect(actual).to.eql({
'abs(3.1415926 - pi()) < 0.000001': [1],
'abs(1 - cos(2 * pi())) < 0.000001': [1],
'abs(0 - sin(pi())) < 0.000001': [1],
'abs(0 - tan(0)) < 0.000001': [1],
'abs(0 - cot(pi() / 2)) < 0.000001': [1],
'abs(1 - acos(cos(1))) < 0.000001': [1],
'abs(1 - asin(sin(1))) < 0.000001': [1],
'abs(1 - atan(tan(1))) < 0.000001': [1],
'abs(1 - cosh(0)) < 0.000001': [1],
'abs(0 - sinh(0)) < 0.000001': [1],
'abs(tanh(1) + tanh(-1)) < 0.000001': [1],
'abs(coth(1) + coth(-1)) < 0.000001': [1],
'abs(1 - acosh(cosh(1))) < 0.000001': [1],
'abs(1 - asinh(sinh(1))) < 0.000001': [1],
'abs(1 - atanh(tanh(1))) < 0.000001': [1],
'abs(180 - degrees(pi())) < 0.000001': [1],
'abs(pi() - radians(180)) < 0.000001': [1],
'abs(pi() / 2 - atan2(1, 0)) < 0.000001': [1]
})
})
it('supports contrib math functions', async function () {
@@ -51,7 +71,17 @@ describe('SQLite extensions', function () {
ceil(-1.95) + ceil(1.95),
floor(-1.95) + floor(1.95)
`)
expect(actual.values).to.eql([[1, 1, 4, 8, 0, 16, 1, -1]])
expect(actual).to.eql({
'exp(0)': [1],
'log(exp(1))': [1],
'log10(10000)': [4],
'power(2, 3)': [8],
'sign(-10) + sign(20)': [0],
'sqrt(square(16))': [16],
'ceil(-1.95) + ceil(1.95)': [1],
'floor(-1.95) + floor(1.95)': [-1]
})
})
it('supports contrib string functions', async function () {
@@ -69,9 +99,19 @@ describe('SQLite extensions', function () {
padc('foo', 5),
strfilter('abcba', 'bc')
`)
expect(actual.values).to.eql([
['abababab', 7, 0, 'fo', 'ar', 'raboof', 'Foobar', ' foo', 'foo ', ' foo ', 'bcb']
])
expect(actual).to.eql({
"replicate('ab', 4)": ['abababab'],
"charindex('ab', 'foobarabbarfoo')": [7],
"charindex('ab', 'foobarabbarfoo', 8)": [0],
"leftstr('foobar', 2)": ['fo'],
"rightstr('foobar', 2)": ['ar'],
"reverse('foobar')": ['raboof'],
"proper('fooBar')": ['Foobar'],
"padl('foo', 5)": [' foo'],
"padr('foo', 5)": ['foo '],
"padc('foo', 5)": [' foo '],
"strfilter('abcba', 'bc')": ['bcb']
})
})
it('supports contrib aggregate functions', async function () {
@@ -97,7 +137,14 @@ describe('SQLite extensions', function () {
VALUES (1)
)
`)
expect(actual.values).to.eql([[1, 1, 1, 6, 3, 9]])
expect(actual).to.eql({
'abs( 3.77406806 - stdev(x)) < 0.000001': [1],
'abs(14.24358974 - variance(x)) < 0.000001': [1],
'mode(x)': [1],
'median(x)': [6],
'lower_quartile(x)': [3],
'upper_quartile(x)': [9]
})
})
it('supports generate_series', async function () {
@@ -105,7 +152,9 @@ describe('SQLite extensions', function () {
SELECT value
FROM generate_series(5, 20, 5)
`)
expect(actual.values).to.eql([[5], [10], [15], [20]])
expect(actual).to.eql({
value: [5, 10, 15, 20]
})
})
it('supports transitive_closure', async function () {
@@ -145,33 +194,42 @@ describe('SQLite extensions', function () {
WHERE nc.root = 2 AND nc.depth = 2
);
`)
expect(actual.values).to.eql([
['_sql.spec.js'],
['_statements.spec.js'],
['database.spec.js'],
['sqliteExtensions.spec.js'],
['fileIo.spec.js'],
['time.spec.js']
])
expect(actual).to.eql({
name: [
'_sql.spec.js',
'_statements.spec.js',
'database.spec.js',
'sqliteExtensions.spec.js',
'fileIo.spec.js',
'time.spec.js'
]
})
})
it('supports UUID functions', async function () {
const actual = await db.execute(`
SELECT
length(uuid()),
uuid_str(uuid_blob('26a8349c8a7f4cbeb519bf792c3d7ac6'))
length(uuid()) as length,
uuid_str(uuid_blob('26a8349c8a7f4cbeb519bf792c3d7ac6')) as uid
`)
expect(actual.values).to.eql([[36, '26a8349c-8a7f-4cbe-b519-bf792c3d7ac6']])
expect(actual).to.eql({
length: [36],
uid: ['26a8349c-8a7f-4cbe-b519-bf792c3d7ac6']
})
})
it('supports regexp', async function () {
const actual = await db.execute(`
SELECT
regexp('=\\s?\\d+', 'const foo = 123; const bar = "bar"'),
regexpi('=\\s?\\d+', 'const foo = 123; const bar = "bar"'),
'const foo = 123; const bar = "bar"' REGEXP '=\\s?\\d+'
regexp('=\\s?\\d+', 'const foo = 123; const bar = "bar"') as one,
regexpi('=\\s?\\d+', 'const foo = 123; const bar = "bar"') as two,
'const foo = 123; const bar = "bar"' REGEXP '=\\s?\\d+' as three
`)
expect(actual.values).to.eql([[1, 1, 1]])
expect(actual).to.eql({
one: [1],
two: [1],
three: [1]
})
})
it('supports pivot virtual table', async function () {
@@ -202,12 +260,13 @@ describe('SQLite extensions', function () {
ALTER TABLE surface DROP COLUMN rownum;
SELECT * FROM surface;
`)
expect(actual.columns).to.eql(['x', 'y', '5.0', '10.0', '15.0'])
expect(actual.values).to.eql([
[5, 3, 3.2, 4, 4.8],
[10, 6, 4.3, 3.8, 4],
[15, 9, 5.4, 3.6, 3.5]
])
expect(actual).to.eql({
x: [5, 10, 15],
y: [3, 6, 9],
'5.0': [3.2, 4.3, 5.4],
'10.0': [4, 3.8, 3.6],
'15.0': [4.8, 4, 3.5]
})
})
it('supports FTS5', async function () {
@@ -233,6 +292,8 @@ describe('SQLite extensions', function () {
WHERE body MATCH '"full-text" NOT document'
ORDER BY rank;
`)
expect(actual.values).to.eql([['bar@localhost']])
expect(actual).to.eql({
sender: ['bar@localhost']
})
})
})

View File

@@ -0,0 +1,42 @@
import { expect } from 'chai'
import migrations from '@/lib/storedInquiries/_migrations'
describe('_migrations.js', () => {
it('migrates from version 1 to the current', () => {
const oldInquiries = [
{
id: '123',
name: 'foo',
query: 'SELECT * FROM foo',
chart: { here_are: 'foo chart settings' },
createdAt: '2021-05-06T11:05:50.877Z'
},
{
id: '456',
name: 'bar',
query: 'SELECT * FROM bar',
chart: { here_are: 'bar chart settings' },
createdAt: '2021-05-07T11:05:50.877Z'
}
]
expect(migrations._migrate(1, oldInquiries)).to.eql([
{
id: '123',
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: { here_are: 'foo chart settings' },
createdAt: '2021-05-06T11:05:50.877Z'
},
{
id: '456',
name: 'bar',
query: 'SELECT * FROM bar',
viewType: 'chart',
viewOptions: { here_are: 'bar chart settings' },
createdAt: '2021-05-07T11:05:50.877Z'
}
])
})
})

View File

@@ -0,0 +1,432 @@
import { expect } from 'chai'
import sinon from 'sinon'
import storedInquiries from '@/lib/storedInquiries'
import fu from '@/lib/utils/fileIo'
describe('storedInquiries.js', () => {
beforeEach(() => {
localStorage.removeItem('myInquiries')
localStorage.removeItem('myQueries')
})
afterEach(() => {
sinon.restore()
})
it('getStoredInquiries returns emplty array when storage is empty', () => {
const inquiries = storedInquiries.getStoredInquiries()
expect(inquiries).to.eql([])
})
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' }
}
]))
const inquiries = storedInquiries.getStoredInquiries()
expect(inquiries).to.eql([
{
id: '123',
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: { here_are: 'foo chart settings' }
},
{
id: '456',
name: 'bar',
query: 'SELECT * FROM bar',
viewType: 'chart',
viewOptions: { here_are: 'bar chart settings' }
}
])
})
it('updateStorage and getStoredInquiries', () => {
const data = [
{ id: 1 },
{ id: 2 }
]
storedInquiries.updateStorage(data)
const inquiries = storedInquiries.getStoredInquiries()
expect(inquiries).to.eql(data)
})
it('duplicateInquiry', () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)
const base = {
id: 1,
name: 'foo',
query: 'SELECT * from foo',
viewType: 'chart',
viewOptions: [],
createdAt: new Date(2021, 0, 1),
isPredefined: true
}
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('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)
expect(copy).to.have.property('createdAt').which.within(now, nowPlusMinute)
expect(copy).to.not.have.property('isPredefined')
})
it('isTabNeedName returns false when the inquiry has a name and is not predefined', () => {
const tab = {
initName: 'foo'
}
expect(storedInquiries.isTabNeedName(tab)).to.equal(false)
})
it('isTabNeedName returns true when the inquiry has no name and is not predefined', () => {
const tab = {
initName: null,
tempName: 'Untitled'
}
expect(storedInquiries.isTabNeedName(tab)).to.equal(true)
})
it('isTabNeedName returns true when the inquiry is predefined', () => {
const tab = {
initName: 'foo',
isPredefined: true
}
expect(storedInquiries.isTabNeedName(tab)).to.equal(true)
})
it('serialiseInquiries', () => {
const inquiryList = [
{
id: 1,
name: 'foo',
query: 'SELECT from foo',
viewType: 'chart',
viewOptions: [],
createdAt: '2020-11-03T14:17:49.524Z',
isPredefined: true
},
{
id: 2,
name: 'bar',
query: 'SELECT from bar',
viewType: 'chart',
viewOptions: [],
createdAt: '2020-12-03T14:17:49.524Z'
}
]
const str = storedInquiries.serialiseInquiries(inquiryList)
const parsedJson = JSON.parse(str)
expect(parsedJson.version).to.equal(2)
expect(parsedJson.inquiries).to.have.lengthOf(2)
expect(parsedJson.inquiries[1]).to.eql(inquiryList[1])
expect(parsedJson.inquiries[0]).to.eql({
id: 1,
name: 'foo',
query: 'SELECT from foo',
viewType: 'chart',
viewOptions: [],
createdAt: '2020-11-03T14:17:49.524Z'
})
})
it('deserialiseInquiries migrates inquiries', () => {
const str = `[
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"chart": [],
"createdAt": "2020-11-03T14:17:49.524Z"
},
{
"id": 2,
"name": "bar",
"query": "select * from bar",
"chart": [],
"createdAt": "2020-11-04T14:17:49.524Z"
}
]`
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'
},
{
id: 2,
name: 'bar',
query: 'select * from bar',
viewType: 'chart',
viewOptions: [],
createdAt: '2020-11-04T14:17:49.524Z'
}
])
})
it('deserialiseInquiries return array for one inquiry of v1', () => {
const str = `
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"chart": [],
"createdAt": "2020-11-03T14:17:49.524Z"
}
`
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'
}])
})
it('deserialiseInquiries generates new id to avoid duplication', () => {
storedInquiries.updateStorage([{ id: 1 }])
const str = `{
"version": 2,
"inquiries": [
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"viewType": "chart",
"viewOptions": [],
"createdAt": "2020-11-03T14:17:49.524Z"
},
{
"id": 2,
"name": "bar",
"query": "select * from bar",
"viewType": "chart",
"viewOptions": [],
"createdAt": "2020-11-04T14:17:49.524Z"
}
]
}`
const inquiries = storedInquiries.deserialiseInquiries(str)
const parsedStr = JSON.parse(str)
expect(inquiries[1]).to.eql(parsedStr.inquiries[1])
expect(inquiries[0].id).to.not.equal(parsedStr.inquiries[0].id)
expect(inquiries[0].id).to.not.equal(parsedStr.inquiries[0].id)
expect(inquiries[0].name).to.equal(parsedStr.inquiries[0].name)
expect(inquiries[0].query).to.equal(parsedStr.inquiries[0].query)
expect(inquiries[0].viewType).to.equal(parsedStr.inquiries[0].viewType)
expect(inquiries[0].viewOptions).to.eql(parsedStr.inquiries[0].viewOptions)
expect(inquiries[0].createdAt).to.equal(parsedStr.inquiries[0].createdAt)
})
it('importInquiries v1', async () => {
const str = `
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"chart": [],
"createdAt": "2020-11-03T14:17:49.524Z"
}
`
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'
}])
})
it('importInquiries', async () => {
const str = `{
"version": 2,
"inquiries": [{
"id": 1,
"name": "foo",
"query": "select * from foo",
"viewType": "chart",
"viewOptions": [],
"createdAt": "2020-11-03T14:17:49.524Z"
}]
}`
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'
}])
})
it('readPredefinedInquiries old', async () => {
const str = `[
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"chart": [],
"createdAt": "2020-11-03T14:17:49.524Z"
}]
`
sinon.stub(fu, 'readFile').returns(Promise.resolve(new Response(str)))
const inquiries = await storedInquiries.readPredefinedInquiries()
expect(fu.readFile.calledOnceWith('./inquiries.json')).to.equal(true)
expect(inquiries).to.eql([
{
id: 1,
name: 'foo',
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
createdAt: '2020-11-03T14:17:49.524Z'
}])
})
it('readPredefinedInquiries', async () => {
const str = `{
"version": 2,
"inquiries": [
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"viewType": "chart",
"viewOptions": [],
"createdAt": "2020-11-03T14:17:49.524Z"
}]
}
`
sinon.stub(fu, 'readFile').returns(Promise.resolve(new Response(str)))
const inquiries = await storedInquiries.readPredefinedInquiries()
expect(fu.readFile.calledOnceWith('./inquiries.json')).to.equal(true)
expect(inquiries).to.eql([
{
id: 1,
name: 'foo',
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
createdAt: '2020-11-03T14:17:49.524Z'
}])
})
it('save adds new inquiry in the storage', () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)
const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
initName: null,
$refs: {
dataView: {
getOptionsForSave () {
return ['chart']
}
}
}
}
const value = storedInquiries.save(tab, 'foo')
expect(value.id).to.equal(tab.id)
expect(value.name).to.equal('foo')
expect(value.query).to.equal(tab.query)
expect(value.viewOptions).to.eql(['chart'])
expect(value).to.have.property('createdAt').which.within(now, nowPlusMinute)
const inquiries = storedInquiries.getStoredInquiries()
expect(JSON.stringify(inquiries)).to.equal(JSON.stringify([value]))
})
it('save updates existing inquiry in the storage', () => {
const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
initName: null,
$refs: {
dataView: {
getOptionsForSave () {
return ['chart']
}
}
}
}
const first = storedInquiries.save(tab, 'foo')
tab.initName = 'foo'
tab.query = 'select * from foo'
storedInquiries.save(tab)
const inquiries = storedInquiries.getStoredInquiries()
const second = inquiries[0]
expect(inquiries).has.lengthOf(1)
expect(second.id).to.equal(first.id)
expect(second.name).to.equal(first.name)
expect(second.query).to.equal(tab.query)
expect(second.viewOptions).to.eql(['chart'])
expect(new Date(second.createdAt).getTime()).to.equal(first.createdAt.getTime())
})
it("save adds a new inquiry with new id if it's based on predefined inquiry", () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)
const tab = {
id: 1,
query: 'select * from foo',
viewType: 'chart',
viewOptions: [],
initName: 'foo predefined',
$refs: {
dataView: {
getOptionsForSave () {
return ['chart']
}
}
},
isPredefined: true
}
storedInquiries.save(tab, 'foo')
const inquiries = storedInquiries.getStoredInquiries()
expect(inquiries).has.lengthOf(1)
expect(inquiries[0]).to.have.property('id').which.not.equal(tab.id)
expect(inquiries[0].name).to.equal('foo')
expect(inquiries[0].query).to.equal(tab.query)
expect(inquiries[0].viewOptions).to.eql(['chart'])
expect(new Date(inquiries[0].createdAt)).to.be.within(now, nowPlusMinute)
})
})

View File

@@ -1,267 +0,0 @@
import { expect } from 'chai'
import sinon from 'sinon'
import storedQueries from '@/lib/storedQueries'
import fu from '@/lib/utils/fileIo'
describe('storedQueries.js', () => {
beforeEach(() => {
localStorage.removeItem('myQueries')
})
afterEach(() => {
sinon.restore()
})
it('getStoredQueries returns emplty array when storage is empty', () => {
const queries = storedQueries.getStoredQueries()
expect(queries).to.eql([])
})
it('updateStorage and 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')
})
it('isTabNeedName returns false when the query has a name and is not predefined', () => {
const tab = {
initName: 'foo'
}
expect(storedQueries.isTabNeedName(tab)).to.equal(false)
})
it('isTabNeedName returns true when the query has no name and is not predefined', () => {
const tab = {
initName: null,
tempName: 'Untitled'
}
expect(storedQueries.isTabNeedName(tab)).to.equal(true)
})
it('isTabNeedName returns true when the qiery is predefined', () => {
const tab = {
initName: 'foo',
isPredefined: true
}
expect(storedQueries.isTabNeedName(tab)).to.equal(true)
})
it('serialiseQueries', () => {
const queryList = [
{
id: 1,
name: 'foo',
query: 'SELECT from foo',
chart: [],
createdAt: '2020-11-03T14:17:49.524Z',
isPredefined: true
},
{
id: 2,
name: 'bar',
query: 'SELECT from bar',
chart: [],
createdAt: '2020-12-03T14:17:49.524Z'
}
]
const str = storedQueries.serialiseQueries(queryList)
const parsedJson = JSON.parse(str)
expect(parsedJson).to.have.lengthOf(2)
expect(parsedJson[1]).to.eql(queryList[1])
expect(parsedJson[0].id).to.equal(queryList[0].id)
expect(parsedJson[0].name).to.equal(queryList[0].name)
expect(parsedJson[0].query).to.equal(queryList[0].query)
expect(parsedJson[0].chart).to.eql(queryList[0].chart)
expect(parsedJson[0].createdAt).to.eql(queryList[0].createdAt)
expect(parsedJson[0].chart).to.not.have.property('isPredefined')
})
it('deserialiseQueries return array for one query', () => {
const str = `
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"chart": [],
"createdAt": "2020-11-03T14:17:49.524Z"
}
`
const query = storedQueries.deserialiseQueries(str)
expect(query).to.eql([JSON.parse(str)])
})
it('deserialiseQueries generates new id to avoid duplication', () => {
storedQueries.updateStorage([{ id: 1 }])
const str = `[
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"chart": [],
"createdAt": "2020-11-03T14:17:49.524Z"
},
{
"id": 2,
"name": "bar",
"query": "select * from bar",
"chart": [],
"createdAt": "2020-11-04T14:17:49.524Z"
}
]`
const queries = storedQueries.deserialiseQueries(str)
const parsedStr = JSON.parse(str)
expect(queries[1]).to.eql(parsedStr[1])
expect(queries[0].id).to.not.equal(parsedStr[0].id)
expect(queries[0]).to.have.property('id')
expect(queries[0].id).to.not.equal(parsedStr[0].id)
expect(queries[0].name).to.equal(parsedStr[0].name)
expect(queries[0].query).to.equal(parsedStr[0].query)
expect(queries[0].chart).to.eql(parsedStr[0].chart)
expect(queries[0].createdAt).to.equal(parsedStr[0].createdAt)
})
it('importQueries', async () => {
const str = `
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"chart": [],
"createdAt": "2020-11-03T14:17:49.524Z"
}
`
sinon.stub(fu, 'importFile').returns(Promise.resolve(str))
const queries = await storedQueries.importQueries()
expect(queries).to.eql([JSON.parse(str)])
})
it('readPredefinedQueries', async () => {
const str = `
{
"id": 1,
"name": "foo",
"query": "select * from foo",
"chart": [],
"createdAt": "2020-11-03T14:17:49.524Z"
}
`
sinon.stub(fu, 'readFile').returns(Promise.resolve(new Response(str)))
const queries = await storedQueries.readPredefinedQueries()
expect(fu.readFile.calledOnceWith('./queries.json')).to.equal(true)
expect(queries).to.eql(JSON.parse(str))
})
it('save adds new query in the storage', () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)
const tab = {
id: 1,
query: 'select * from foo',
chart: [],
initName: null,
$refs: {
chart: {
getChartStateForSave () {
return ['chart']
}
}
}
}
const value = storedQueries.save(tab, 'foo')
expect(value.id).to.equal(tab.id)
expect(value.name).to.equal('foo')
expect(value.query).to.equal(tab.query)
expect(value.chart).to.eql(['chart'])
expect(value).to.have.property('createdAt').which.within(now, nowPlusMinute)
const queries = storedQueries.getStoredQueries()
expect(JSON.stringify(queries)).to.equal(JSON.stringify([value]))
})
it('save updates existing query in the storage', () => {
const tab = {
id: 1,
query: 'select * from foo',
chart: [],
initName: null,
$refs: {
chart: {
getChartStateForSave () {
return ['chart']
}
}
}
}
const first = storedQueries.save(tab, 'foo')
tab.initName = 'foo'
tab.query = 'select * from foo'
storedQueries.save(tab)
const queries = storedQueries.getStoredQueries()
const second = queries[0]
expect(queries).has.lengthOf(1)
expect(second.id).to.equal(first.id)
expect(second.name).to.equal(first.name)
expect(second.query).to.equal(tab.query)
expect(second.chart).to.eql(['chart'])
expect(new Date(second.createdAt).getTime()).to.equal(first.createdAt.getTime())
})
it("save adds a new query with new id if it's based on predefined query", () => {
const now = new Date()
const nowPlusMinute = new Date(now.getTime() + 60 * 1000)
const tab = {
id: 1,
query: 'select * from foo',
chart: [],
initName: 'foo predefined',
$refs: {
chart: {
getChartStateForSave () {
return ['chart']
}
}
},
isPredefined: true
}
storedQueries.save(tab, 'foo')
const queries = storedQueries.getStoredQueries()
expect(queries).has.lengthOf(1)
expect(queries[0]).to.have.property('id').which.not.equal(tab.id)
expect(queries[0].name).to.equal('foo')
expect(queries[0].query).to.equal(tab.query)
expect(queries[0].chart).to.eql(['chart'])
expect(new Date(queries[0].createdAt)).to.be.within(now, nowPlusMinute)
})
})

View File

@@ -10,15 +10,30 @@ describe('actions', () => {
untitledLastIndex: 0
}
const id = await addTab({ state })
expect(state.tabs[0].id).to.eql(id)
expect(state.tabs[0].name).to.eql(null)
expect(state.tabs[0].tempName).to.eql('Untitled')
expect(state.tabs[0].isUnsaved).to.eql(true)
let id = await addTab({ state })
expect(state.tabs[0]).to.eql({
id: id,
name: null,
tempName: 'Untitled',
viewType: 'chart',
viewOptions: undefined,
isSaved: false
})
expect(state.untitledLastIndex).to.equal(1)
id = await addTab({ state })
expect(state.tabs[1]).to.eql({
id: id,
name: null,
tempName: 'Untitled 1',
viewType: 'chart',
viewOptions: undefined,
isSaved: false
})
expect(state.untitledLastIndex).to.equal(2)
})
it('addTab adds tab from saved queries', async () => {
it('addTab adds tab from saved inquiries', async () => {
const state = {
tabs: [],
untitledLastIndex: 0
@@ -28,22 +43,24 @@ describe('actions', () => {
name: 'test',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
await addTab({ state }, tab)
expect(state.tabs[0]).to.eql(tab)
expect(state.untitledLastIndex).to.equal(0)
})
it("addTab doesn't add anything when the query is already opened", async () => {
it("addTab doesn't add anything when the inquiry is already opened", async () => {
const tab1 = {
id: 1,
name: 'test',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const tab2 = {
@@ -51,8 +68,9 @@ describe('actions', () => {
name: 'bar',
tempName: null,
query: 'SELECT * from bar',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const state = {

View File

@@ -6,7 +6,7 @@ const {
deleteTab,
setCurrentTabId,
setCurrentTab,
updatePredefinedQueries,
updatePredefinedInquiries,
setDb
} = mutations
@@ -23,14 +23,15 @@ describe('mutations', () => {
expect(oldDb.shutDown.calledOnce).to.equal(true)
})
it('updateTab (save)', () => {
it('updateTab - save', () => {
const tab = {
id: 1,
name: 'test',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: true,
viewType: 'chart',
viewOptions: { here_are: 'chart settings' },
isSaved: false,
isPredefined: false
}
@@ -39,7 +40,9 @@ describe('mutations', () => {
id: 1,
name: 'new test',
query: 'SELECT * from bar',
isUnsaved: false
viewType: 'pivot',
viewOptions: { here_are: 'pivot settings' },
isSaved: true
}
const state = {
@@ -47,21 +50,26 @@ describe('mutations', () => {
}
updateTab(state, newTab)
expect(state.tabs[0].id).to.equal(1)
expect(state.tabs[0].name).to.equal('new test')
expect(state.tabs[0].tempName).to.equal(null)
expect(state.tabs[0].query).to.equal('SELECT * from bar')
expect(state.tabs[0].isUnsaved).to.equal(false)
expect(state.tabs[0]).to.eql({
id: 1,
name: 'new test',
tempName: null,
query: 'SELECT * from bar',
viewType: 'pivot',
viewOptions: { here_are: 'pivot settings' },
isSaved: true
})
})
it('updateTab (save predefined)', () => {
it('updateTab - save predefined', () => {
const tab = {
id: 1,
name: 'test',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: true,
viewType: 'chart',
viewOptions: {},
isSaved: false,
isPredefined: true
}
@@ -70,8 +78,9 @@ describe('mutations', () => {
id: 2,
name: 'new test',
query: 'SELECT * from bar',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const state = {
@@ -85,18 +94,19 @@ describe('mutations', () => {
expect(state.tabs[0].id).to.equal(2)
expect(state.tabs[0].name).to.equal('new test')
expect(state.tabs[0].query).to.equal('SELECT * from bar')
expect(state.tabs[0].isUnsaved).to.equal(false)
expect(state.tabs[0].isSaved).to.equal(true)
expect(state.tabs[0].isPredefined).to.equal(undefined)
})
it('updateTab (rename)', () => {
it('updateTab - rename', () => {
const tab = {
id: 1,
name: 'test',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: true
viewType: 'chart',
viewOptions: {},
isSaved: false
}
const newTab = {
@@ -114,23 +124,24 @@ describe('mutations', () => {
expect(state.tabs[0].id).to.equal(1)
expect(state.tabs[0].name).to.equal('new test')
expect(state.tabs[0].query).to.equal('SELECT * from foo')
expect(state.tabs[0].isUnsaved).to.equal(true)
expect(state.tabs[0].isSaved).to.equal(false)
})
it('updateTab (changes detected)', () => {
it('updateTab - changes detected', () => {
const tab = {
id: 1,
name: 'test',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false,
viewType: 'chart',
viewOptions: {},
isSaved: true,
isPredefined: true
}
const newTab = {
index: 0,
isUnsaved: true
isSaved: false
}
const state = {
@@ -142,17 +153,18 @@ describe('mutations', () => {
expect(state.tabs[0].id).to.equal(1)
expect(state.tabs[0].name).to.equal('test')
expect(state.tabs[0].query).to.equal('SELECT * from foo')
expect(state.tabs[0].isUnsaved).to.equal(true)
expect(state.tabs[0].isSaved).to.equal(false)
})
it('deleteTab (opened, first)', () => {
it('deleteTab - opened, first', () => {
const tab1 = {
id: 1,
name: 'foo',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const tab2 = {
@@ -160,8 +172,9 @@ describe('mutations', () => {
name: 'bar',
tempName: null,
query: 'SELECT * from bar',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const state = {
@@ -175,14 +188,15 @@ describe('mutations', () => {
expect(state.currentTabId).to.equal(2)
})
it('deleteTab (opened, last)', () => {
it('deleteTab - opened, last', () => {
const tab1 = {
id: 1,
name: 'foo',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const tab2 = {
@@ -190,8 +204,9 @@ describe('mutations', () => {
name: 'bar',
tempName: null,
query: 'SELECT * from bar',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const state = {
@@ -205,14 +220,15 @@ describe('mutations', () => {
expect(state.currentTabId).to.equal(1)
})
it('deleteTab (opened, in the middle)', () => {
it('deleteTab - opened, in the middle', () => {
const tab1 = {
id: 1,
name: 'foo',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const tab2 = {
@@ -220,8 +236,9 @@ describe('mutations', () => {
name: 'bar',
tempName: null,
query: 'SELECT * from bar',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const tab3 = {
@@ -229,8 +246,9 @@ describe('mutations', () => {
name: 'foobar',
tempName: null,
query: 'SELECT * from foobar',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const state = {
@@ -245,14 +263,15 @@ describe('mutations', () => {
expect(state.currentTabId).to.equal(3)
})
it('deleteTab (opened, single)', () => {
it('deleteTab - opened, single', () => {
const tab1 = {
id: 1,
name: 'foo',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const state = {
@@ -265,14 +284,15 @@ describe('mutations', () => {
expect(state.currentTabId).to.equal(null)
})
it('deleteTab (not opened)', () => {
it('deleteTab - not opened', () => {
const tab1 = {
id: 1,
name: 'foo',
tempName: null,
query: 'SELECT * from foo',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const tab2 = {
@@ -280,8 +300,9 @@ describe('mutations', () => {
name: 'bar',
tempName: null,
query: 'SELECT * from bar',
chart: {},
isUnsaved: false
viewType: 'chart',
viewOptions: {},
isSaved: true
}
const state = {
@@ -313,44 +334,47 @@ describe('mutations', () => {
expect(state.currentTab).to.eql({ id: 2 })
})
it('updatePredefinedQueries (single)', () => {
const query = {
it('updatePredefinedInquiries - single', () => {
const inquiry = {
id: 1,
name: 'foo',
query: 'SELECT * FROM foo',
chart: {},
viewType: 'chart',
viewOptions: {},
createdAt: '2020-11-07T20:57:04.492Z'
}
const state = {
predefinedQueries: []
predefinedInquiries: []
}
updatePredefinedQueries(state, query)
expect(state.predefinedQueries).to.eql([query])
updatePredefinedInquiries(state, inquiry)
expect(state.predefinedInquiries).to.eql([inquiry])
})
it('updatePredefinedQueries (array)', () => {
const queries = [{
it('updatePredefinedInquiries - array', () => {
const inquiries = [{
id: 1,
name: 'foo',
query: 'SELECT * FROM foo',
chart: {},
viewType: 'chart',
viewOptions: {},
createdAt: '2020-11-07T20:57:04.492Z'
},
{
id: 2,
name: 'bar',
query: 'SELECT * FROM bar',
chart: {},
viewType: 'chart',
viewOptions: {},
createdAt: '2020-11-07T20:57:04.492Z'
}]
const state = {
predefinedQueries: []
predefinedInquiries: []
}
updatePredefinedQueries(state, queries)
expect(state.predefinedQueries).to.eql(queries)
updatePredefinedInquiries(state, inquiries)
expect(state.predefinedInquiries).to.eql(inquiries)
})
})

View File

@@ -3,6 +3,16 @@ import { mount } from '@vue/test-utils'
import tooltipMixin from '@/tooltipMixin'
describe('tooltipMixin.js', () => {
let container
beforeEach(() => {
container = document.createElement('div')
document.body.appendChild(container)
})
afterEach(() => {
container.remove()
})
it('tooltip is hidden in initial', () => {
const component = {
template: '<div :style="tooltipStyle"></div>',
@@ -12,13 +22,16 @@ describe('tooltipMixin.js', () => {
expect(wrapper.find('div').isVisible()).to.equal(false)
})
it('tooltipStyle is correct when showTooltip', async () => {
it('tooltipStyle is correct when showTooltip: top-right', async () => {
const component = {
template: '<div :style="tooltipStyle"></div>',
template: '<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>',
mixins: [tooltipMixin]
}
const wrapper = mount(component)
await wrapper.vm.showTooltip(new MouseEvent('mouseover', {
const wrapper = mount(component, { attachTo: container })
// by default top-right
await wrapper.vm.showTooltip(new MouseEvent('mouseenter', {
clientX: 10,
clientY: 20
}))
@@ -30,13 +43,73 @@ describe('tooltipMixin.js', () => {
expect(wrapper.find('div').isVisible()).to.equal(true)
})
it('tooltipStyle is correct when showTooltip: top-left', async () => {
const component = {
template: '<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>',
mixins: [tooltipMixin]
}
const wrapper = mount(component, { attachTo: container })
await wrapper.vm.showTooltip(new MouseEvent('mouseenter', {
clientX: 212,
clientY: 20
}), 'top-left')
expect(wrapper.vm.tooltipStyle).to.eql({
visibility: 'visible',
top: '8px',
left: '100px'
})
expect(wrapper.find('div').isVisible()).to.equal(true)
})
it('tooltipStyle is correct when showTooltip: bottom-right', async () => {
const component = {
template: '<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>',
mixins: [tooltipMixin]
}
const wrapper = mount(component, { attachTo: container })
await wrapper.vm.showTooltip(new MouseEvent('mouseenter', {
clientX: 10,
clientY: 20
}), 'bottom-right')
expect(wrapper.vm.tooltipStyle).to.eql({
visibility: 'visible',
top: '32px',
left: '22px'
})
expect(wrapper.find('div').isVisible()).to.equal(true)
})
it('tooltipStyle is correct when showTooltip: bottom-left', async () => {
const component = {
template: '<div :style="{...tooltipStyle, width: \'100px\'}" ref="tooltip"></div>',
mixins: [tooltipMixin]
}
const wrapper = mount(component, { attachTo: container })
await wrapper.vm.showTooltip(new MouseEvent('mouseenter', {
clientX: 212,
clientY: 20
}), 'bottom-left')
expect(wrapper.vm.tooltipStyle).to.eql({
visibility: 'visible',
top: '32px',
left: '100px'
})
expect(wrapper.find('div').isVisible()).to.equal(true)
})
it('tooltip is not visible after hideTooltip', async () => {
const component = {
template: '<div :style="tooltipStyle"></div>',
mixins: [tooltipMixin]
}
const wrapper = mount(component)
await wrapper.vm.showTooltip(new MouseEvent('mouseover', {
await wrapper.vm.showTooltip(new MouseEvent('mouseenter', {
clientX: 10,
clientY: 20
}))

View File

@@ -3,7 +3,7 @@ import sinon from 'sinon'
import { mount, shallowMount, createWrapper } from '@vue/test-utils'
import Vuex from 'vuex'
import MainMenu from '@/views/Main/MainMenu'
import storedQueries from '@/lib/storedQueries'
import storedInquiries from '@/lib/storedInquiries'
let wrapper = null
@@ -16,91 +16,63 @@ describe('MainMenu.vue', () => {
wrapper.destroy()
})
it('Run and Save are visible only on /editor page', async () => {
it('Create and Save are visible only on /workspace page', async () => {
const state = {
currentTab: { query: '', execute: sinon.stub() },
tabs: [{}],
db: {}
}
const store = new Vuex.Store({ state })
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
// mount the component
wrapper = shallowMount(MainMenu, {
store,
mocks: { $route },
stubs: ['router-link']
})
expect(wrapper.find('#run-btn').exists()).to.equal(true)
expect(wrapper.find('#run-btn').isVisible()).to.equal(true)
expect(wrapper.find('#save-btn').exists()).to.equal(true)
expect(wrapper.find('#save-btn').isVisible()).to.equal(true)
expect(wrapper.find('#create-btn').exists()).to.equal(true)
expect(wrapper.find('#create-btn').isVisible()).to.equal(true)
await wrapper.vm.$set(wrapper.vm.$route, 'path', '/my-queries')
expect(wrapper.find('#run-btn').exists()).to.equal(false)
await wrapper.vm.$set(wrapper.vm.$route, 'path', '/inquiries')
expect(wrapper.find('#save-btn').exists()).to.equal(true)
expect(wrapper.find('#save-btn').isVisible()).to.equal(false)
expect(wrapper.find('#create-btn').exists()).to.equal(true)
expect(wrapper.find('#create-btn').isVisible()).to.equal(true)
})
it('Run and Save are not visible if there is no tabs', () => {
it('Save is not visible if there is no tabs', () => {
const state = {
currentTab: null,
tabs: [{}],
db: {}
}
const store = new Vuex.Store({ state })
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
wrapper = shallowMount(MainMenu, {
store,
mocks: { $route },
stubs: ['router-link']
})
expect(wrapper.find('#run-btn').exists()).to.equal(false)
expect(wrapper.find('#save-btn').exists()).to.equal(true)
expect(wrapper.find('#save-btn').isVisible()).to.equal(false)
expect(wrapper.find('#create-btn').exists()).to.equal(true)
expect(wrapper.find('#create-btn').isVisible()).to.equal(true)
})
it('Run is disabled if there is no db or no query', async () => {
const state = {
currentTab: { query: 'SELECT * FROM foo', execute: sinon.stub() },
tabs: [{}],
db: null
}
const store = new Vuex.Store({ state })
const $route = { path: '/editor' }
wrapper = shallowMount(MainMenu, {
store,
mocks: { $route },
stubs: ['router-link']
})
const vm = wrapper.vm
expect(wrapper.find('#run-btn').element.disabled).to.equal(true)
await vm.$set(state, 'db', {})
expect(wrapper.find('#run-btn').element.disabled).to.equal(false)
await vm.$set(state.currentTab, 'query', '')
expect(wrapper.find('#run-btn').element.disabled).to.equal(true)
})
it('Save is disabled if current tab.isUnsaved is false', async () => {
it('Save is disabled if current tab.isSaved is true', async () => {
const state = {
currentTab: {
query: 'SELECT * FROM foo',
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ isUnsaved: true }],
tabs: [{ isSaved: false }],
db: {}
}
const store = new Vuex.Store({ state })
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
wrapper = shallowMount(MainMenu, {
store,
@@ -110,7 +82,7 @@ describe('MainMenu.vue', () => {
const vm = wrapper.vm
expect(wrapper.find('#save-btn').element.disabled).to.equal(false)
await vm.$set(state.tabs[0], 'isUnsaved', false)
await vm.$set(state.tabs[0], 'isSaved', true)
expect(wrapper.find('#save-btn').element.disabled).to.equal(true)
})
@@ -121,18 +93,18 @@ describe('MainMenu.vue', () => {
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ isUnsaved: true }],
tabs: [{ isSaved: false }],
db: {}
}
const newQueryId = 1
const newInquiryId = 1
const actions = {
addTab: sinon.stub().resolves(newQueryId)
addTab: sinon.stub().resolves(newInquiryId)
}
const mutations = {
setCurrentTabId: sinon.stub()
}
const store = new Vuex.Store({ state, mutations, actions })
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
const $router = { push: sinon.stub() }
wrapper = shallowMount(MainMenu, {
@@ -144,29 +116,29 @@ describe('MainMenu.vue', () => {
await wrapper.find('#create-btn').trigger('click')
expect(actions.addTab.calledOnce).to.equal(true)
await actions.addTab.returnValues[0]
expect(mutations.setCurrentTabId.calledOnceWith(state, newQueryId)).to.equal(true)
expect(mutations.setCurrentTabId.calledOnceWith(state, newInquiryId)).to.equal(true)
expect($router.push.calledOnce).to.equal(false)
})
it('Creates a tab and redirects to editor', async () => {
it('Creates a tab and redirects to workspace', async () => {
const state = {
currentTab: {
query: 'SELECT * FROM foo',
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ isUnsaved: true }],
tabs: [{ isSaved: false }],
db: {}
}
const newQueryId = 1
const newInquiryId = 1
const actions = {
addTab: sinon.stub().resolves(newQueryId)
addTab: sinon.stub().resolves(newInquiryId)
}
const mutations = {
setCurrentTabId: sinon.stub()
}
const store = new Vuex.Store({ state, mutations, actions })
const $route = { path: '/my-queries' }
const $route = { path: '/inquiries' }
const $router = { push: sinon.stub() }
wrapper = shallowMount(MainMenu, {
@@ -178,11 +150,11 @@ describe('MainMenu.vue', () => {
await wrapper.find('#create-btn').trigger('click')
expect(actions.addTab.calledOnce).to.equal(true)
await actions.addTab.returnValues[0]
expect(mutations.setCurrentTabId.calledOnceWith(state, newQueryId)).to.equal(true)
expect(mutations.setCurrentTabId.calledOnceWith(state, newInquiryId)).to.equal(true)
expect($router.push.calledOnce).to.equal(true)
})
it('Ctrl R calls currentTab.execute if running is enabled and route.path is "/editor"',
it('Ctrl R calls currentTab.execute if running is enabled and route.path is "/workspace"',
async () => {
const state = {
currentTab: {
@@ -190,11 +162,11 @@ describe('MainMenu.vue', () => {
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ isUnsaved: true }],
tabs: [{ isSaved: false }],
db: {}
}
const store = new Vuex.Store({ state })
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
const $router = { push: sinon.stub() }
wrapper = shallowMount(MainMenu, {
@@ -205,29 +177,29 @@ describe('MainMenu.vue', () => {
const ctrlR = new KeyboardEvent('keydown', { key: 'r', ctrlKey: true })
const metaR = new KeyboardEvent('keydown', { key: 'r', metaKey: true })
// Running is enabled and route path is editor
// Running is enabled and route path is workspace
document.dispatchEvent(ctrlR)
expect(state.currentTab.execute.calledOnce).to.equal(true)
document.dispatchEvent(metaR)
expect(state.currentTab.execute.calledTwice).to.equal(true)
// Running is disabled and route path is editor
// Running is disabled and route path is workspace
await wrapper.vm.$set(state, 'db', null)
document.dispatchEvent(ctrlR)
expect(state.currentTab.execute.calledTwice).to.equal(true)
document.dispatchEvent(metaR)
expect(state.currentTab.execute.calledTwice).to.equal(true)
// Running is enabled and route path is not editor
// Running is enabled and route path is not workspace
await wrapper.vm.$set(state, 'db', {})
await wrapper.vm.$set($route, 'path', '/my-queries')
await wrapper.vm.$set($route, 'path', '/inquiries')
document.dispatchEvent(ctrlR)
expect(state.currentTab.execute.calledTwice).to.equal(true)
document.dispatchEvent(metaR)
expect(state.currentTab.execute.calledTwice).to.equal(true)
})
it('Ctrl Enter calls currentTab.execute if running is enabled and route.path is "/editor"',
it('Ctrl Enter calls currentTab.execute if running is enabled and route.path is "/workspace"',
async () => {
const state = {
currentTab: {
@@ -235,11 +207,11 @@ describe('MainMenu.vue', () => {
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ isUnsaved: true }],
tabs: [{ isSaved: false }],
db: {}
}
const store = new Vuex.Store({ state })
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
const $router = { push: sinon.stub() }
wrapper = shallowMount(MainMenu, {
@@ -250,63 +222,63 @@ describe('MainMenu.vue', () => {
const ctrlEnter = new KeyboardEvent('keydown', { key: 'Enter', ctrlKey: true })
const metaEnter = new KeyboardEvent('keydown', { key: 'Enter', metaKey: true })
// Running is enabled and route path is editor
// Running is enabled and route path is workspace
document.dispatchEvent(ctrlEnter)
expect(state.currentTab.execute.calledOnce).to.equal(true)
document.dispatchEvent(metaEnter)
expect(state.currentTab.execute.calledTwice).to.equal(true)
// Running is disabled and route path is editor
// Running is disabled and route path is workspace
await wrapper.vm.$set(state, 'db', null)
document.dispatchEvent(ctrlEnter)
expect(state.currentTab.execute.calledTwice).to.equal(true)
document.dispatchEvent(metaEnter)
expect(state.currentTab.execute.calledTwice).to.equal(true)
// Running is enabled and route path is not editor
// Running is enabled and route path is not workspace
await wrapper.vm.$set(state, 'db', {})
await wrapper.vm.$set($route, 'path', '/my-queries')
await wrapper.vm.$set($route, 'path', '/inquiries')
document.dispatchEvent(ctrlEnter)
expect(state.currentTab.execute.calledTwice).to.equal(true)
document.dispatchEvent(metaEnter)
expect(state.currentTab.execute.calledTwice).to.equal(true)
})
it('Ctrl B calls createNewQuery', async () => {
it('Ctrl B calls createNewInquiry', async () => {
const state = {
currentTab: {
query: 'SELECT * FROM foo',
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ isUnsaved: true }],
tabs: [{ isSaved: false }],
db: {}
}
const store = new Vuex.Store({ state })
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
wrapper = shallowMount(MainMenu, {
store,
mocks: { $route },
stubs: ['router-link']
})
sinon.stub(wrapper.vm, 'createNewQuery')
sinon.stub(wrapper.vm, 'createNewInquiry')
const ctrlB = new KeyboardEvent('keydown', { key: 'b', ctrlKey: true })
const metaB = new KeyboardEvent('keydown', { key: 'b', metaKey: true })
document.dispatchEvent(ctrlB)
expect(wrapper.vm.createNewQuery.calledOnce).to.equal(true)
expect(wrapper.vm.createNewInquiry.calledOnce).to.equal(true)
document.dispatchEvent(metaB)
expect(wrapper.vm.createNewQuery.calledTwice).to.equal(true)
expect(wrapper.vm.createNewInquiry.calledTwice).to.equal(true)
await wrapper.vm.$set($route, 'path', '/my-queries')
await wrapper.vm.$set($route, 'path', '/inquiries')
document.dispatchEvent(ctrlB)
expect(wrapper.vm.createNewQuery.calledThrice).to.equal(true)
expect(wrapper.vm.createNewInquiry.calledThrice).to.equal(true)
document.dispatchEvent(metaB)
expect(wrapper.vm.createNewQuery.callCount).to.equal(4)
expect(wrapper.vm.createNewInquiry.callCount).to.equal(4)
})
it('Ctrl S calls checkQueryBeforeSave if the tab is unsaved and route path is /editor',
it('Ctrl S calls checkInquiryBeforeSave if the tab is unsaved and route path is /workspace',
async () => {
const state = {
currentTab: {
@@ -314,44 +286,44 @@ describe('MainMenu.vue', () => {
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ isUnsaved: true }],
tabs: [{ isSaved: false }],
db: {}
}
const store = new Vuex.Store({ state })
const $route = { path: '/editor' }
const $route = { path: '/workspace' }
wrapper = shallowMount(MainMenu, {
store,
mocks: { $route },
stubs: ['router-link']
})
sinon.stub(wrapper.vm, 'checkQueryBeforeSave')
sinon.stub(wrapper.vm, 'checkInquiryBeforeSave')
const ctrlS = new KeyboardEvent('keydown', { key: 's', ctrlKey: true })
const metaS = new KeyboardEvent('keydown', { key: 's', metaKey: true })
// tab is unsaved and route is /editor
// tab is unsaved and route is /workspace
document.dispatchEvent(ctrlS)
expect(wrapper.vm.checkQueryBeforeSave.calledOnce).to.equal(true)
expect(wrapper.vm.checkInquiryBeforeSave.calledOnce).to.equal(true)
document.dispatchEvent(metaS)
expect(wrapper.vm.checkQueryBeforeSave.calledTwice).to.equal(true)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true)
// tab is saved and route is /editor
await wrapper.vm.$set(state.tabs[0], 'isUnsaved', false)
// tab is saved and route is /workspace
await wrapper.vm.$set(state.tabs[0], 'isSaved', true)
document.dispatchEvent(ctrlS)
expect(wrapper.vm.checkQueryBeforeSave.calledTwice).to.equal(true)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true)
document.dispatchEvent(metaS)
expect(wrapper.vm.checkQueryBeforeSave.calledTwice).to.equal(true)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true)
// tab is unsaved and route is not /editor
await wrapper.vm.$set($route, 'path', '/my-queries')
await wrapper.vm.$set(state.tabs[0], 'isUnsaved', true)
// tab is unsaved and route is not /workspace
await wrapper.vm.$set($route, 'path', '/inquiries')
await wrapper.vm.$set(state.tabs[0], 'isSaved', false)
document.dispatchEvent(ctrlS)
expect(wrapper.vm.checkQueryBeforeSave.calledTwice).to.equal(true)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true)
document.dispatchEvent(metaS)
expect(wrapper.vm.checkQueryBeforeSave.calledTwice).to.equal(true)
expect(wrapper.vm.checkInquiryBeforeSave.calledTwice).to.equal(true)
})
it('Saves the query when no need the new name',
it('Saves the inquiry when no need the new name',
async () => {
const state = {
currentTab: {
@@ -359,20 +331,21 @@ describe('MainMenu.vue', () => {
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ id: 1, name: 'foo', isUnsaved: true }],
tabs: [{ id: 1, name: 'foo', isSaved: false }],
db: {}
}
const mutations = {
updateTab: sinon.stub()
}
const store = new Vuex.Store({ state, mutations })
const $route = { path: '/editor' }
sinon.stub(storedQueries, 'isTabNeedName').returns(false)
sinon.stub(storedQueries, 'save').returns({
const $route = { path: '/workspace' }
sinon.stub(storedInquiries, 'isTabNeedName').returns(false)
sinon.stub(storedInquiries, 'save').returns({
name: 'foo',
id: 1,
query: 'SELECT * FROM foo',
chart: []
viewType: 'chart',
viewOptions: []
})
wrapper = mount(MainMenu, {
@@ -386,8 +359,8 @@ describe('MainMenu.vue', () => {
// check that the dialog is closed
expect(wrapper.find('[data-modal="save"]').exists()).to.equal(false)
// check that the query was saved via storedQueries.save (newName='')
expect(storedQueries.save.calledOnceWith(state.currentTab, '')).to.equal(true)
// check that the inquiry was saved via storedInquiries.save (newName='')
expect(storedInquiries.save.calledOnceWith(state.currentTab, '')).to.equal(true)
// check that the tab was updated
expect(mutations.updateTab.calledOnceWith(state, sinon.match({
@@ -395,12 +368,13 @@ describe('MainMenu.vue', () => {
name: 'foo',
id: 1,
query: 'SELECT * FROM foo',
chart: [],
isUnsaved: false
viewType: 'chart',
viewOptions: [],
isSaved: true
}))).to.equal(true)
// check that 'querySaved' event was triggered on $root
expect(createWrapper(wrapper.vm.$root).emitted('querySaved')).to.have.lengthOf(1)
// check that 'inquirySaved' event was triggered on $root
expect(createWrapper(wrapper.vm.$root).emitted('inquirySaved')).to.have.lengthOf(1)
})
it('Shows en error when the new name is needed but not specifyied', async () => {
@@ -410,20 +384,21 @@ describe('MainMenu.vue', () => {
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ id: 1, name: null, tempName: 'Untitled', isUnsaved: true }],
tabs: [{ id: 1, name: null, tempName: 'Untitled', isSaved: false }],
db: {}
}
const mutations = {
updateTab: sinon.stub()
}
const store = new Vuex.Store({ state, mutations })
const $route = { path: '/editor' }
sinon.stub(storedQueries, 'isTabNeedName').returns(true)
sinon.stub(storedQueries, 'save').returns({
const $route = { path: '/workspace' }
sinon.stub(storedInquiries, 'isTabNeedName').returns(true)
sinon.stub(storedInquiries, 'save').returns({
name: 'foo',
id: 1,
query: 'SELECT * FROM foo',
chart: []
viewType: 'chart',
viewOptions: []
})
wrapper = mount(MainMenu, {
@@ -444,31 +419,32 @@ describe('MainMenu.vue', () => {
.trigger('click')
// check that we have an error message and dialog is still open
expect(wrapper.find('.text-field-error').text()).to.equal('Query name can\'t be empty')
expect(wrapper.find('.text-field-error').text()).to.equal('Inquiry name can\'t be empty')
expect(wrapper.find('[data-modal="save"]').exists()).to.equal(true)
})
it('Saves the query with a new name', async () => {
it('Saves the inquiry with a new name', async () => {
const state = {
currentTab: {
query: 'SELECT * FROM foo',
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ id: 1, name: null, tempName: 'Untitled', isUnsaved: true }],
tabs: [{ id: 1, name: null, tempName: 'Untitled', isSaved: false }],
db: {}
}
const mutations = {
updateTab: sinon.stub()
}
const store = new Vuex.Store({ state, mutations })
const $route = { path: '/editor' }
sinon.stub(storedQueries, 'isTabNeedName').returns(true)
sinon.stub(storedQueries, 'save').returns({
const $route = { path: '/workspace' }
sinon.stub(storedInquiries, 'isTabNeedName').returns(true)
sinon.stub(storedInquiries, 'save').returns({
name: 'foo',
id: 1,
query: 'SELECT * FROM foo',
chart: []
viewType: 'chart',
viewOptions: []
})
wrapper = mount(MainMenu, {
@@ -494,8 +470,8 @@ describe('MainMenu.vue', () => {
// check that the dialog is closed
expect(wrapper.find('[data-modal="save"]').exists()).to.equal(false)
// check that the query was saved via storedQueries.save (newName='foo')
expect(storedQueries.save.calledOnceWith(state.currentTab, 'foo')).to.equal(true)
// check that the inquiry was saved via storedInquiries.save (newName='foo')
expect(storedInquiries.save.calledOnceWith(state.currentTab, 'foo')).to.equal(true)
// check that the tab was updated
expect(mutations.updateTab.calledOnceWith(state, sinon.match({
@@ -503,15 +479,16 @@ describe('MainMenu.vue', () => {
name: 'foo',
id: 1,
query: 'SELECT * FROM foo',
chart: [],
isUnsaved: false
viewType: 'chart',
viewOptions: [],
isSaved: true
}))).to.equal(true)
// check that 'querySaved' event was triggered on $root
expect(createWrapper(wrapper.vm.$root).emitted('querySaved')).to.have.lengthOf(1)
// check that 'inquirySaved' event was triggered on $root
expect(createWrapper(wrapper.vm.$root).emitted('inquirySaved')).to.have.lengthOf(1)
})
it('Saves a predefined query with a new name', async () => {
it('Saves a predefined inquiry with a new name', async () => {
const state = {
currentTab: {
query: 'SELECT * FROM foo',
@@ -525,22 +502,24 @@ describe('MainMenu.vue', () => {
[2, 'Drako Malfoy']
]
},
view: 'chart'
viewType: 'chart',
viewOptions: []
},
tabs: [{ id: 1, name: 'foo', isUnsaved: true, isPredefined: true }],
tabs: [{ id: 1, name: 'foo', isSaved: false, isPredefined: true }],
db: {}
}
const mutations = {
updateTab: sinon.stub()
}
const store = new Vuex.Store({ state, mutations })
const $route = { path: '/editor' }
sinon.stub(storedQueries, 'isTabNeedName').returns(true)
sinon.stub(storedQueries, 'save').returns({
const $route = { path: '/workspace' }
sinon.stub(storedInquiries, 'isTabNeedName').returns(true)
sinon.stub(storedInquiries, 'save').returns({
name: 'bar',
id: 2,
query: 'SELECT * FROM foo',
chart: []
viewType: 'chart',
viewOptions: []
})
wrapper = mount(MainMenu, {
@@ -569,8 +548,8 @@ describe('MainMenu.vue', () => {
// check that the dialog is closed
expect(wrapper.find('[data-modal="save"]').exists()).to.equal(false)
// check that the query was saved via storedQueries.save (newName='bar')
expect(storedQueries.save.calledOnceWith(state.currentTab, 'bar')).to.equal(true)
// check that the inquiry was saved via storedInquiries.save (newName='bar')
expect(storedInquiries.save.calledOnceWith(state.currentTab, 'bar')).to.equal(true)
// check that the tab was updated
expect(mutations.updateTab.calledOnceWith(state, sinon.match({
@@ -578,18 +557,19 @@ describe('MainMenu.vue', () => {
name: 'bar',
id: 2,
query: 'SELECT * FROM foo',
chart: [],
isUnsaved: false
viewType: 'chart',
viewOptions: [],
isSaved: true
}))).to.equal(true)
// check that 'querySaved' event was triggered on $root
expect(createWrapper(wrapper.vm.$root).emitted('querySaved')).to.have.lengthOf(1)
// check that 'inquirySaved' event was triggered on $root
expect(createWrapper(wrapper.vm.$root).emitted('inquirySaved')).to.have.lengthOf(1)
// We saved predefined query, so the tab will be created again
// We saved predefined inquiry, so the tab will be created again
// (because of new id) and it will be without sql result and has default view - table.
// That's why we need to restore data and view.
// Check that result and view are preserved in the currentTab:
expect(state.currentTab.view).to.equal('chart')
expect(state.currentTab.viewType).to.equal('chart')
expect(state.currentTab.result).to.eql({
columns: ['id', 'name'],
values: [
@@ -606,16 +586,16 @@ describe('MainMenu.vue', () => {
execute: sinon.stub(),
tabIndex: 0
},
tabs: [{ id: 1, name: null, tempName: 'Untitled', isUnsaved: true }],
tabs: [{ id: 1, name: null, tempName: 'Untitled', isSaved: false }],
db: {}
}
const mutations = {
updateTab: sinon.stub()
}
const store = new Vuex.Store({ state, mutations })
const $route = { path: '/editor' }
sinon.stub(storedQueries, 'isTabNeedName').returns(true)
sinon.stub(storedQueries, 'save').returns({
const $route = { path: '/workspace' }
sinon.stub(storedInquiries, 'isTabNeedName').returns(true)
sinon.stub(storedInquiries, 'save').returns({
name: 'bar',
id: 2,
query: 'SELECT * FROM foo',
@@ -642,13 +622,13 @@ describe('MainMenu.vue', () => {
// check that the dialog is closed
expect(wrapper.find('[data-modal="save"]').exists()).to.equal(false)
// check that the query was not saved via storedQueries.save
expect(storedQueries.save.called).to.equal(false)
// check that the inquiry was not saved via storedInquiries.save
expect(storedInquiries.save.called).to.equal(false)
// check that the tab was not updated
expect(mutations.updateTab.called).to.equal(false)
// check that 'querySaved' event is not listened on $root
expect(wrapper.vm.$root.$listeners).to.not.have.property('querySaved')
// check that 'inquirySaved' event is not listened on $root
expect(wrapper.vm.$root.$listeners).to.not.have.property('inquirySaved')
})
})

View File

@@ -0,0 +1,23 @@
import { expect } from 'chai'
import { mount } from '@vue/test-utils'
import actions from '@/store/actions'
import Vuex from 'vuex'
import Workspace from '@/views/Main/Workspace'
describe('Workspace.vue', () => {
it('Creates a tab with example if schema is empty', () => {
const state = {
db: {},
tabs: []
}
const store = new Vuex.Store({ state, actions })
mount(Workspace, { store })
expect(state.tabs[0].query).to.include('Your database is empty.')
expect(state.tabs[0].tempName).to.equal('Untitled')
expect(state.tabs[0].name).to.equal(null)
expect(state.tabs[0].viewType).to.equal('chart')
expect(state.tabs[0].viewOptions).to.equal(undefined)
expect(state.tabs[0].isSaved).to.equal(false)
})
})

View File

@@ -2,8 +2,8 @@ import { expect } from 'chai'
import sinon from 'sinon'
import { mount, createLocalVue } from '@vue/test-utils'
import Vuex from 'vuex'
import Schema from '@/views/Main/Editor/Schema'
import TableDescription from '@/views/Main/Editor/Schema/TableDescription'
import Schema from '@/views/Main/Workspace/Schema'
import TableDescription from '@/views/Main/Workspace/Schema/TableDescription'
import database from '@/lib/database'
import fIo from '@/lib/utils/fileIo'
import csv from '@/components/CsvImport/csv'
@@ -129,10 +129,8 @@ describe('Schema.vue', () => {
sinon.stub(csv, 'parse').resolves({
delimiter: '|',
data: {
columns: ['col1', 'col2'],
values: [
[1, 'foo']
]
col1: [1],
col2: ['foo']
},
hasErrors: false,
messages: []
@@ -171,8 +169,8 @@ describe('Schema.vue', () => {
const res = await wrapper.vm.$store.state.db.execute('select * from test')
expect(res).to.eql({
columns: ['col1', 'col2'],
values: [[1, 'foo']]
col1: [1],
col2: ['foo']
})
})
})

View File

@@ -1,6 +1,6 @@
import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import TableDescription from '@/views/Main/Editor/Schema/TableDescription'
import TableDescription from '@/views/Main/Workspace/Schema/TableDescription'
describe('TableDescription.vue', () => {
it('Initially the columns are hidden and table name is rendered', () => {

View File

@@ -0,0 +1,50 @@
import { expect } from 'chai'
import sinon from 'sinon'
import { mount, shallowMount } from '@vue/test-utils'
import Chart from '@/views/Main/Workspace/Tabs/Tab/DataView/Chart'
import chartHelper from '@/views/Main/Workspace/Tabs/Tab/DataView/Chart/chartHelper'
import * as dereference from 'react-chart-editor/lib/lib/dereference'
describe('Chart.vue', () => {
afterEach(() => {
sinon.restore()
})
it('getOptionsForSave called with proper arguments', () => {
// mount the component
const wrapper = shallowMount(Chart)
const vm = wrapper.vm
const stub = sinon.stub(chartHelper, 'getOptionsForSave').returns('result')
const chartData = vm.getOptionsForSave()
expect(stub.calledOnceWith(vm.state, vm.dataSources)).to.equal(true)
expect(chartData).to.equal('result')
})
it('emits update when plotly updates', async () => {
// mount the component
const wrapper = mount(Chart)
wrapper.findComponent({ ref: 'plotlyEditor' }).vm.$emit('onUpdate')
expect(wrapper.emitted('update')).to.have.lengthOf(1)
})
it('calls dereference when sqlResult is changed', async () => {
sinon.stub(dereference, 'default')
const dataSources = {
id: [1],
name: ['foo']
}
// mount the component
const wrapper = shallowMount(Chart, {
propsData: { dataSources }
})
const newDataSources = {
id: [2],
name: ['bar']
}
await wrapper.setProps({ dataSources: newDataSources })
expect(dereference.default.called).to.equal(true)
})
})

View File

@@ -0,0 +1,32 @@
import { expect } from 'chai'
import { mount, createWrapper } from '@vue/test-utils'
import DataView from '@/views/Main/Workspace/Tabs/Tab/DataView'
import sinon from 'sinon'
describe('DataView.vue', () => {
it('emits update on mode changing', async () => {
const wrapper = mount(DataView)
const pivotBtn = createWrapper(wrapper.findComponent({ name: 'pivotIcon' }).vm.$parent)
await pivotBtn.trigger('click')
expect(wrapper.emitted('update')).to.have.lengthOf(1)
})
it('method getOptionsForSave call the same method of the current view component', async () => {
const wrapper = mount(DataView)
const chart = wrapper.findComponent({ name: 'Chart' }).vm
sinon.stub(chart, 'getOptionsForSave').returns({ here_are: 'chart_settings' })
expect(wrapper.vm.getOptionsForSave()).to.eql({ here_are: 'chart_settings' })
const pivotBtn = createWrapper(wrapper.findComponent({ name: 'pivotIcon' }).vm.$parent)
await pivotBtn.trigger('click')
const pivot = wrapper.findComponent({ name: 'pivot' }).vm
sinon.stub(pivot, 'getOptionsForSave').returns({ here_are: 'pivot_settings' })
expect(wrapper.vm.getOptionsForSave()).to.eql({ here_are: 'pivot_settings' })
})
})

View File

@@ -0,0 +1,214 @@
import { expect } from 'chai'
import { mount } from '@vue/test-utils'
import Pivot from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot'
import $ from 'jquery'
describe('Pivot.vue', () => {
it('renders pivot table', () => {
const wrapper = mount(Pivot, {
propsData: {
dataSources: {
item: ['foo', 'bar', 'bar', 'bar'],
year: [2021, 2021, 2020, 2020]
},
initOptions: {
rows: ['item'],
cols: ['year'],
colOrder: 'key_a_to_z',
rowOrder: 'key_a_to_z',
aggregatorName: 'Count',
vals: [],
rendererName: 'Table'
}
}
})
const colLabels = wrapper.findAll('.pivot-output thead th.pvtColLabel')
expect(colLabels.at(0).text()).to.equal('2020')
expect(colLabels.at(1).text()).to.equal('2021')
const rows = wrapper.findAll('.pivot-output tbody tr')
// row0: bar - 2 - 1
expect(rows.at(0).find('th').text()).to.equal('bar')
expect(rows.at(0).find('td.col0').text()).to.equal('2')
expect(rows.at(0).find('td.col1').text()).to.equal('1')
expect(rows.at(0).find('td.rowTotal').text()).to.equal('3')
// row1: foo - - 2
expect(rows.at(1).find('th').text()).to.equal('foo')
expect(rows.at(1).find('td.col0').text()).to.equal('')
expect(rows.at(1).find('td.col1').text()).to.equal('1')
expect(rows.at(1).find('td.rowTotal').text()).to.equal('1')
})
it('updates when dataSource changes', async () => {
const wrapper = mount(Pivot, {
propsData: {
dataSources: {
item: ['foo', 'bar', 'bar', 'bar'],
year: [2021, 2021, 2020, 2020]
},
initOptions: {
rows: ['item'],
cols: ['year'],
colOrder: 'key_a_to_z',
rowOrder: 'key_a_to_z',
aggregatorName: 'Count',
vals: [],
rendererName: 'Table'
}
}
})
await wrapper.setProps({
dataSources: {
item: ['foo', 'bar', 'bar', 'bar', 'foo', 'baz'],
year: [2021, 2021, 2020, 2020, 2021, 2020]
}
})
const colLabels = wrapper.findAll('.pivot-output thead th.pvtColLabel')
expect(colLabels.at(0).text()).to.equal('2020')
expect(colLabels.at(1).text()).to.equal('2021')
const rows = wrapper.findAll('.pivot-output tbody tr')
// row0: bar - 2 - 1
expect(rows.at(0).find('th').text()).to.equal('bar')
expect(rows.at(0).find('td.col0').text()).to.equal('2')
expect(rows.at(0).find('td.col1').text()).to.equal('1')
expect(rows.at(0).find('td.rowTotal').text()).to.equal('3')
// row1: baz - 1 -
expect(rows.at(1).find('th').text()).to.equal('baz')
expect(rows.at(1).find('td.col0').text()).to.equal('1')
expect(rows.at(1).find('td.col1').text()).to.equal('')
expect(rows.at(1).find('td.rowTotal').text()).to.equal('1')
// row2: foo - - 2
expect(rows.at(2).find('th').text()).to.equal('foo')
expect(rows.at(2).find('td.col0').text()).to.equal('')
expect(rows.at(2).find('td.col1').text()).to.equal('2')
expect(rows.at(2).find('td.rowTotal').text()).to.equal('2')
})
it('updates when pivot settings changes', async () => {
const wrapper = mount(Pivot, {
propsData: {
dataSources: {
item: ['foo', 'bar', 'bar', 'bar'],
year: [2021, 2021, 2020, 2020]
},
initOptions: {
rows: ['item'],
cols: ['year'],
colOrder: 'key_a_to_z',
rowOrder: 'key_a_to_z',
aggregatorName: 'Count',
vals: [],
rendererName: 'Table'
}
}
})
await wrapper.findComponent({ name: 'pivotUi' }).vm.$emit('input', {
rows: ['year'],
cols: ['item'],
colOrder: 'key_a_to_z',
rowOrder: 'key_a_to_z',
aggregator: $.pivotUtilities.aggregators.Count(),
aggregatorName: 'Count',
renderer: $.pivotUtilities.renderers.Table,
rendererName: 'Table',
rendererOptions: undefined,
vals: []
})
const colLabels = wrapper.findAll('.pivot-output thead th.pvtColLabel')
expect(colLabels.at(0).text()).to.equal('bar')
expect(colLabels.at(1).text()).to.equal('foo')
const rows = wrapper.findAll('.pivot-output tbody tr')
// row0: 2020 - 2 -
expect(rows.at(0).find('th').text()).to.equal('2020')
expect(rows.at(0).find('td.col0').text()).to.equal('2')
expect(rows.at(0).find('td.col1').text()).to.equal('')
expect(rows.at(0).find('td.rowTotal').text()).to.equal('2')
// row1: 2021 - 1 - 1
expect(rows.at(1).find('th').text()).to.equal('2021')
expect(rows.at(1).find('td.col0').text()).to.equal('1')
expect(rows.at(1).find('td.col1').text()).to.equal('1')
expect(rows.at(1).find('td.rowTotal').text()).to.equal('2')
})
it('returns options for save', async () => {
const wrapper = mount(Pivot, {
propsData: {
dataSources: {
item: ['foo', 'bar', 'bar', 'bar'],
year: [2021, 2021, 2020, 2020]
},
initOptions: {
rows: ['item'],
cols: ['year'],
colOrder: 'key_a_to_z',
rowOrder: 'key_a_to_z',
aggregatorName: 'Count',
vals: [],
rendererName: 'Table'
}
}
})
await wrapper.findComponent({ name: 'pivotUi' }).vm.$emit('input', {
rows: ['year'],
cols: ['item'],
colOrder: 'value_a_to_z',
rowOrder: 'value_z_to_a',
aggregator: $.pivotUtilities.aggregators.Count(),
aggregatorName: 'Count',
renderer: $.pivotUtilities.renderers.Table,
rendererName: 'Table',
rendererOptions: undefined,
vals: []
})
let optionsForSave = wrapper.vm.getOptionsForSave()
expect(optionsForSave.rows).to.eql(['year'])
expect(optionsForSave.cols).to.eql(['item'])
expect(optionsForSave.colOrder).to.equal('value_a_to_z')
expect(optionsForSave.rowOrder).to.equal('value_z_to_a')
expect(optionsForSave.aggregatorName).to.equal('Count')
expect(optionsForSave.rendererName).to.equal('Table')
expect(optionsForSave.rendererOptions).to.equal(undefined)
expect(optionsForSave.vals).to.eql([])
await wrapper.findComponent({ name: 'pivotUi' }).vm.$emit('input', {
rows: ['item'],
cols: ['year'],
colOrder: 'value_a_to_z',
rowOrder: 'value_z_to_a',
aggregator: $.pivotUtilities.aggregators.Count(),
aggregatorName: 'Count',
renderer: $.pivotUtilities.renderers['Custom chart'],
rendererName: 'Custom chart',
rendererOptions: {
customChartComponent: {
getOptionsForSave () {
return { here_are: 'custom chart settings' }
}
}
},
vals: []
})
optionsForSave = wrapper.vm.getOptionsForSave()
expect(optionsForSave.rows).to.eql(['item'])
expect(optionsForSave.cols).to.eql(['year'])
expect(optionsForSave.colOrder).to.equal('value_a_to_z')
expect(optionsForSave.rowOrder).to.equal('value_z_to_a')
expect(optionsForSave.aggregatorName).to.equal('Count')
expect(optionsForSave.rendererName).to.equal('Custom chart')
expect(optionsForSave.rendererOptions).to.eql({
customChartOptions: { here_are: 'custom chart settings' }
})
expect(optionsForSave.vals).to.eql([])
})
})

View File

@@ -0,0 +1,21 @@
import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import PivotSortBtn from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/PivotSortBtn'
describe('PivotSortBtn.vue', () => {
it('switches order', async () => {
const wrapper = shallowMount(PivotSortBtn, { propsData: { value: 'key_a_to_z' } })
expect(wrapper.vm.value).to.equal('key_a_to_z')
await wrapper.find('.pivot-sort-btn').trigger('click')
expect(wrapper.emitted('input')[0]).to.eql(['value_a_to_z'])
await wrapper.setProps({ value: 'value_a_to_z' })
await wrapper.find('.pivot-sort-btn').trigger('click')
expect(wrapper.emitted('input')[1]).to.eql(['value_z_to_a'])
await wrapper.setProps({ value: 'value_z_to_a' })
await wrapper.find('.pivot-sort-btn').trigger('click')
expect(wrapper.emitted('input')[2]).to.eql(['key_a_to_z'])
})
})

View File

@@ -0,0 +1,143 @@
import { expect } from 'chai'
import { mount } from '@vue/test-utils'
import PivotUi from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi'
describe('PivotUi.vue', () => {
it('returns value when settings changed', async () => {
const wrapper = mount(PivotUi, {
propsData: {
keyNames: ['foo', 'bar']
}
})
// choose columns
await wrapper.findAll('.sqliteviz-select.cols .multiselect__element > span').at(0)
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(1)
expect(wrapper.emitted().input[0][0].rows).to.eql([])
expect(wrapper.emitted().input[0][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[0][0].colOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[0][0].rowOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[0][0].aggregatorName).to.equal('Count')
expect(wrapper.emitted().input[0][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[0][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[0][0].vals).to.eql([])
// choose rows
await wrapper.findAll('.sqliteviz-select.rows .multiselect__element > span').at(0)
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(2)
expect(wrapper.emitted().input[1][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[1][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[1][0].colOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[1][0].rowOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[1][0].aggregatorName).to.equal('Count')
expect(wrapper.emitted().input[1][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[1][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[1][0].vals).to.eql([])
// change column order
await wrapper.find('.pivot-sort-btn.col').trigger('click')
expect(wrapper.emitted().update.length).to.equal(3)
expect(wrapper.emitted().input[2][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[2][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[2][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[2][0].rowOrder).to.equal('key_a_to_z')
expect(wrapper.emitted().input[2][0].aggregatorName).to.equal('Count')
expect(wrapper.emitted().input[2][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[2][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[2][0].vals).to.eql([])
// change row order
await wrapper.find('.pivot-sort-btn.row').trigger('click')
expect(wrapper.emitted().update.length).to.equal(4)
expect(wrapper.emitted().input[3][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[3][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[3][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[3][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[3][0].aggregatorName).to.equal('Count')
expect(wrapper.emitted().input[3][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[3][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[3][0].vals).to.eql([])
// change aggregator
await wrapper.findAll('.sqliteviz-select.aggregator .multiselect__element > span').at(12)
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(5)
expect(wrapper.emitted().input[4][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[4][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[4][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[4][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[4][0].aggregatorName).to.equal('Sum over Sum')
expect(wrapper.emitted().input[4][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[4][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[4][0].vals).to.eql(['', ''])
// set first aggregator argument
await wrapper
.findAll('.sqliteviz-select.aggr-arg').at(0)
.findAll('.multiselect__element > span').at(0)
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(6)
expect(wrapper.emitted().input[5][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[5][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[5][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[5][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[5][0].aggregatorName).to.equal('Sum over Sum')
expect(wrapper.emitted().input[5][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[5][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[5][0].vals).to.eql(['foo', ''])
// set second aggregator argument
await wrapper
.findAll('.sqliteviz-select.aggr-arg').at(1)
.findAll('.multiselect__element > span').at(1)
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(7)
expect(wrapper.emitted().input[6][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[6][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[6][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[6][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[6][0].aggregatorName).to.equal('Sum over Sum')
expect(wrapper.emitted().input[6][0].rendererName).to.equal('Table')
expect(wrapper.emitted().input[6][0].rendererOptions).to.equal(undefined)
expect(wrapper.emitted().input[6][0].vals).to.eql(['foo', 'bar'])
// change renderer
await wrapper.findAll('.sqliteviz-select.renderer .multiselect__element > span').at(13)
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(8)
expect(wrapper.emitted().input[7][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[7][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[7][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[7][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[7][0].aggregatorName).to.equal('Sum over Sum')
expect(wrapper.emitted().input[7][0].rendererName).to.equal('Custom chart')
expect(wrapper.emitted().input[7][0].rendererOptions.customChartComponent)
.to.not.equal(undefined)
expect(wrapper.emitted().input[7][0].vals).to.eql(['foo', 'bar'])
// change aggregator again
await wrapper.findAll('.sqliteviz-select.aggregator .multiselect__element > span').at(3)
.trigger('click')
expect(wrapper.emitted().update.length).to.equal(9)
expect(wrapper.emitted().input[8][0].rows).to.eql(['bar'])
expect(wrapper.emitted().input[8][0].cols).to.eql(['foo'])
expect(wrapper.emitted().input[8][0].colOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[8][0].rowOrder).to.equal('value_a_to_z')
expect(wrapper.emitted().input[8][0].aggregatorName).to.equal('Sum')
expect(wrapper.emitted().input[8][0].rendererName).to.equal('Custom chart')
expect(wrapper.emitted().input[8][0].rendererOptions.customChartComponent)
.to.not.equal(undefined)
expect(wrapper.emitted().input[8][0].vals).to.eql(['foo'])
})
})

View File

@@ -0,0 +1,56 @@
import { expect } from 'chai'
import { _getDataSources } from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/pivotHelper'
describe('pivotHelper.js', () => {
it('_getDataSources returns data sources', () => {
/*
+---+---+---------+---------+
| | x | 5 | 10 |
| +---+----+----+----+----+
| | z | 2 | 3 | 1 | 6 |
+---+---+ | | | |
| y | | | | | |
+---+---+----+----+----+----+
| 3 | 5 | 6 | 4 | 9 |
+-------+----+----+----+----+
| 6 | 8 | 9 | 7 | 12 |
+-------+----+----+----+----+
| 9 | 11 | 12 | 10 | 15 |
+-------+----+----+----+----+
*/
const pivotData = {
rowAttrs: ['y'],
colAttrs: ['x', 'z'],
getRowKeys () {
return [[3], [6], [9]]
},
getColKeys () {
return [
[5, 2],
[5, 3],
[10, 1],
[10, 6]
]
},
getAggregator (row, col) {
return {
value () {
return +row + +col[1]
}
}
}
}
expect(_getDataSources(pivotData)).to.eql({
'Column keys': ['5-2', '5-3', '10-1', '10-6'],
'Row keys': ['3', '6', '9'],
'x-z:5-2': [5, 8, 11],
'x-z:5-3': [6, 9, 12],
'x-z:10-1': [4, 7, 10],
'x-z:10-6': [9, 12, 15],
'y:3': [5, 6, 4, 9],
'y:6': [8, 9, 7, 12],
'y:9': [11, 12, 10, 15]
})
})
})

View File

@@ -1,6 +1,6 @@
import { expect } from 'chai'
import sinon from 'sinon'
import * as chartHelper from '@/views/Main/Editor/Tabs/Tab/Chart/chartHelper'
import * as chartHelper from '@/views/Main/Workspace/Tabs/Tab/DataView/Chart/chartHelper'
import * as dereference from 'react-chart-editor/lib/lib/dereference'
describe('chartHelper.js', () => {
@@ -8,22 +8,6 @@ describe('chartHelper.js', () => {
sinon.restore()
})
it('getDataSourcesFromSqlResult', () => {
const sqlResult = {
columns: ['id', 'name'],
values: [
[1, 'foo'],
[2, 'bar']
]
}
const ds = chartHelper.getDataSourcesFromSqlResult(sqlResult)
expect(ds).to.eql({
id: [1, 2],
name: ['foo', 'bar']
})
})
it('getOptionsFromDataSources', () => {
const dataSources = {
id: [1, 2],
@@ -37,7 +21,7 @@ describe('chartHelper.js', () => {
])
})
it('getChartStateForSave', () => {
it('getOptionsForSave', () => {
const state = {
data: {
foo: {},
@@ -53,7 +37,7 @@ describe('chartHelper.js', () => {
sinon.stub(dereference, 'default')
sinon.spy(JSON, 'parse')
const ds = chartHelper.getChartStateForSave(state, dataSources)
const ds = chartHelper.getOptionsForSave(state, dataSources)
expect(dereference.default.calledOnce).to.equal(true)

View File

@@ -0,0 +1,44 @@
import { expect } from 'chai'
import { mount } from '@vue/test-utils'
import Vuex from 'vuex'
import SqlEditor from '@/views/Main/Workspace/Tabs/Tab/SqlEditor'
describe('SqlEditor.vue', () => {
it('Emits input event when a query is changed', async () => {
// mock store state
const state = {
db: {}
}
const store = new Vuex.Store({ state })
const wrapper = mount(SqlEditor, { store })
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
expect(wrapper.emitted('input')[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 = new Vuex.Store({ state })
const wrapper = mount(SqlEditor, { store, propsData: { isGettingResults: false } })
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
const runButton = wrapper.findComponent({ name: 'RunIcon' }).vm.$parent
expect(runButton.disabled).to.equal(true)
await wrapper.vm.$set(store.state, 'db', {})
expect(runButton.disabled).to.equal(false)
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', '')
expect(runButton.disabled).to.equal(true)
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
expect(runButton.disabled).to.equal(false)
await wrapper.setProps({ isGettingResults: true })
expect(runButton.disabled).to.equal(true)
})
})

View File

@@ -1,7 +1,7 @@
import { expect } from 'chai'
import sinon from 'sinon'
import state from '@/store/state'
import showHint, { getHints } from '@/views/Main/Editor/Tabs/Tab/SqlEditor/hint'
import showHint, { getHints } from '@/views/Main/Workspace/Tabs/Tab/SqlEditor/hint'
import CM from 'codemirror'
describe('hint.js', () => {

View File

@@ -1,13 +1,21 @@
import { expect } from 'chai'
import sinon from 'sinon'
import { mount } from '@vue/test-utils'
import { mount, createWrapper } from '@vue/test-utils'
import mutations from '@/store/mutations'
import Vuex from 'vuex'
import Tab from '@/views/Main/Editor/Tabs/Tab'
import Tab from '@/views/Main/Workspace/Tabs/Tab'
let place
describe('Tab.vue', () => {
beforeEach(() => {
place = document.createElement('div')
document.body.appendChild(place)
})
afterEach(() => {
sinon.restore()
place.remove()
})
it('Renders passed query', () => {
@@ -19,21 +27,24 @@ describe('Tab.vue', () => {
// mount the component
const wrapper = mount(Tab, {
attachTo: place,
store,
stubs: ['chart'],
propsData: {
id: 1,
initName: 'foo',
initQuery: 'SELECT * FROM foo',
initChart: [],
initViewType: 'chart',
initViewOptions: [],
tabIndex: 0,
isPredefined: false
}
})
expect(wrapper.find('.tab-content-container').isVisible()).to.equal(true)
expect(wrapper.find('.table-view').isVisible()).to.equal(true)
expect(wrapper.find('.table-view .result-before').isVisible()).to.equal(true)
expect(wrapper.find('.query-editor').text()).to.equal('SELECT * FROM foo')
expect(wrapper.find('.bottomPane .run-result-panel').exists()).to.equal(true)
expect(wrapper.find('.run-result-panel .result-before').isVisible()).to.equal(true)
expect(wrapper.find('.above .sql-editor-panel .codemirror-container').text()).to.equal('SELECT * FROM foo')
})
it("Doesn't render tab when it's not active", () => {
@@ -54,29 +65,6 @@ describe('Tab.vue', () => {
expect(wrapper.find('.tab-content-container').isVisible()).to.equal(false)
})
it("Shows chart when view equals 'chart'", async () => {
// mock store state
const state = {
currentTabId: 1
}
const store = new Vuex.Store({ state, mutations })
// mount the component
const wrapper = mount(Tab, {
store,
stubs: ['chart'],
propsData: {
id: 1
}
})
expect(wrapper.findComponent({ ref: 'chart' }).vm.visible).to.equal(false)
await wrapper.setData({ view: 'chart' })
expect(wrapper.find('.table-view').isVisible()).to.equal(false)
expect(wrapper.findComponent({ ref: 'chart' }).vm.visible).to.equal(true)
})
it('Is not visible when not active', async () => {
// mock store state
const state = {
@@ -123,7 +111,7 @@ describe('Tab.vue', () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'SELECT * FROM foo', chart: [], isUnsaved: false }
{ id: 1, name: 'foo', query: 'SELECT * FROM foo', chart: [], isSaved: true }
],
currentTabId: 1
}
@@ -138,13 +126,14 @@ describe('Tab.vue', () => {
id: 1,
initName: 'foo',
initQuery: 'SELECT * FROM foo',
initChart: [],
initViewOptions: [],
initViewType: 'chart',
tabIndex: 0,
isPredefined: false
}
})
await wrapper.findComponent({ name: 'SqlEditor' }).vm.$emit('input', ' limit 100')
expect(state.tabs[0].isUnsaved).to.equal(true)
expect(state.tabs[0].isSaved).to.equal(false)
})
it('Shows .result-in-progress message when executing query', async () => {
@@ -165,7 +154,8 @@ describe('Tab.vue', () => {
id: 1,
initName: 'foo',
initQuery: 'SELECT * FROM foo',
initChart: [],
initViewOptions: [],
initViewType: 'chart',
tabIndex: 0,
isPredefined: false
}
@@ -173,8 +163,7 @@ describe('Tab.vue', () => {
wrapper.vm.execute()
await wrapper.vm.$nextTick()
expect(wrapper.find('.table-view .result-before').isVisible()).to.equal(false)
expect(wrapper.find('.table-view .result-in-progress').isVisible()).to.equal(true)
expect(wrapper.find('.run-result-panel .result-in-progress').isVisible()).to.equal(true)
})
it('Shows error when executing query ends with error', async () => {
@@ -196,26 +185,24 @@ describe('Tab.vue', () => {
id: 1,
initName: 'foo',
initQuery: 'SELECT * FROM foo',
initChart: [],
initViewOptions: [],
initViewType: 'chart',
tabIndex: 0,
isPredefined: false
}
})
await wrapper.vm.execute()
expect(wrapper.find('.table-view .result-before').isVisible()).to.equal(false)
expect(wrapper.find('.table-view .result-in-progress').exists()).to.equal(false)
expect(wrapper.find('.run-result-panel .result-before').isVisible()).to.equal(false)
expect(wrapper.find('.run-result-panel .result-in-progress').exists()).to.equal(false)
expect(wrapper.findComponent({ name: 'logs' }).isVisible()).to.equal(true)
expect(wrapper.findComponent({ name: 'logs' }).text()).to.include('There is no table foo')
})
it('Passes result to sql-table component', async () => {
const result = {
columns: ['id', 'name'],
values: [
[1, 'foo'],
[2, 'bar']
]
id: [1, 2],
name: ['foo', 'bar']
}
// mock store state
const state = {
@@ -236,23 +223,24 @@ describe('Tab.vue', () => {
id: 1,
initName: 'foo',
initQuery: 'SELECT * FROM foo',
initChart: [],
initViewOptions: [],
initViewType: 'chart',
tabIndex: 0,
isPredefined: false
}
})
await wrapper.vm.execute()
expect(wrapper.find('.table-view .result-before').isVisible()).to.equal(false)
expect(wrapper.find('.table-view .result-in-progress').exists()).to.equal(false)
expect(wrapper.find('.run-result-panel .result-before').isVisible()).to.equal(false)
expect(wrapper.find('.run-result-panel .result-in-progress').exists()).to.equal(false)
expect(wrapper.findComponent({ name: 'logs' }).exists()).to.equal(false)
expect(wrapper.findComponent({ name: 'SqlTable' }).vm.dataSet).to.eql(result)
})
it('Updates schema after query execution', async () => {
const result = {
columns: ['id', 'name'],
values: []
id: [],
name: []
}
// mock store state
@@ -275,7 +263,8 @@ describe('Tab.vue', () => {
id: 1,
initName: 'foo',
initQuery: 'SELECT * FROM foo; CREATE TABLE bar(a,b);',
initChart: [],
initViewOptions: [],
initViewType: 'chart',
tabIndex: 0,
isPredefined: false
}
@@ -284,4 +273,52 @@ describe('Tab.vue', () => {
await wrapper.vm.execute()
expect(state.db.refreshSchema.calledOnce).to.equal(true)
})
it('Switches views', async () => {
const state = {
currentTabId: 1,
db: {}
}
const store = new Vuex.Store({ state, mutations })
const wrapper = mount(Tab, {
attachTo: place,
store,
stubs: ['chart'],
propsData: {
id: 1,
initName: 'foo',
initQuery: 'SELECT * FROM foo; CREATE TABLE bar(a,b);',
initViewOptions: [],
initViewType: 'chart',
tabIndex: 0,
isPredefined: false
}
})
let tableBtn = createWrapper(wrapper.find('.above .side-tool-bar').findComponent({ name: 'tableIcon' }).vm.$parent)
await tableBtn.trigger('click')
expect(wrapper.find('.bottomPane .sql-editor-panel').exists()).to.equal(true)
expect(wrapper.find('.above .run-result-panel').exists()).to.equal(true)
const dataViewBtn = createWrapper(wrapper.find('.above .side-tool-bar').findComponent({ name: 'dataViewIcon' }).vm.$parent)
await dataViewBtn.trigger('click')
expect(wrapper.find('.bottomPane .sql-editor-panel').exists()).to.equal(true)
expect(wrapper.find('.above .data-view-panel').exists()).to.equal(true)
const sqlEditorBtn = createWrapper(wrapper.find('.above .side-tool-bar').findComponent({ name: 'sqlEditorIcon' }).vm.$parent)
await sqlEditorBtn.trigger('click')
expect(wrapper.find('.above .sql-editor-panel').exists()).to.equal(true)
expect(wrapper.find('.bottomPane .data-view-panel').exists()).to.equal(true)
tableBtn = createWrapper(wrapper.find('.bottomPane .side-tool-bar').findComponent({ name: 'tableIcon' }).vm.$parent)
await tableBtn.trigger('click')
expect(wrapper.find('.above .sql-editor-panel').exists()).to.equal(true)
expect(wrapper.find('.bottomPane .run-result-panel').exists()).to.equal(true)
})
})

View File

@@ -3,7 +3,7 @@ import sinon from 'sinon'
import { shallowMount, mount, createWrapper } from '@vue/test-utils'
import mutations from '@/store/mutations'
import Vuex from 'vuex'
import Tabs from '@/views/Main/Editor/Tabs'
import Tabs from '@/views/Main/Workspace/Tabs'
describe('Tabs.vue', () => {
afterEach(() => {
@@ -31,8 +31,8 @@ describe('Tabs.vue', () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isUnsaved: true }
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isSaved: true },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isSaved: false }
],
currentTabId: 2
}
@@ -65,8 +65,8 @@ describe('Tabs.vue', () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isUnsaved: true }
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isSaved: true },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isSaved: false }
],
currentTabId: 2
}
@@ -94,8 +94,8 @@ describe('Tabs.vue', () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isUnsaved: true }
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isSaved: true },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isSaved: false }
],
currentTabId: 2
}
@@ -125,8 +125,8 @@ describe('Tabs.vue', () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isUnsaved: true }
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isSaved: true },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isSaved: false }
],
currentTabId: 2
}
@@ -166,8 +166,8 @@ describe('Tabs.vue', () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isUnsaved: true }
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isSaved: true },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isSaved: false }
],
currentTabId: 2
}
@@ -199,9 +199,9 @@ describe('Tabs.vue', () => {
expect(firstTab.find('.star').isVisible()).to.equal(false)
expect(firstTab.classes()).to.include('tab-selected')
// check that 'saveQuery' event was not emited
// check that 'saveInquiry' event was not emited
const rootWrapper = createWrapper(wrapper.vm.$root)
expect(rootWrapper.emitted('saveQuery')).to.equal(undefined)
expect(rootWrapper.emitted('saveInquiry')).to.equal(undefined)
// check that the dialog is closed
expect(wrapper.find('[data-modal="close-warn"]').exists()).to.equal(false)
@@ -211,8 +211,8 @@ describe('Tabs.vue', () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isUnsaved: true }
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isSaved: true },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isSaved: false }
],
currentTabId: 2
}
@@ -237,8 +237,8 @@ describe('Tabs.vue', () => {
// click 'Save and close' in the dialog
await closeBtn.trigger('click')
// pretend like saving is completed - trigger 'querySaved' on $root
await wrapper.vm.$root.$emit('querySaved')
// pretend like saving is completed - trigger 'inquirySaved' on $root
await wrapper.vm.$root.$emit('inquirySaved')
// check that tab is closed
expect(wrapper.findAllComponents({ name: 'Tab' })).to.have.lengthOf(1)
@@ -247,20 +247,20 @@ describe('Tabs.vue', () => {
expect(firstTab.find('.star').isVisible()).to.equal(false)
expect(firstTab.classes()).to.include('tab-selected')
// check that 'saveQuery' event was emited
// check that 'saveInquiry' event was emited
const rootWrapper = createWrapper(wrapper.vm.$root)
expect(rootWrapper.emitted('saveQuery')).to.have.lengthOf(1)
expect(rootWrapper.emitted('saveInquiry')).to.have.lengthOf(1)
// check that the dialog is closed
expect(wrapper.find('[data-modal="close-warn"]').exists()).to.equal(false)
})
it('Prevents closing a tab of a browser if there is unsaved query', () => {
it('Prevents closing a tab of a browser if there is unsaved inquiry', () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isUnsaved: true }
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isSaved: true },
{ id: 2, name: null, tempName: 'Untitled', query: '', chart: [], isSaved: false }
],
currentTabId: 2
}
@@ -280,11 +280,11 @@ describe('Tabs.vue', () => {
expect(event.preventDefault.calledOnce).to.equal(true)
})
it("Doesn't prevent closing a tab of a browser if there is unsaved query", () => {
it("Doesn't prevent closing a tab of a browser if there is unsaved inquiry", () => {
// mock store state
const state = {
tabs: [
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false }
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isSaved: true }
],
currentTabId: 1
}

View File

@@ -1,68 +0,0 @@
import { expect } from 'chai'
import sinon from 'sinon'
import { mount, shallowMount } from '@vue/test-utils'
import Chart from '@/views/Main/Editor/Tabs/Tab/Chart'
import chartHelper from '@/views/Main/Editor/Tabs/Tab/Chart/chartHelper'
import * as dereference from 'react-chart-editor/lib/lib/dereference'
describe('Chart.vue', () => {
afterEach(() => {
sinon.restore()
})
it('getChartStateForSave called with proper arguments', () => {
// mount the component
const wrapper = shallowMount(Chart)
const vm = wrapper.vm
const stub = sinon.stub(chartHelper, 'getChartStateForSave').returns('result')
const chartData = vm.getChartStateForSave()
expect(stub.calledOnceWith(vm.state, vm.dataSources)).to.equal(true)
expect(chartData).to.equal('result')
})
it('is not visible when visible is false', () => {
// mount the component
const wrapper = shallowMount(Chart, {
propsData: { visible: false }
})
expect(wrapper.find('.chart-container').isVisible()).to.equal(false)
})
it('is visible when visible is true', () => {
// mount the component
const wrapper = shallowMount(Chart, {
propsData: { visible: true }
})
expect(wrapper.find('.chart-container').isVisible()).to.equal(true)
})
it('emits update when plotly updates', async () => {
// mount the component
const wrapper = mount(Chart)
wrapper.findComponent({ ref: 'plotlyEditor' }).vm.$emit('onUpdate')
expect(wrapper.emitted('update')).to.have.lengthOf(1)
})
it('calls dereference when sqlResult is changed', async () => {
sinon.stub(dereference, 'default')
const sqlResult = {
columns: ['id', 'name'],
values: [[1, 'foo']]
}
// mount the component
const wrapper = shallowMount(Chart, {
propsData: { sqlResult: sqlResult }
})
const newSqlResult = {
columns: ['id', 'name'],
values: [[2, 'bar']]
}
await wrapper.setProps({ sqlResult: newSqlResult })
expect(dereference.default.called).to.equal(true)
})
})

View File

@@ -1,11 +0,0 @@
import { expect } from 'chai'
import { mount } from '@vue/test-utils'
import SqlEditor from '@/views/Main/Editor/Tabs/Tab/SqlEditor'
describe('SqlEditor.vue', () => {
it('Emits input event when a query is changed', async () => {
const wrapper = mount(SqlEditor)
await wrapper.findComponent({ name: 'codemirror' }).vm.$emit('input', 'SELECT * FROM foo')
expect(wrapper.emitted('input')[0]).to.eql(['SELECT * FROM foo'])
})
})