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 }])
})
})

View File

@@ -8,14 +8,22 @@ describe('_migrations.js', () => {
id: '123',
name: 'foo',
query: 'SELECT * FROM foo',
chart: { here_are: 'foo chart settings' },
chart: {
data: [{ selectedpoints: ['some selected points'] }, {}],
layout: { selections: [{}, {}] },
frames: 'foo chart frames'
},
createdAt: '2021-05-06T11:05:50.877Z'
},
{
id: '456',
name: 'bar',
query: 'SELECT * FROM bar',
chart: { here_are: 'bar chart settings' },
chart: {
data: [{}, {}],
layout: {},
frames: 'bar chart frames'
},
createdAt: '2021-05-07T11:05:50.877Z'
}
]
@@ -26,7 +34,11 @@ describe('_migrations.js', () => {
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: { here_are: 'foo chart settings' },
viewOptions: {
data: [{}, {}],
layout: { selections: [] },
frames: 'foo chart frames'
},
createdAt: '2021-05-06T11:05:50.877Z'
},
{
@@ -34,7 +46,7 @@ describe('_migrations.js', () => {
name: 'bar',
query: 'SELECT * FROM bar',
viewType: 'chart',
viewOptions: { here_are: 'bar chart settings' },
viewOptions: { data: [{}, {}], layout: {}, frames: 'bar chart frames' },
createdAt: '2021-05-07T11:05:50.877Z'
}
])
@@ -47,7 +59,11 @@ describe('_migrations.js', () => {
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: { here_are: 'foo chart settings' },
viewOptions: {
data: [{ selectedpoints: ['some selected points'] }, {}],
layout: { selections: [{}, {}] },
frames: 'foo chart frames'
},
createdAt: '2021-05-06T11:05:50.877Z'
},
{
@@ -108,7 +124,11 @@ describe('_migrations.js', () => {
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: { here_are: 'foo chart settings' },
viewOptions: {
data: [{}, {}],
layout: { selections: [] },
frames: 'foo chart frames'
},
createdAt: '2021-05-06T11:05:50.877Z'
},
{
@@ -175,7 +195,11 @@ describe('_migrations.js', () => {
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: { here_are: 'foo chart settings' },
viewOptions: {
data: [{ selectedpoints: ['some selected points'] }, {}],
layout: { selections: [{}, {}] },
frames: 'foo chart frames'
},
createdAt: '2021-05-06T11:05:50.877Z'
},
{
@@ -238,7 +262,150 @@ describe('_migrations.js', () => {
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: { here_are: 'foo chart settings' },
viewOptions: {
data: [{}, {}],
layout: { selections: [] },
frames: 'foo chart frames'
},
createdAt: '2021-05-06T11:05:50.877Z'
},
{
id: '456',
name: 'bar',
query: 'SELECT * FROM bar',
viewType: 'graph',
viewOptions: {
structure: {
nodeId: 'node_id',
objectType: 'object_type',
edgeSource: 'source',
edgeTarget: 'target'
},
style: {
backgroundColor: 'white',
highlightMode: 'node_and_neighbors',
nodes: {
size: { type: 'constant', value: 10 },
color: {
type: 'calculated',
method: 'degree',
colorscale: null,
mode: 'continious',
colorscaleDirection: 'reversed',
opacity: 100
},
label: { source: 'label', color: '#444444' }
},
edges: {
showDirection: true,
size: { type: 'constant', value: 2 },
color: { type: 'constant', value: '#a2b1c6' },
label: { source: null, color: '#a2b1c6' }
}
},
layout: {
type: 'forceAtlas2',
options: {
initialAlgorithm: 'circular',
initialIterationsAmount: 50,
adjustSizes: false,
barnesHutOptimize: false,
barnesHutTheta: 0.5,
edgeWeightInfluence: 0,
gravity: 1,
linLogMode: false,
outboundAttractionDistribution: false,
scalingRatio: 1,
slowDown: 1,
strongGravityMode: false
}
}
},
createdAt: '2021-05-07T11:05:50.877Z'
}
])
})
it('migrates from version 4 to the current', () => {
const oldInquiries = [
{
id: '123',
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: {
data: [{ selectedpoints: ['some selected points'] }, {}],
layout: { selections: [{}, {}] },
frames: 'foo chart frames'
},
createdAt: '2021-05-06T11:05:50.877Z'
},
{
id: '456',
name: 'bar',
query: 'SELECT * FROM bar',
viewType: 'graph',
viewOptions: {
structure: {
nodeId: 'node_id',
objectType: 'object_type',
edgeSource: 'source',
edgeTarget: 'target'
},
style: {
backgroundColor: 'white',
highlightMode: 'node_and_neighbors',
nodes: {
size: { type: 'constant', value: 10 },
color: {
type: 'calculated',
method: 'degree',
colorscale: null,
mode: 'continious',
colorscaleDirection: 'reversed',
opacity: 100
},
label: { source: 'label', color: '#444444' }
},
edges: {
showDirection: true,
size: { type: 'constant', value: 2 },
color: { type: 'constant', value: '#a2b1c6' },
label: { source: null, color: '#a2b1c6' }
}
},
layout: {
type: 'forceAtlas2',
options: {
initialAlgorithm: 'circular',
initialIterationsAmount: 50,
adjustSizes: false,
barnesHutOptimize: false,
barnesHutTheta: 0.5,
edgeWeightInfluence: 0,
gravity: 1,
linLogMode: false,
outboundAttractionDistribution: false,
scalingRatio: 1,
slowDown: 1,
strongGravityMode: false
}
}
},
createdAt: '2021-05-07T11:05:50.877Z'
}
]
expect(migrations._migrate(4, oldInquiries)).to.eql([
{
id: '123',
name: 'foo',
query: 'SELECT * FROM foo',
viewType: 'chart',
viewOptions: {
data: [{}, {}],
layout: { selections: [] },
frames: 'foo chart frames'
},
createdAt: '2021-05-06T11:05:50.877Z'
},
{