1
0
mirror of https://github.com/lana-k/sqliteviz.git synced 2026-08-05 15:29:17 +08:00

Compare commits

...

11 Commits

Author SHA1 Message Date
lana-k
62786e7dda #139 tests 2026-07-23 23:14:17 +02:00
lana-k
6fbddb69bb #139 tests 2026-07-21 22:55:03 +02:00
lana-k
9838421d65 #139 view details of selected points 2026-07-20 21:37:24 +02:00
lana-k
686a09a8ce fix import 2026-07-12 21:56:29 +02:00
lana-k
4e9d1a785c 0.30.1 2026-07-12 17:19:37 +02:00
lana-k
2b6de12dc5 fix: show custom chart settings in pivot #138 2026-07-12 17:19:07 +02:00
lana-k
39d1604959 fix: save chart settings wihtout data #137 2026-07-12 17:18:41 +02:00
lana-k
053b8fbecb wip 2026-07-08 20:39:43 +02:00
lana-k
1043a03c96 fix plotly patch file 2026-07-05 19:38:03 +02:00
lana-k
b6ec71338b fix plotly warnings see issue 7809 2026-07-05 19:12:24 +02:00
lana-k
4bb6676648 selection view wip 2026-05-25 17:50:57 +02:00
16 changed files with 584 additions and 86 deletions

6
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "sqliteviz",
"version": "0.29.0",
"version": "0.30.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sqliteviz",
"version": "0.29.0",
"version": "0.30.0",
"hasInstallScript": true,
"license": "Apache-2.0",
"dependencies": {
@@ -24,7 +24,7 @@
"nanoid": "^3.1.12",
"papaparse": "^5.4.1",
"pivottable": "^2.23.0",
"plotly.js": "^2.35.2",
"plotly.js": "^2.35.3",
"promise-worker": "^2.0.1",
"react": "^16.14.0",
"react-chart-editor": "^0.46.1",

View File

@@ -1,6 +1,6 @@
{
"name": "sqliteviz",
"version": "0.30.0",
"version": "0.30.1",
"license": "Apache-2.0",
"private": true,
"type": "module",
@@ -28,7 +28,7 @@
"nanoid": "^3.1.12",
"papaparse": "^5.4.1",
"pivottable": "^2.23.0",
"plotly.js": "^2.35.2",
"plotly.js": "^2.35.3",
"promise-worker": "^2.0.1",
"react": "^16.14.0",
"react-chart-editor": "^0.46.1",

View File

@@ -0,0 +1,26 @@
diff --git a/node_modules/plotly.js/dist/plotly.js b/node_modules/plotly.js/dist/plotly.js
index 28f5612..5b9956d 100644
--- a/node_modules/plotly.js/dist/plotly.js
+++ b/node_modules/plotly.js/dist/plotly.js
@@ -34384,6 +34384,9 @@ var layoutUIControlPatterns = [{
pattern: /^(shapes|annotations)/,
attr: 'editrevision'
}, {
+ pattern: /^selections/,
+ attr: 'selectionrevision'
+},{
pattern: /^title\.text$/,
attr: 'editrevision'
}];
diff --git a/node_modules/plotly.js/src/plot_api/plot_api.js b/node_modules/plotly.js/src/plot_api/plot_api.js
index 75e98f5..5c38053 100644
--- a/node_modules/plotly.js/src/plot_api/plot_api.js
+++ b/node_modules/plotly.js/src/plot_api/plot_api.js
@@ -2394,6 +2394,7 @@ var layoutUIControlPatterns = [
{pattern: /^legend\.(x|y)$/, attr: 'editrevision'},
{pattern: /^(shapes|annotations)/, attr: 'editrevision'},
+ {pattern: /^selections/, attr: 'selectionrevision'},
{pattern: /^title\.text$/, attr: 'editrevision'}
];

View File

@@ -1,30 +1,45 @@
<template>
<div ref="chartContainer" class="chart-container">
<div class="chart-container">
<div v-show="!dataSources" class="warning data-view-warning">
There is no data to build a chart. Run your SQL query and make sure the
result is not empty.
</div>
<div
<splitpanes
:before="{ size: 70, max: 100 }"
:after="{ size: 30, max: 50, hidden: !showValueViewer }"
:default="{ before: 70, after: 30 }"
class="chart"
:style="{ height: !dataSources ? 'calc(100% - 40px)' : '100%' }"
>
<PlotlyEditor
ref="plotlyEditor"
:data="state.data"
:layout="state.layout"
:frames="state.frames"
:config="config"
:dataSources="dataSources"
:dataSourceOptions="dataSourceOptions"
:plotly="plotly"
:useResizeHandler="useResizeHandler"
:debug="true"
:advancedTraceTypeSelector="true"
:hideControls="!showViewSettings"
@update="update"
@render="onRender"
/>
</div>
<template #left-pane>
<div ref="chartContainer" :style="{ height: '100%' }">
<PlotlyEditor
ref="plotlyEditor"
:data="state.data"
:layout="state.layout"
:frames="state.frames"
:config="config"
:dataSources="dataSources"
:dataSourceOptions="dataSourceOptions"
:plotly="plotly"
:useResizeHandler="useResizeHandler"
:debug="true"
:advancedTraceTypeSelector="true"
:hideControls="!showViewSettings"
@update="update"
@render="onRender"
/>
</div>
</template>
<template v-if="showValueViewer" #right-pane>
<value-viewer
:empty="!selectedItems || selectedItems.length === 0"
emptyMessage="No points selected to view"
:value="JSON.stringify(selectedItems)"
defaultFormat="json"
/>
</template>
</splitpanes>
</div>
</template>
@@ -37,11 +52,16 @@ import chartHelper from '@/lib/chartHelper'
import * as dereference from 'react-chart-editor/lib/lib/dereference'
import fIo from '@/lib/utils/fileIo'
import events from '@/lib/utils/events'
import Splitpanes from '@/components/Common/Splitpanes'
import ValueViewer from '@/components/ValueViewer.vue'
import { nextTick } from 'vue'
export default {
name: 'Chart',
components: {
PlotlyEditor: applyPureReactInVue(ReactPlotlyEditorWithPlotRef)
PlotlyEditor: applyPureReactInVue(ReactPlotlyEditorWithPlotRef),
Splitpanes,
ValueViewer
},
props: {
dataSources: Object,
@@ -49,7 +69,8 @@ export default {
exportToPngEnabled: Boolean,
exportToSvgEnabled: Boolean,
forPivot: Boolean,
showViewSettings: Boolean
showViewSettings: Boolean,
showValueViewer: Boolean
},
emits: [
'update:exportToSvgEnabled',
@@ -60,18 +81,21 @@ export default {
data() {
return {
plotly,
state: this.initOptions || {
data: [],
layout: { autosize: true },
frames: []
},
state: this.initOptions
? JSON.parse(JSON.stringify(this.initOptions))
: {
data: [],
layout: { autosize: true },
frames: []
},
config: {
editable: true,
displaylogo: false,
modeBarButtonsToRemove: ['toImage']
},
resizeObserver: null,
useResizeHandler: this.$store.state.isWorkspaceVisible
useResizeHandler: this.$store.state.isWorkspaceVisible,
selectedItems: null
}
},
computed: {
@@ -81,6 +105,7 @@ export default {
},
watch: {
dataSources() {
chartHelper.clearSelection(this.state.data, this.state.layout)
// we need to update state.data in order to update the graph
// https://github.com/plotly/react-chart-editor/issues/948
if (this.dataSources) {
@@ -115,13 +140,27 @@ export default {
this.$emit('update:exportToSvgEnabled', true)
this.$emit('update:exportToHtmlEnabled', true)
},
mounted() {
async mounted() {
this.resizeObserver = new ResizeObserver(this.handleResize)
this.resizeObserver.observe(this.$refs.chartContainer)
if (this.dataSources) {
dereference.default(this.state.data, this.dataSources)
}
this.handleResize()
await nextTick()
const plotlyDiv =
this.$refs.plotlyEditor?.$el?.querySelector('.js-plotly-plot')
plotlyDiv?.on('plotly_selected', selectionEvent => {
if (selectionEvent) {
this.selectedItems = chartHelper.getRowsByIndexFromDataSources(
this.dataSources,
selectionEvent.points.map(point => point.pointIndex)
)
}
})
plotlyDiv?.on('plotly_deselect', () => {
this.selectedItems = null
})
},
activated() {
this.useResizeHandler = true
@@ -144,6 +183,8 @@ export default {
// TODO: check changes and enable Save button if needed
},
update(data, layout, frames) {
chartHelper.clearSelection(data, layout)
this.state = { data, layout, frames }
this.$emit('update')
},

View File

@@ -58,9 +58,9 @@
</icon-button>
<icon-button
v-if="mode === 'graph'"
ref="viewNodeOrEdgeBtn"
tooltip="View node or edge details"
v-if="mode !== 'pivot'"
ref="viewDetailsBtn"
tooltip="View details"
tooltipPosition="top-left"
:active="viewValuePanelVisible"
@click="viewValuePanelVisible = !viewValuePanelVisible"

View File

@@ -125,6 +125,13 @@ export default {
},
async checkFile(file) {
if (!file) {
alert(
'You should drop a file. ' +
'It can be an SQLite database, CSV file, JSON or NDJSON file.'
)
return
}
this.state = 'dropping'
this.newDb = database.getNewDatabase()

View File

@@ -227,7 +227,7 @@ export default {
events.send(eventName)
},
_keyListener(e) {
if (this.$route.path === '/workspace') {
if (this.$route.path === '/workspace' && this.currentInquiryTab) {
// Run query Ctrl+R or Ctrl+Enter
if ((e.key === 'r' || e.key === 'Enter') && (e.ctrlKey || e.metaKey)) {
e.preventDefault()

View File

@@ -19,6 +19,7 @@
<chart
ref="customChart"
v-bind="customChartComponentProps"
:showViewSettings="showViewSettings"
@update="$emit('update')"
@loading-image-completed="$emit('loadingImageCompleted')"
/>

View File

@@ -13,6 +13,27 @@ export function getOptionsFromDataSources(dataSources) {
}))
}
export function getRowsByIndexFromDataSources(dataSources, rowIndexes) {
if (!dataSources) {
return []
}
const dataSourceColumns = Object.keys(dataSources)
return rowIndexes.map(rowIndex =>
dataSourceColumns.reduce((result, columnName) => {
result[columnName] = dataSources[columnName][rowIndex]
return result
}, {})
)
}
export function clearSelection(data, layout) {
if (layout?.selections?.length > 0) {
layout.selections = []
data.forEach(dataItem => delete dataItem.selectedpoints)
}
}
export function getOptionsForSave(state, dataSources) {
// we don't need to save the data, only settings
// so we modify state.data using dereference
@@ -22,6 +43,9 @@ export function getOptionsForSave(state, dataSources) {
emptySources[key] = []
}
dereference.default(stateCopy.data, emptySources)
// Also, we don't need to save selections
clearSelection(stateCopy.data, stateCopy.layout)
return stateCopy
}
@@ -72,5 +96,7 @@ export default {
getOptionsForSave,
getImageDataUrl,
getHtml,
getChartData
getChartData,
getRowsByIndexFromDataSources,
clearSelection
}

View File

@@ -1,3 +1,5 @@
import { clearSelection } from '@/lib/chartHelper'
export default {
_migrate(installedVersion, inquiries) {
if (installedVersion < 2) {
@@ -28,6 +30,14 @@ export default {
})
}
if (installedVersion < 5) {
inquiries.forEach(inquiry => {
if (inquiry.viewType === 'chart') {
clearSelection(inquiry.viewOptions.data, inquiry.viewOptions.layout)
}
})
}
return inquiries
}
}

View File

@@ -5,7 +5,7 @@ import migration from './_migrations'
const migrate = migration._migrate
const myInquiriesKey = 'myInquiries'
const latestVersion = 4
const latestVersion = 5
export default {
version: latestVersion,

View File

@@ -429,37 +429,44 @@ describe('DataView.vue', () => {
}
})
// viewNodeOrEdgeBtn is not disaplyed in chart mode
expect(
wrapper.findComponent({ ref: 'viewNodeOrEdgeBtn' }).exists()
).to.equal(false)
// viewDetailsBtn is disaplyed in chart mode
expect(wrapper.findComponent({ ref: 'viewDetailsBtn' }).exists()).to.equal(
true
)
// Switch to pivot
const pivotBtn = wrapper.findComponent({ ref: 'pivotBtn' })
await pivotBtn.trigger('click')
// viewNodeOrEdgeBtn is not disaplyed in pivot mode
expect(
wrapper.findComponent({ ref: 'viewNodeOrEdgeBtn' }).exists()
).to.equal(false)
// viewDetailsBtn is not disaplyed in pivot mode
expect(wrapper.findComponent({ ref: 'viewDetailsBtn' }).exists()).to.equal(
false
)
// Switch to graph
const graphBtn = wrapper.findComponent({ ref: 'graphBtn' })
await graphBtn.trigger('click')
// viewNodeOrEdgeBtn is disaplyed in graph mode
const viewNodeOrEdgeBtn = wrapper.findComponent({
ref: 'viewNodeOrEdgeBtn'
// viewDetailsBtn is disaplyed in graph mode
const viewDetailsBtn = wrapper.findComponent({
ref: 'viewDetailsBtn'
})
expect(viewNodeOrEdgeBtn.exists()).to.equal(true)
expect(viewDetailsBtn.exists()).to.equal(true)
// by default node viewer is hidden
// by default details viewer is hidden
expect(wrapper.findComponent({ name: 'value-viewer' }).exists()).to.equal(
false
)
// Click to show node viewer
await viewNodeOrEdgeBtn.trigger('click')
// Click to show details viewer
await viewDetailsBtn.trigger('click')
expect(wrapper.findComponent({ name: 'value-viewer' }).exists()).to.equal(
true
)
// Switch to chart
const chartBtn = wrapper.findComponent({ ref: 'chartBtn' })
await chartBtn.trigger('click')
expect(wrapper.findComponent({ name: 'value-viewer' }).exists()).to.equal(
true
)

View File

@@ -210,8 +210,8 @@ describe('MainMenu.vue', () => {
isSaved: false
}
const state = {
currentTab: tab,
tabs: [tab],
currentTab: null,
tabs: [],
db: {}
}
const store = createStore({ state })
@@ -228,6 +228,17 @@ describe('MainMenu.vue', () => {
const ctrlR = new KeyboardEvent('keydown', { key: 'r', ctrlKey: true })
const metaR = new KeyboardEvent('keydown', { key: 'r', metaKey: true })
// execute is not called - no tabs open
document.dispatchEvent(ctrlR)
expect(tab.execute.calledOnce).to.equal(false)
document.dispatchEvent(metaR)
expect(tab.execute.calledOnce).to.equal(false)
// Open a tab
store.state.currentTab = tab
store.state.tabs = [tab]
// Running is enabled and route path is workspace
document.dispatchEvent(ctrlR)
expect(state.currentTab.execute.calledOnce).to.equal(true)
@@ -257,8 +268,8 @@ describe('MainMenu.vue', () => {
isSaved: false
}
const state = {
currentTab: tab,
tabs: [tab],
currentTab: null,
tabs: [],
db: {}
}
const store = createStore({ state })
@@ -281,6 +292,17 @@ describe('MainMenu.vue', () => {
key: 'Enter',
metaKey: true
})
// execute is not called - no tabs open
document.dispatchEvent(ctrlEnter)
expect(tab.execute.calledOnce).to.equal(false)
document.dispatchEvent(metaEnter)
expect(tab.execute.calledOnce).to.equal(false)
// Open a tab
store.state.currentTab = tab
store.state.tabs = [tab]
// Running is enabled and route path is workspace
document.dispatchEvent(ctrlEnter)
expect(state.currentTab.execute.calledOnce).to.equal(true)
@@ -347,8 +369,8 @@ describe('MainMenu.vue', () => {
isSaved: false
}
const state = {
currentTab: tab,
tabs: [tab],
currentTab: null,
tabs: [],
db: {}
}
const store = createStore({ state })
@@ -365,6 +387,17 @@ describe('MainMenu.vue', () => {
const ctrlS = new KeyboardEvent('keydown', { key: 's', ctrlKey: true })
const metaS = new KeyboardEvent('keydown', { key: 's', metaKey: true })
// onSave is not called - no tabs open
document.dispatchEvent(ctrlS)
expect(wrapper.vm.onSave.calledOnce).to.equal(false)
document.dispatchEvent(metaS)
expect(wrapper.vm.onSave.calledOnce).to.equal(false)
// Open a tab
store.state.currentTab = tab
store.state.tabs = [tab]
// tab is unsaved and route is /workspace
document.dispatchEvent(ctrlS)
expect(wrapper.vm.onSave.calledOnce).to.equal(true)
@@ -394,8 +427,8 @@ describe('MainMenu.vue', () => {
isSaved: false
}
const state = {
currentTab: tab,
tabs: [tab],
currentTab: null,
tabs: [],
db: {}
}
const store = createStore({ state })
@@ -420,6 +453,17 @@ describe('MainMenu.vue', () => {
metaKey: true,
shiftKey: true
})
// onSaveAs is not called - no tabs open
document.dispatchEvent(ctrlS)
expect(wrapper.vm.onSaveAs.calledOnce).to.equal(false)
document.dispatchEvent(metaS)
expect(wrapper.vm.onSaveAs.calledOnce).to.equal(false)
// Open a tab
store.state.currentTab = tab
store.state.tabs = [tab]
// tab is unsaved and route is /workspace
document.dispatchEvent(ctrlS)
expect(wrapper.vm.onSaveAs.calledOnce).to.equal(true)

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'
},
{

View File

@@ -0,0 +1,122 @@
import { expect } from 'chai'
import { mount, flushPromises } from '@vue/test-utils'
import actions from '@/store/actions'
import mutations from '@/store/mutations'
import { createStore } from 'vuex'
import MainView from '@/views/MainView.vue'
import { routes } from '@/router'
import { createRouter, createWebHistory } from 'vue-router'
describe('MainView.vue', () => {
it('Saves inquiry without data', async () => {
const state = {
db: {},
tabs: [],
inquiries: []
}
const store = createStore({ state, actions, mutations })
const router = createRouter({
history: createWebHistory(),
routes: routes
})
router.push('/workspace')
await router.isReady()
const wrapper = mount(MainView, {
global: {
stubs: {
'router-link': true,
teleport: false,
'app-diagnostic-info': true,
transition: false,
schema: true,
'run-result': true
},
plugins: [store, router]
},
attachTo: document.body
})
await wrapper.find('#create-btn').trigger('click')
store.state.tabs[1].result = {
columns: ['id', 'name'],
values: {
id: [1, 2],
name: ['Harry', 'Drako']
}
}
await flushPromises()
// Add trace
await wrapper
.findAllComponents({ name: 'Chart' })[1]
.find('button.js-add-button')
.wrapperElement.click()
await flushPromises()
// Select data for axis x
await wrapper
.findAll('.field .dropdown-container .Select__indicator')[0]
.wrapperElement.dispatchEvent(
new MouseEvent('mousedown', { bubbles: true })
)
await wrapper.findAll('.Select__menu .Select__option')[0].trigger('click')
// Select data for axis y
await wrapper
.findAll('.field .dropdown-container .Select__indicator')[2]
.wrapperElement.dispatchEvent(
new MouseEvent('mousedown', { bubbles: true })
)
await wrapper.findAll('.Select__menu .Select__option')[1].trigger('click')
// Click Save in the top menu
await wrapper.find('#save-btn').trigger('click')
// Input inquiry name
document.querySelector('.dialog input').value = 'test'
document.querySelector('.dialog input').dispatchEvent(
new InputEvent('input', {
data: 'test'
})
)
// Click Save in the dialog
document
.querySelector('.dialog .dialog-buttons-container button.primary')
.click()
const inquiriesInStore = store.state.inquiries
expect(inquiriesInStore.length).to.equal(1)
expect(inquiriesInStore[0].createdAt).to.not.be.null
expect(inquiriesInStore[0].createdAt).to.not.be.undefined
expect(inquiriesInStore[0].updateAt).to.not.be.null
expect(inquiriesInStore[0].updatedAt).to.not.be.undefined
expect(inquiriesInStore[0].id).to.not.be.null
expect(inquiriesInStore[0].id).to.not.be.undefined
expect(inquiriesInStore[0].name).to.equal('test')
expect(inquiriesInStore[0].viewType).to.equal('chart')
expect(inquiriesInStore[0].viewOptions.data).to.eql([
{
type: 'scatter',
mode: 'markers',
x: null,
xsrc: 'id',
meta: {
columnNames: {
x: 'id',
y: 'name'
}
},
y: null,
ysrc: 'name'
}
])
wrapper.unmount()
})
})