1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2025-12-06 18:18:53 +08:00
Files
sqliteviz/tests/unit/chart.spec.js
2021-02-12 21:39:47 +01:00

66 lines
1.4 KiB
JavaScript

import { expect } from 'chai'
import sinon from 'sinon'
import * as chart from '@/chart'
import * as dereference from 'react-chart-editor/lib/lib/dereference'
describe('chart.js', () => {
it('getDataSourcesFromSqlResult', () => {
const sqlResult = {
columns: ['id', 'name'],
values: [
[1, 'foo'],
[2, 'bar']
]
}
const ds = chart.getDataSourcesFromSqlResult(sqlResult)
expect(ds).to.eql({
id: [1, 2],
name: ['foo', 'bar']
})
})
it('getOptionsFromDataSources', () => {
const dataSources = {
id: [1, 2],
name: ['foo', 'bar']
}
const ds = chart.getOptionsFromDataSources(dataSources)
expect(ds).to.eql([
{ value: 'id', label: 'id' },
{ value: 'name', label: 'name' }
])
})
it('getChartStateForSave', () => {
const state = {
data: {
foo: {},
bar: {}
},
layout: {},
frames: {}
}
const dataSources = {
id: [1, 2],
name: ['foo', 'bar']
}
sinon.stub(dereference, 'default')
const ds = chart.getChartStateForSave(state, dataSources)
expect(dereference.default.calledOnce).to.equal(true)
const args = dereference.default.firstCall.args
expect(args[0]).to.eql({
foo: {},
bar: {}
})
expect(args[1]).to.eql({
id: [],
name: []
})
})
})