1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2026-08-05 07:19:17 +08:00
This commit is contained in:
lana-k
2026-07-21 22:55:03 +02:00
parent 9838421d65
commit 6fbddb69bb
2 changed files with 238 additions and 24 deletions

View File

@@ -23,35 +23,54 @@ describe('chartHelper.js', () => {
it('getOptionsForSave', () => {
const state = {
data: {
foo: {},
bar: {}
},
layout: {},
data: [
{
foo: {},
bar: {},
selectedpoints: []
}
],
layout: { selections: [{}] },
frames: {}
}
const dataSources = {
id: [1, 2],
name: ['foo', 'bar']
}
sinon.stub(dereference, 'default')
const dereferenceArgs = []
sinon.stub(dereference, 'default').callsFake((data, emptySources) => {
dereferenceArgs[0] = JSON.stringify(data)
dereferenceArgs[1] = JSON.stringify(emptySources)
})
sinon.spy(JSON, 'parse')
const ds = chartHelper.getOptionsForSave(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: []
})
expect(dereferenceArgs[0]).to.eql(
JSON.stringify([
{
foo: {},
bar: {},
selectedpoints: []
}
])
)
expect(dereferenceArgs[1]).to.eql(
JSON.stringify({
id: [],
name: []
})
)
expect(ds).to.equal(JSON.parse.returnValues[0])
expect(ds.layout.selections).to.eql([])
expect(ds.data).to.eql([
{
foo: {},
bar: {}
}
])
})
it('getImageDataUrl returns dataUrl', async () => {
@@ -101,4 +120,32 @@ describe('chartHelper.js', () => {
'Plotly.newPlot(el, "plotly data", "plotly layout"'
)
})
it('getRowsByIndexFromDataSources', () => {
const dataSources = {
id: [1, 2, 3],
name: ['Harry', 'Draco', 'Ron'],
points: [10, null, 7]
}
const rows = chartHelper.getRowsByIndexFromDataSources(dataSources, [1, 2])
expect(rows).to.eql([
{ id: 2, name: 'Draco', points: null },
{ id: 3, name: 'Ron', points: 7 }
])
})
it('clearSelection', () => {
const layout = {
selections: [{}],
someLayoutField: 1
}
const data = [
{ selectedpoints: [], someField: 1 },
{ someField: 2 },
{ selectedpoints: [], someField: 3 }
]
chartHelper.clearSelection(data, layout)
expect(layout).to.eql({ selections: [], someLayoutField: 1 })
expect(data).to.eql([{ someField: 1 }, { someField: 2 }, { someField: 3 }])
})
})