-
{{ query.name }}
+
{{ inquiry.name }}
Predefined
-
- Predefined queries come from the server.
- These queries can’t be deleted or renamed.
+
+ Predefined inquiries come from the server.
+ These inquiries can’t be deleted or renamed.
-
{{ query.createdAt | date }}
+
{{ inquiry.createdAt | date }}
-
-
+
+
@@ -99,15 +100,15 @@
-
+
Cancel
- Rename
+ Rename
-
+
{{ deleteDialogMsg }}
-
+
- Note: Predefined queries you've selected won't be deleted
+ Note: Predefined inquiries you've selected won't be deleted
Cancel
- Delete
+ Delete
@@ -149,11 +150,11 @@ import CloseIcon from '@/components/svg/close'
import TextField from '@/components/TextField'
import CheckBox from '@/components/CheckBox'
import tooltipMixin from '@/tooltipMixin'
-import storedQueries from '@/lib/storedQueries'
+import storedInquiries from '@/lib/storedInquiries'
import fu from '@/lib/utils/fileIo'
export default {
- name: 'MyQueries',
+ name: 'Inquiries',
components: {
RenameIcon,
CopyIcon,
@@ -166,13 +167,13 @@ export default {
mixins: [tooltipMixin],
data () {
return {
- queries: [],
+ inquiries: [],
filter: null,
newName: null,
- processedQueryId: null,
+ processedInquiryId: null,
errorMsg: null,
- selectedQueriesIds: new Set(),
- selectedQueriesCount: 0,
+ selectedInquiriesIds: new Set(),
+ selectedInquiriesCount: 0,
selectedNotPredefinedCount: 0,
selectAll: false,
deleteGroup: false,
@@ -181,61 +182,61 @@ export default {
}
},
computed: {
- predefinedQueries () {
- return this.$store.state.predefinedQueries.map(query => {
- query.isPredefined = true
- return query
+ predefinedInquiries () {
+ return this.$store.state.predefinedInquiries.map(inquiry => {
+ inquiry.isPredefined = true
+ return inquiry
})
},
- predefinedQueriesIds () {
- return new Set(this.predefinedQueries.map(query => query.id))
+ predefinedInquiriesIds () {
+ return new Set(this.predefinedInquiries.map(inquiry => inquiry.id))
},
- showedQueries () {
- let showedQueries = this.allQueries
+ showedInquiries () {
+ let showedInquiries = this.allInquiries
if (this.filter) {
- showedQueries = showedQueries.filter(
- query => query.name.toUpperCase().indexOf(this.filter.toUpperCase()) >= 0
+ showedInquiries = showedInquiries.filter(
+ inquiry => inquiry.name.toUpperCase().indexOf(this.filter.toUpperCase()) >= 0
)
}
- return showedQueries
+ return showedInquiries
},
- allQueries () {
- return this.predefinedQueries.concat(this.queries)
+ allInquiries () {
+ return this.predefinedInquiries.concat(this.inquiries)
},
- processedQueryIndex () {
- return this.queries.findIndex(query => query.id === this.processedQueryId)
+ processedInquiryIndex () {
+ return this.inquiries.findIndex(inquiry => inquiry.id === this.processedInquiryId)
},
deleteDialogMsg () {
if (!this.deleteGroup && (
- this.processedQueryIndex === null ||
- this.processedQueryIndex < 0 ||
- this.processedQueryIndex > this.queries.length
+ this.processedInquiryIndex === null ||
+ this.processedInquiryIndex < 0 ||
+ this.processedInquiryIndex > this.inquiries.length
)) {
return ''
}
const deleteItem = this.deleteGroup
? `${this.selectedNotPredefinedCount} ${this.selectedNotPredefinedCount > 1
- ? 'queries'
- : 'query'}`
- : `"${this.queries[this.processedQueryIndex].name}"`
+ ? 'inquiries'
+ : 'inquiry'}`
+ : `"${this.inquiries[this.processedInquiryIndex].name}"`
return `Are you sure you want to delete ${deleteItem}?`
}
},
created () {
- storedQueries.readPredefinedQueries()
- .then(queries => {
- this.$store.commit('updatePredefinedQueries', queries)
+ storedInquiries.readPredefinedInquiries()
+ .then(inquiries => {
+ this.$store.commit('updatePredefinedInquiries', inquiries)
})
.catch(console.error)
.finally(() => {
- this.queries = storedQueries.getStoredQueries()
+ this.inquiries = storedInquiries.getStoredInquiries()
})
},
mounted () {
this.resizeObserver = new ResizeObserver(this.calcMaxTableHeight)
- this.resizeObserver.observe(this.$refs['my-queries-content'])
+ this.resizeObserver.observe(this.$refs['my-inquiries-content'])
this.tableResizeObserver = new ResizeObserver(this.calcNameWidth)
this.tableResizeObserver.observe(this.$refs.table)
@@ -243,7 +244,7 @@ export default {
this.calcMaxTableHeight()
},
beforeDestroy () {
- this.resizeObserver.unobserve(this.$refs['my-queries-content'])
+ this.resizeObserver.unobserve(this.$refs['my-inquiries-content'])
this.tableResizeObserver.unobserve(this.$refs.table)
},
filters: {
@@ -269,153 +270,153 @@ export default {
this.$refs['name-th'].style = `width: ${nameWidth}px`
},
calcMaxTableHeight () {
- const freeSpace = this.$refs['my-queries-content'].offsetHeight - 200
+ const freeSpace = this.$refs['my-inquiries-content'].offsetHeight - 200
this.maxTableHeight = freeSpace - (freeSpace % 40) + 1
},
- openQuery (index) {
- const tab = this.showedQueries[index]
+ openInquiry (index) {
+ const tab = this.showedInquiries[index]
this.$store.dispatch('addTab', tab).then(id => {
this.$store.commit('setCurrentTabId', id)
- this.$router.push('/editor')
+ this.$router.push('/workspace')
})
},
showRenameDialog (id) {
this.errorMsg = null
- this.processedQueryId = id
- this.newName = this.queries[this.processedQueryIndex].name
+ this.processedInquiryId = id
+ this.newName = this.inquiries[this.processedInquiryIndex].name
this.$modal.show('rename')
},
- renameQuery () {
+ renameInquiry () {
if (!this.newName) {
- this.errorMsg = 'Query name can\'t be empty'
+ this.errorMsg = "Inquiry name can't be empty"
return
}
- const processedQuery = this.queries[this.processedQueryIndex]
- processedQuery.name = this.newName
- this.$set(this.queries, this.processedQueryIndex, processedQuery)
+ const processedInquiry = this.inquiries[this.processedInquiryIndex]
+ processedInquiry.name = this.newName
+ this.$set(this.inquiries, this.processedInquiryIndex, processedInquiry)
- // update queries in local storage
- storedQueries.updateStorage(this.queries)
+ // update inquiries in local storage
+ storedInquiries.updateStorage(this.inquiries)
- // update tab, if renamed query is opened
- const tabIndex = this.findTabIndex(processedQuery.id)
+ // update tab, if renamed inquiry is opened
+ const tabIndex = this.findTabIndex(processedInquiry.id)
if (tabIndex >= 0) {
this.$store.commit('updateTab', {
index: tabIndex,
name: this.newName,
- id: processedQuery.id
+ id: processedInquiry.id
})
}
// hide dialog
this.$modal.hide('rename')
},
- duplicateQuery (index) {
- const newQuery = storedQueries.duplicateQuery(this.showedQueries[index])
+ duplicateInquiry (index) {
+ const newInquiry = storedInquiries.duplicateInquiry(this.showedInquiries[index])
if (this.selectAll) {
- this.selectedQueriesIds.add(newQuery.id)
- this.selectedQueriesCount = this.selectedQueriesIds.size
+ this.selectedInquiriesIds.add(newInquiry.id)
+ this.selectedInquiriesCount = this.selectedInquiriesIds.size
}
- this.queries.push(newQuery)
- storedQueries.updateStorage(this.queries)
+ this.inquiries.push(newInquiry)
+ storedInquiries.updateStorage(this.inquiries)
},
showDeleteDialog (idsSet) {
this.deleteGroup = idsSet.size > 1
if (!this.deleteGroup) {
- this.processedQueryId = idsSet.values().next().value
+ this.processedInquiryId = idsSet.values().next().value
}
this.$modal.show('delete')
},
- deleteQuery () {
+ deleteInquiry () {
this.$modal.hide('delete')
if (!this.deleteGroup) {
- this.queries.splice(this.processedQueryIndex, 1)
+ this.inquiries.splice(this.processedInquiryIndex, 1)
- // Close deleted query tab if it was opened
- const tabIndex = this.findTabIndex(this.processedQueryId)
+ // Close deleted inquiry tab if it was opened
+ const tabIndex = this.findTabIndex(this.processedInquiryId)
if (tabIndex >= 0) {
this.$store.commit('deleteTab', tabIndex)
}
// Clear checkboxes
- if (this.selectedQueriesIds.has(this.processedQueryId)) {
- this.selectedQueriesIds.delete(this.processedQueryId)
+ if (this.selectedInquiriesIds.has(this.processedInquiryId)) {
+ this.selectedInquiriesIds.delete(this.processedInquiryId)
}
} else {
- this.queries = this.selectAll
+ this.inquiries = this.selectAll
? []
- : this.queries.filter(query => !this.selectedQueriesIds.has(query.id))
+ : this.inquiries.filter(inquiry => !this.selectedInquiriesIds.has(inquiry.id))
- // Close deleted queries if it was opened
+ // Close deleted inquiries if it was opened
const tabs = this.$store.state.tabs
for (let i = tabs.length - 1; i >= 0; i--) {
- if (this.selectedQueriesIds.has(tabs[i].id)) {
+ if (this.selectedInquiriesIds.has(tabs[i].id)) {
this.$store.commit('deleteTab', i)
}
}
// Clear checkboxes
- this.selectedQueriesIds.clear()
+ this.selectedInquiriesIds.clear()
}
- this.selectedQueriesCount = this.selectedQueriesIds.size
- storedQueries.updateStorage(this.queries)
+ this.selectedInquiriesCount = this.selectedInquiriesIds.size
+ storedInquiries.updateStorage(this.inquiries)
},
findTabIndex (id) {
return this.$store.state.tabs.findIndex(tab => tab.id === id)
},
- exportToFile (queryList, fileName) {
- const jsonStr = storedQueries.serialiseQueries(queryList)
+ exportToFile (inquiryList, fileName) {
+ const jsonStr = storedInquiries.serialiseInquiries(inquiryList)
fu.exportToFile(jsonStr, fileName)
},
- exportSelectedQueries () {
- const queryList = this.selectAll
- ? this.allQueries
- : this.allQueries.filter(query => this.selectedQueriesIds.has(query.id))
+ exportSelectedInquiries () {
+ const inquiryList = this.selectAll
+ ? this.allInquiries
+ : this.allInquiries.filter(inquiry => this.selectedInquiriesIds.has(inquiry.id))
- this.exportToFile(queryList, 'My sqliteviz queries.json')
+ this.exportToFile(inquiryList, 'My sqliteviz inquiries.json')
},
- importQueries () {
- storedQueries.importQueries()
- .then(importedQueries => {
+ importInquiries () {
+ storedInquiries.importInquiries()
+ .then(importedInquiries => {
if (this.selectAll) {
- importedQueries.forEach(query => {
- this.selectedQueriesIds.add(query.id)
+ importedInquiries.forEach(inquiry => {
+ this.selectedInquiriesIds.add(inquiry.id)
})
- this.selectedQueriesCount = this.selectedQueriesIds.size
+ this.selectedInquiriesCount = this.selectedInquiriesIds.size
}
- this.queries = this.queries.concat(importedQueries)
- storedQueries.updateStorage(this.queries)
+ this.inquiries = this.inquiries.concat(importedInquiries)
+ storedInquiries.updateStorage(this.inquiries)
})
},
toggleSelectAll (checked) {
this.selectAll = checked
this.$refs.rowCheckBox.forEach(item => { item.checked = checked })
- this.selectedQueriesIds = checked
- ? new Set(this.allQueries.map(query => query.id))
+ this.selectedInquiriesIds = checked
+ ? new Set(this.allInquiries.map(inquiry => inquiry.id))
: new Set()
- this.selectedQueriesCount = this.selectedQueriesIds.size
- this.selectedNotPredefinedCount = checked ? this.queries.length : 0
+ this.selectedInquiriesCount = this.selectedInquiriesIds.size
+ this.selectedNotPredefinedCount = checked ? this.inquiries.length : 0
},
toggleRow (checked, id) {
- const isPredefined = this.predefinedQueriesIds.has(id)
+ const isPredefined = this.predefinedInquiriesIds.has(id)
if (checked) {
- this.selectedQueriesIds.add(id)
+ this.selectedInquiriesIds.add(id)
if (!isPredefined) {
this.selectedNotPredefinedCount += 1
}
} else {
- if (this.selectedQueriesIds.size === this.allQueries.length) {
+ if (this.selectedInquiriesIds.size === this.allInquiries.length) {
this.$refs.mainCheckBox.checked = false
this.selectAll = false
}
- this.selectedQueriesIds.delete(id)
+ this.selectedInquiriesIds.delete(id)
if (!isPredefined) {
this.selectedNotPredefinedCount -= 1
}
}
- this.selectedQueriesCount = this.selectedQueriesIds.size
+ this.selectedInquiriesCount = this.selectedInquiriesIds.size
}
}
}
@@ -432,13 +433,13 @@ export default {
text-align: center;
}
-#my-queries-content {
+#my-inquiries-content {
padding: 52px;
height: 100%;
box-sizing: border-box;
}
-#my-queries-toolbar {
+#my-inquiries-toolbar {
display: flex;
justify-content: space-between;
margin-bottom: 18px;
@@ -465,47 +466,47 @@ export default {
margin-left: 24px;
}
-table {
+table.sqliteviz-table {
margin-top: 0;
}
-tbody tr td {
+.sqliteviz-table tbody tr td {
min-width: 0;
height: 40px;
}
-tbody tr td:first-child {
+.sqliteviz-table tbody tr td:first-child {
width: 70%;
max-width: 0;
padding: 0 12px;
}
-tbody tr td:last-child {
+.sqliteviz-table tbody tr td:last-child {
width: 30%;
max-width: 0;
padding: 0 24px;
}
-tbody .cell-data {
+.sqliteviz-table tbody .cell-data {
display: flex;
align-items: center;
max-width: 100%;
width: 100%;
}
-tbody .cell-data div.name {
+.sqliteviz-table tbody .cell-data div.name {
overflow: hidden;
text-overflow: ellipsis;
margin-left: 24px;
}
-tbody tr:hover td {
+.sqliteviz-table tbody tr:hover td {
cursor: pointer;
}
-tbody tr:hover td {
+.sqliteviz-table tbody tr:hover td {
color: var(--color-text-active);
}
-.second-column {
+.sqliteviz-table .second-column {
display: flex;
justify-content: space-between;
align-items: center;
@@ -523,7 +524,7 @@ tbody tr:hover td {
overflow: hidden;
text-overflow: ellipsis;
}
-tbody tr:hover .icons-container {
+.sqliteviz-table tbody tr:hover .icons-container {
display: flex;
}
.dialog input {
@@ -545,7 +546,7 @@ button.toolbar {
margin-left: 12px;
}
-tbody tr:hover .badge {
+.sqliteviz-table tbody tr:hover .badge {
display: block;
}
#note {
diff --git a/src/views/Main/MyQueries/svg/copy.vue b/src/views/Main/Inquiries/svg/copy.vue
similarity index 76%
rename from src/views/Main/MyQueries/svg/copy.vue
rename to src/views/Main/Inquiries/svg/copy.vue
index dfa8d71..808f2c0 100644
--- a/src/views/Main/MyQueries/svg/copy.vue
+++ b/src/views/Main/Inquiries/svg/copy.vue
@@ -6,18 +6,17 @@
height="18"
viewBox="0 0 18 18"
fill="none"
- xmlns="http://www.w3.org/2000/svg"
- @click.stop="$emit('click')"
- @mouseover="showTooltip"
- @mouseout="hideTooltip"
+ @click.stop="onClick"
+ @mouseenter="showTooltip"
+ @mouseleave="hideTooltip"
>
-
- Duplicate query
+
+ Duplicate inquiry
@@ -27,7 +26,13 @@ import tooltipMixin from '@/tooltipMixin'
export default {
name: 'CopyIcon',
- mixins: [tooltipMixin]
+ mixins: [tooltipMixin],
+ methods: {
+ onClick () {
+ this.hideTooltip()
+ this.$emit('click')
+ }
+ }
}
diff --git a/src/views/Main/MyQueries/svg/delete.vue b/src/views/Main/Inquiries/svg/delete.vue
similarity index 70%
rename from src/views/Main/MyQueries/svg/delete.vue
rename to src/views/Main/Inquiries/svg/delete.vue
index 785a00b..2d6270a 100644
--- a/src/views/Main/MyQueries/svg/delete.vue
+++ b/src/views/Main/Inquiries/svg/delete.vue
@@ -6,18 +6,17 @@
height="18"
viewBox="0 0 18 18"
fill="none"
- xmlns="http://www.w3.org/2000/svg"
- @click.stop="$emit('click')"
- @mouseover="showTooltip"
- @mouseout="hideTooltip"
+ @click.stop="onClick"
+ @mouseenter="showTooltip($event, 'top-left')"
+ @mouseleave="hideTooltip"
>
-
- Delete query
+
+ Delete inquiry
@@ -27,7 +26,13 @@ import tooltipMixin from '@/tooltipMixin'
export default {
name: 'DeleteIcon',
- mixins: [tooltipMixin]
+ mixins: [tooltipMixin],
+ methods: {
+ onClick () {
+ this.hideTooltip()
+ this.$emit('click')
+ }
+ }
}
diff --git a/src/views/Main/MyQueries/svg/rename.vue b/src/views/Main/Inquiries/svg/rename.vue
similarity index 72%
rename from src/views/Main/MyQueries/svg/rename.vue
rename to src/views/Main/Inquiries/svg/rename.vue
index e3795ec..99b70f7 100644
--- a/src/views/Main/MyQueries/svg/rename.vue
+++ b/src/views/Main/Inquiries/svg/rename.vue
@@ -6,18 +6,17 @@
height="18"
viewBox="0 0 18 18"
fill="none"
- xmlns="http://www.w3.org/2000/svg"
- @click.stop="$emit('click')"
- @mouseover="showTooltip"
- @mouseout="hideTooltip"
+ @click.stop="onClick"
+ @mouseenter="showTooltip"
+ @mouseleave="hideTooltip"
>
-
- Rename query
+
+ Rename inquiry
@@ -27,7 +26,13 @@ import tooltipMixin from '@/tooltipMixin'
export default {
name: 'RenameIcon',
- mixins: [tooltipMixin]
+ mixins: [tooltipMixin],
+ methods: {
+ onClick () {
+ this.hideTooltip()
+ this.$emit('click')
+ }
+ }
}
diff --git a/src/views/Main/MainMenu.vue b/src/views/Main/MainMenu.vue
index 1741a30..d8c491e 100644
--- a/src/views/Main/MainMenu.vue
+++ b/src/views/Main/MainMenu.vue
@@ -1,53 +1,44 @@
-
Editor
-
My queries
+
Workspace
+
Inquiries
Help
-
+
- Note: Predefined queries can't be edited.
- That's why your modifications will be saved as a new query. Enter the name for it.
+ Note: Predefined inquiries can't be edited.
+ That's why your modifications will be saved as a new inquiry. Enter the name for it.
Cancel
- Save
+ Save
@@ -64,7 +55,7 @@
+
+
diff --git a/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/PivotSortBtn.vue b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/PivotSortBtn.vue
new file mode 100644
index 0000000..5063dd9
--- /dev/null
+++ b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/PivotSortBtn.vue
@@ -0,0 +1,71 @@
+
+
+ {{ value.includes('key') ? 'key' : 'value' }}
+
+
+
+
+
+
+
diff --git a/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/index.vue b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/index.vue
new file mode 100644
index 0000000..98b6fd2
--- /dev/null
+++ b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/index.vue
@@ -0,0 +1,302 @@
+
+
+
+
+
Columns
+
+
+ No Results
+
+
+ Choose columns
+
+
+ No Results
+
+
+
+
+
+
+
Rows
+
+
+ No Results
+
+
+ Choose rows
+
+
+ No Results
+
+
+
+
+
+
+ Aggregator
+
+
+ No Results
+
+
+
+
+
+
+
+
+
+ View
+
+
+ No Results
+
+
+
+
+
+ {{ collapsed ? 'Show pivot settings' : 'Hide pivot settings' }}
+
+
+
+
+
+
diff --git a/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/pivotHelper.js b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/pivotHelper.js
new file mode 100644
index 0000000..d20d8f9
--- /dev/null
+++ b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi/pivotHelper.js
@@ -0,0 +1,77 @@
+import $ from 'jquery'
+import 'pivottable'
+import 'pivottable/dist/export_renderers.js'
+import 'pivottable/dist/plotly_renderers.js'
+
+export const zeroValAggregators = [
+ 'Count',
+ 'Count as Fraction of Total',
+ 'Count as Fraction of Rows',
+ 'Count as Fraction of Columns'
+]
+
+export const twoValAggregators = [
+ 'Sum over Sum',
+ '80% Upper Bound',
+ '80% Lower Bound'
+]
+
+export function _getDataSources (pivotData) {
+ const rowKeys = pivotData.getRowKeys()
+ const colKeys = pivotData.getColKeys()
+
+ const dataSources = {
+ 'Column keys': colKeys.map(colKey => colKey.join('-')),
+ 'Row keys': rowKeys.map(rowKey => rowKey.join('-'))
+ }
+
+ const dataSourcesByRows = {}
+ const dataSourcesByCols = {}
+
+ const rowAttrs = pivotData.rowAttrs.join('-')
+ const colAttrs = pivotData.colAttrs.join('-')
+
+ colKeys.forEach(colKey => {
+ const sourceColKey = colAttrs + ':' + colKey.join('-')
+ dataSourcesByCols[sourceColKey] = []
+ rowKeys.forEach(rowKey => {
+ const value = pivotData.getAggregator(rowKey, colKey).value()
+ dataSourcesByCols[sourceColKey].push(value)
+ const sourceRowKey = rowAttrs + ':' + rowKey.join('-')
+ if (!dataSourcesByRows[sourceRowKey]) {
+ dataSourcesByRows[sourceRowKey] = []
+ }
+ dataSourcesByRows[sourceRowKey].push(value)
+ })
+ })
+
+ return Object.assign(dataSources, dataSourcesByCols, dataSourcesByRows)
+}
+
+function customChartRenderer (data, options) {
+ options.customChartComponent.dataSources = _getDataSources(data)
+ options.customChartComponent.$mount()
+
+ return $(options.customChartComponent.$el)
+}
+
+$.extend(
+ $.pivotUtilities.renderers,
+ $.pivotUtilities.export_renderers,
+ $.pivotUtilities.plotly_renderers,
+ { 'Custom chart': customChartRenderer }
+)
+
+export const renderers = Object.keys($.pivotUtilities.renderers).map(key => {
+ return {
+ name: key,
+ fun: $.pivotUtilities.renderers[key]
+ }
+})
+
+export const aggregators = Object.keys($.pivotUtilities.aggregators).map(key => {
+ return {
+ name: key,
+ fun: $.pivotUtilities.aggregators[key]
+ }
+})
diff --git a/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/index.vue b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/index.vue
new file mode 100644
index 0000000..3e7e58c
--- /dev/null
+++ b/src/views/Main/Workspace/Tabs/Tab/DataView/Pivot/index.vue
@@ -0,0 +1,228 @@
+
+
+
+ There is no data to build a pivot. Run your SQL query and make sure the result is not empty.
+
+
+
+
+
+
+
+
+
diff --git a/src/views/Main/Workspace/Tabs/Tab/DataView/index.vue b/src/views/Main/Workspace/Tabs/Tab/DataView/index.vue
new file mode 100644
index 0000000..652a6df
--- /dev/null
+++ b/src/views/Main/Workspace/Tabs/Tab/DataView/index.vue
@@ -0,0 +1,118 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/views/Main/Workspace/Tabs/Tab/RunResult.vue b/src/views/Main/Workspace/Tabs/Tab/RunResult.vue
new file mode 100644
index 0000000..6b3c547
--- /dev/null
+++ b/src/views/Main/Workspace/Tabs/Tab/RunResult.vue
@@ -0,0 +1,130 @@
+
+
+
+
+ Run your query and get results here
+
+
+
+ Fetching results...
+
+
+ No rows retrieved according to your query
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/views/Main/Workspace/Tabs/Tab/SideToolBar.vue b/src/views/Main/Workspace/Tabs/Tab/SideToolBar.vue
new file mode 100644
index 0000000..211436a
--- /dev/null
+++ b/src/views/Main/Workspace/Tabs/Tab/SideToolBar.vue
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
diff --git a/src/views/Main/Editor/Tabs/Tab/SqlEditor/hint.js b/src/views/Main/Workspace/Tabs/Tab/SqlEditor/hint.js
similarity index 100%
rename from src/views/Main/Editor/Tabs/Tab/SqlEditor/hint.js
rename to src/views/Main/Workspace/Tabs/Tab/SqlEditor/hint.js
diff --git a/src/views/Main/Editor/Tabs/Tab/SqlEditor/index.vue b/src/views/Main/Workspace/Tabs/Tab/SqlEditor/index.vue
similarity index 51%
rename from src/views/Main/Editor/Tabs/Tab/SqlEditor/index.vue
rename to src/views/Main/Workspace/Tabs/Tab/SqlEditor/index.vue
index cbc2788..99cb4c4 100644
--- a/src/views/Main/Editor/Tabs/Tab/SqlEditor/index.vue
+++ b/src/views/Main/Workspace/Tabs/Tab/SqlEditor/index.vue
@@ -1,6 +1,24 @@
-
-
+
@@ -13,16 +31,23 @@ import 'codemirror/mode/sql/sql.js'
import 'codemirror/theme/neo.css'
import 'codemirror/addon/hint/show-hint.css'
import 'codemirror/addon/display/autorefresh.js'
+import SideToolBar from '../SideToolBar'
+import IconButton from '@/components/IconButton'
+import RunIcon from '@/components/svg/run'
export default {
name: 'SqlEditor',
- props: ['value'],
- components: { codemirror },
+ props: ['value', 'isGettingResults'],
+ components: {
+ codemirror,
+ SideToolBar,
+ IconButton,
+ RunIcon
+ },
data () {
return {
query: this.value,
cmOptions: {
- // codemirror options
tabSize: 4,
mode: 'text/x-mysql',
theme: 'neo',
@@ -33,6 +58,11 @@ export default {
}
}
},
+ computed: {
+ runDisabled () {
+ return (!this.$store.state.db || !this.query || this.isGettingResults)
+ }
+ },
watch: {
query () {
this.$emit('input', this.query)
@@ -48,9 +78,18 @@ export default {
diff --git a/src/views/Main/Editor/Tabs/index.vue b/src/views/Main/Workspace/Tabs/index.vue
similarity index 83%
rename from src/views/Main/Editor/Tabs/index.vue
rename to src/views/Main/Workspace/Tabs/index.vue
index f081332..ab7e53e 100644
--- a/src/views/Main/Editor/Tabs/index.vue
+++ b/src/views/Main/Workspace/Tabs/index.vue
@@ -8,7 +8,7 @@
:class="[{'tab-selected': (tab.id === selectedIndex)}, 'tab']"
>
- *
+ *
{{ tab.name }}
{{ tab.tempName }}
@@ -23,14 +23,15 @@
:id="tab.id"
:init-name="tab.name"
:init-query="tab.query"
- :init-chart="tab.chart"
+ :init-view-options="tab.viewOptions"
+ :init-view-type="tab.viewType"
:is-predefined="tab.isPredefined"
:tab-index="index"
/>
- Create
- a new query from scratch or open the one from
- My queries
+ Create
+ new inquiry from scratch or open one from
+ Inquiries
@@ -88,7 +89,7 @@ export default {
},
methods: {
leavingSqliteviz (event) {
- if (this.tabs.some(tab => tab.isUnsaved)) {
+ if (this.tabs.some(tab => !tab.isSaved)) {
event.preventDefault()
event.returnValue = ''
}
@@ -98,7 +99,7 @@ export default {
},
beforeCloseTab (index) {
this.closingTabIndex = index
- if (this.tabs[index].isUnsaved) {
+ if (!this.tabs[index].isSaved) {
this.$modal.show('close-warn')
} else {
this.closeTab(index)
@@ -110,14 +111,14 @@ export default {
this.$store.commit('deleteTab', index)
},
saveAndClose (index) {
- this.$root.$on('querySaved', () => {
+ this.$root.$on('inquirySaved', () => {
this.closeTab(index)
- this.$root.$off('querySaved')
+ this.$root.$off('inquirySaved')
})
this.selectTab(this.tabs[index].id)
this.$modal.hide('close-warn')
this.$nextTick(() => {
- this.$root.$emit('saveQuery')
+ this.$root.$emit('saveInquiry')
})
}
}
@@ -159,18 +160,29 @@ export default {
flex-shrink: 1;
}
-#tabs-header div:hover {
+#tabs-header .tab:hover {
cursor: pointer;
}
#tabs-header .tab-selected {
color: var(--color-text-active);
- font-weight: 600;
border-bottom: none;
background-color: var(--color-white);
+ position: relative;
}
-#tabs-header .tab-selected:hover {
- cursor: default;
+
+#tabs-header .tab-selected:after {
+ content: '';
+ width: 100%;
+ height: 4px;
+ background-color: var(--color-accent);
+ position: absolute;
+ left: 0;
+ bottom: 0;
+}
+
+#tabs-header .tab.tab-selected:hover {
+ cursor: default;
}
.close-icon {
diff --git a/src/views/Main/Editor/index.vue b/src/views/Main/Workspace/index.vue
similarity index 98%
rename from src/views/Main/Editor/index.vue
rename to src/views/Main/Workspace/index.vue
index dc5b023..ae1d98b 100644
--- a/src/views/Main/Editor/index.vue
+++ b/src/views/Main/Workspace/index.vue
@@ -21,7 +21,7 @@ import Schema from './Schema'
import Tabs from './Tabs'
export default {
- name: 'Editor',
+ name: 'Workspace',
components: {
Schema,
Splitpanes,
diff --git a/src/views/Main/index.vue b/src/views/Main/index.vue
index c62b2c5..fdcd5e8 100644
--- a/src/views/Main/index.vue
+++ b/src/views/Main/index.vue
@@ -1,7 +1,7 @@
-
+
diff --git a/src/views/Welcome.vue b/src/views/Welcome.vue
index 341ecc6..d00f0bd 100644
--- a/src/views/Welcome.vue
+++ b/src/views/Welcome.vue
@@ -4,7 +4,7 @@
Sqliteviz is fully client-side. Your database never leaves your computer.
-
+
Create empty database
diff --git a/tests/components/CsvImport/CsvImport.spec.js b/tests/components/CsvImport/CsvImport.spec.js
index 982597b..75722a2 100644
--- a/tests/components/CsvImport/CsvImport.spec.js
+++ b/tests/components/CsvImport/CsvImport.spec.js
@@ -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: []
})
diff --git a/tests/components/CsvImport/csv.spec.js b/tests/components/CsvImport/csv.spec.js
index 08a3373..43fcebd 100644
--- a/tests/components/CsvImport/csv.spec.js
+++ b/tests/components/CsvImport/csv.spec.js
@@ -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: [
{
diff --git a/tests/components/DbUploader.spec.js b/tests/components/DbUploader.spec.js
index e1c53cd..4bcf002 100644
--- a/tests/components/DbUploader.spec.js
+++ b/tests/components/DbUploader.spec.js
@@ -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, {
diff --git a/tests/components/Logs.spec.js b/tests/components/Logs.spec.js
index 6fa1f4e..144b487 100644
--- a/tests/components/Logs.spec.js
+++ b/tests/components/Logs.spec.js
@@ -8,6 +8,7 @@ describe('Logs.vue', () => {
place = document.createElement('div')
document.body.appendChild(place)
})
+
afterEach(() => {
place.remove()
})
diff --git a/tests/lib/database/_sql.spec.js b/tests/lib/database/_sql.spec.js
index 0bd2df7..e761452 100644
--- a/tests/lib/database/_sql.spec.js
+++ b/tests/lib/database/_sql.spec.js
@@ -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']
+ })
})
})
diff --git a/tests/lib/database/_statements.spec.js b/tests/lib/database/_statements.spec.js
index 9c64bf7..1d44633 100644
--- a/tests/lib/database/_statements.spec.js
+++ b/tests/lib/database/_statements.spec.js
@@ -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);'
)
})
diff --git a/tests/lib/database/database.spec.js b/tests/lib/database/database.spec.js
index c99e764..3f5b72c 100644
--- a/tests/lib/database/database.spec.js
+++ b/tests/lib/database/database.spec.js
@@ -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', () => {
diff --git a/tests/lib/database/sqliteExtensions.spec.js b/tests/lib/database/sqliteExtensions.spec.js
index 6f58b1e..e36db0a 100644
--- a/tests/lib/database/sqliteExtensions.spec.js
+++ b/tests/lib/database/sqliteExtensions.spec.js
@@ -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']
+ })
})
})
diff --git a/tests/lib/storedInquiries/_migrations.spec.js b/tests/lib/storedInquiries/_migrations.spec.js
new file mode 100644
index 0000000..1b0419d
--- /dev/null
+++ b/tests/lib/storedInquiries/_migrations.spec.js
@@ -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'
+ }
+ ])
+ })
+})
diff --git a/tests/lib/storedInquiries/storedInquiries.spec.js b/tests/lib/storedInquiries/storedInquiries.spec.js
new file mode 100644
index 0000000..75f3a62
--- /dev/null
+++ b/tests/lib/storedInquiries/storedInquiries.spec.js
@@ -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)
+ })
+})
diff --git a/tests/lib/storedQueries.spec.js b/tests/lib/storedQueries.spec.js
deleted file mode 100644
index 221111e..0000000
--- a/tests/lib/storedQueries.spec.js
+++ /dev/null
@@ -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)
- })
-})
diff --git a/tests/store/actions.spec.js b/tests/store/actions.spec.js
index 6e626fd..dc23d2d 100644
--- a/tests/store/actions.spec.js
+++ b/tests/store/actions.spec.js
@@ -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 = {
diff --git a/tests/store/mutations.spec.js b/tests/store/mutations.spec.js
index e61697c..cd4bb00 100644
--- a/tests/store/mutations.spec.js
+++ b/tests/store/mutations.spec.js
@@ -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)
})
})
diff --git a/tests/tooltipMixin.spec.js b/tests/tooltipMixin.spec.js
index 3854f27..49c623d 100644
--- a/tests/tooltipMixin.spec.js
+++ b/tests/tooltipMixin.spec.js
@@ -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: '
',
@@ -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: '
',
+ template: '
',
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: '
',
+ 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: '
',
+ 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: '
',
+ 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: '
',
mixins: [tooltipMixin]
}
const wrapper = mount(component)
- await wrapper.vm.showTooltip(new MouseEvent('mouseover', {
+ await wrapper.vm.showTooltip(new MouseEvent('mouseenter', {
clientX: 10,
clientY: 20
}))
diff --git a/tests/views/MainView/MyQueries/MyQueries.spec.js b/tests/views/Main/Inquiries/Inquiries.spec.js
similarity index 52%
rename from tests/views/MainView/MyQueries/MyQueries.spec.js
rename to tests/views/Main/Inquiries/Inquiries.spec.js
index 78bb427..c88f83e 100644
--- a/tests/views/MainView/MyQueries/MyQueries.spec.js
+++ b/tests/views/Main/Inquiries/Inquiries.spec.js
@@ -2,47 +2,68 @@ import { expect } from 'chai'
import sinon from 'sinon'
import { mount, shallowMount } from '@vue/test-utils'
import Vuex from 'vuex'
-import MyQueries from '@/views/Main/MyQueries'
-import storedQueries from '@/lib/storedQueries'
+import Inquiries from '@/views/Main/Inquiries'
+import storedInquiries from '@/lib/storedInquiries'
import mutations from '@/store/mutations'
import fu from '@/lib/utils/fileIo'
-describe('MyQueries.vue', () => {
+describe('Inquiries.vue', () => {
afterEach(() => {
sinon.restore()
})
- it('Shows start-guide message if there are no saved and predefined queries', () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- sinon.stub(storedQueries, 'getStoredQueries').returns([])
+ it('Shows start-guide message if there are no saved and predefined inquiries', () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const mutations = {
- updatePredefinedQueries: sinon.stub()
+ updatePredefinedInquiries: sinon.stub()
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = shallowMount(MyQueries, { store })
+ const wrapper = shallowMount(Inquiries, { store })
expect(wrapper.find('#start-guide').exists()).to.equal(true)
})
- it('Renders the list on saved or predefined queries', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([
- { id: 0, name: 'hello_world', query: '', chart: [], createdAt: '2020-03-08T19:57:56.299Z' }
+ it('Renders the list on saved or predefined inquiries', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([
+ {
+ id: 0,
+ name: 'hello_world',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-03-08T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'getStoredQueries').returns([
- { id: 1, name: 'foo', query: '', chart: [], createdAt: '2020-11-03T19:57:56.299Z' },
- { id: 2, name: 'bar', query: '', chart: [], createdAt: '2020-12-04T18:53:56.299Z' }
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([
+ {
+ id: 1,
+ name: 'foo',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-11-03T19:57:56.299Z'
+ },
+ {
+ id: 2,
+ name: 'bar',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-12-04T18:53:56.299Z'
+ }
])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = shallowMount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = shallowMount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
expect(wrapper.find('#start-guide').exists()).to.equal(false)
@@ -60,20 +81,41 @@ describe('MyQueries.vue', () => {
expect(rows.at(2).findAll('td').at(1).text()).to.equals('4 December 2020 19:53')
})
- it('Filters the list of queries', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([
- { id: 0, name: 'hello_world', query: '', chart: [], createdAt: '2020-03-08T19:57:56.299Z' }
+ it('Filters the list of inquiries', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([
+ {
+ id: 0,
+ name: 'hello_world',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-03-08T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'getStoredQueries').returns([
- { id: 1, name: 'foo', query: '', chart: [], createdAt: '2020-11-03T19:57:56.299Z' },
- { id: 2, name: 'bar', query: '', chart: [], createdAt: '2020-12-04T18:53:56.299Z' }
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([
+ {
+ id: 1,
+ name: 'foo',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-11-03T19:57:56.299Z'
+ },
+ {
+ id: 2,
+ name: 'bar',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-12-04T18:53:56.299Z'
+ }
])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
+ const wrapper = mount(Inquiries, { store })
await wrapper.find('#toolbar-search input').setValue('OO')
await wrapper.vm.$nextTick()
@@ -83,21 +125,35 @@ describe('MyQueries.vue', () => {
expect(rows.at(0).findAll('td').at(1).text()).to.contains('3 November 2020 20:57')
})
- it('Predefined query has a badge', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([
- { id: 0, name: 'hello_world', query: '', chart: [], createdAt: '2020-03-08T19:57:56.299Z' }
+ it('Predefined inquiry has a badge', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([
+ {
+ id: 0,
+ name: 'hello_world',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-03-08T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'getStoredQueries').returns([
- { id: 1, name: 'foo', query: '', chart: [], createdAt: '2020-11-03T19:57:56.299Z' }
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([
+ {
+ id: 1,
+ name: 'foo',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-11-03T19:57:56.299Z'
+ }
])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = shallowMount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = shallowMount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
const rows = wrapper.findAll('tbody tr')
@@ -105,94 +161,106 @@ describe('MyQueries.vue', () => {
expect(rows.at(1).find('td .badge').exists()).to.equals(false)
})
- it('Exports one query', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- sinon.stub(storedQueries, 'getStoredQueries').returns([
- { id: 1, name: 'foo', query: '', chart: [], createdAt: '2020-11-03T19:57:56.299Z' }
+ it('Exports one inquiry', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([
+ {
+ id: 1,
+ name: 'foo',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-11-03T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'serialiseQueries').returns('I am a serialized query')
+ sinon.stub(storedInquiries, 'serialiseInquiries').returns('I am a serialized inquiry')
sinon.stub(fu, 'exportToFile')
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
await wrapper.findComponent({ name: 'ExportIcon' }).find('svg').trigger('click')
- expect(fu.exportToFile.calledOnceWith('I am a serialized query', 'foo.json')).to.equals(true)
+ expect(fu.exportToFile.calledOnceWith('I am a serialized inquiry', 'foo.json')).to.equals(true)
})
- it('Duplicates a query', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- const queryInStorage = {
+ it('Duplicates an inquiry', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ const inquiryInStorage = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-11-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([queryInStorage])
- sinon.stub(storedQueries, 'updateStorage')
- const newQuery = {
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([inquiryInStorage])
+ sinon.stub(storedInquiries, 'updateStorage')
+ const newInquiry = {
id: 2,
name: 'foo copy',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-12-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'duplicateQuery').returns(newQuery)
+ sinon.stub(storedInquiries, 'duplicateInquiry').returns(newInquiry)
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
await wrapper.findComponent({ name: 'CopyIcon' }).find('svg').trigger('click')
- expect(storedQueries.duplicateQuery.calledOnceWith(queryInStorage)).to.equals(true)
+ expect(storedInquiries.duplicateInquiry.calledOnceWith(inquiryInStorage)).to.equals(true)
const rows = wrapper.findAll('tbody tr')
expect(rows).to.have.lengthOf(2)
expect(rows.at(1).findAll('td').at(0).text()).to.equals('foo copy')
expect(rows.at(1).findAll('td').at(1).text()).to.contains('3 December 2020 20:57')
- expect(storedQueries.updateStorage.calledOnceWith(sinon.match([queryInStorage, newQuery])))
- .to.equals(true)
+ expect(
+ storedInquiries.updateStorage.calledOnceWith(sinon.match([inquiryInStorage, newInquiry]))
+ ).to.equals(true)
})
- it('Makes the copy of the query selected if all queries were selected before duplication',
+ it('Makes the copy of the inquiry selected if all inquiries were selected before duplication',
async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- const queryInStorage = {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ const inquiryInStorage = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-11-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([queryInStorage])
- sinon.stub(storedQueries, 'updateStorage')
- const newQuery = {
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([inquiryInStorage])
+ sinon.stub(storedInquiries, 'updateStorage')
+ const newInquiry = {
id: 2,
name: 'foo copy',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-12-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'duplicateQuery').returns(newQuery)
+ sinon.stub(storedInquiries, 'duplicateInquiry').returns(newInquiry)
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
await wrapper.findComponent({ ref: 'mainCheckBox' }).find('.checkbox-container').trigger('click')
await wrapper.findComponent({ name: 'CopyIcon' }).find('svg').trigger('click')
@@ -202,74 +270,89 @@ describe('MyQueries.vue', () => {
expect(checkboxes.at(1).vm.checked).to.equals(true)
})
- it('Opens a query', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- const queryInStorage = {
+ it('Opens an inquiry', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ const inquiryInStorage = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-11-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([queryInStorage])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([inquiryInStorage])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const actions = { addTab: sinon.stub().resolves(1) }
sinon.spy(mutations, 'setCurrentTabId')
const $router = { push: sinon.stub() }
const store = new Vuex.Store({ state, mutations, actions })
- const wrapper = shallowMount(MyQueries, {
+ const wrapper = shallowMount(Inquiries, {
store,
mocks: { $router }
})
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
await wrapper.find('tbody tr').trigger('click')
expect(actions.addTab.calledOnce).to.equals(true)
- expect(actions.addTab.getCall(0).args[1]).to.equals(queryInStorage)
+ expect(actions.addTab.getCall(0).args[1]).to.equals(inquiryInStorage)
await actions.addTab.returnValues[0]
expect(mutations.setCurrentTabId.calledOnceWith(state, 1)).to.equals(true)
- expect($router.push.calledOnceWith('/editor')).to.equals(true)
+ expect($router.push.calledOnceWith('/workspace')).to.equals(true)
})
- it('Rename is not available for predefined queries', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([
- { id: 0, name: 'hello_world', query: '', chart: [], createdAt: '2020-03-08T19:57:56.299Z' }
+ it('Rename is not available for predefined inquiries', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([
+ {
+ id: 0,
+ name: 'hello_world',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-03-08T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'getStoredQueries').returns([])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
expect(wrapper.findComponent({ name: 'RenameIcon' }).exists()).to.equals(false)
})
- it('Renames a query', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- sinon.stub(storedQueries, 'getStoredQueries').returns([
- { id: 1, name: 'foo', query: '', chart: [], createdAt: '2020-11-03T19:57:56.299Z' }
+ it('Renames an inquiry', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([
+ {
+ id: 1,
+ name: 'foo',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-11-03T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'updateStorage')
+ sinon.stub(storedInquiries, 'updateStorage')
const state = {
tabs: [{ id: 1, name: 'foo' }],
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
// click Rename icon in the grid
@@ -278,7 +361,7 @@ describe('MyQueries.vue', () => {
// check that rename dialog is open
expect(wrapper.find('[data-modal="rename"]').exists()).to.equal(true)
- // check that input is filled by the current query name
+ // check that input is filled by the current inquiry name
expect(wrapper.find('.dialog-body input').element.value).to.equals('foo')
// change the name
@@ -294,11 +377,12 @@ describe('MyQueries.vue', () => {
expect(wrapper.find('tbody tr td').text()).to.equals('bar')
// check that storage is updated
- expect(storedQueries.updateStorage.calledOnceWith(sinon.match([{
+ expect(storedInquiries.updateStorage.calledOnceWith(sinon.match([{
id: 1,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-11-03T19:57:56.299Z'
}]))).to.equals(true)
@@ -310,20 +394,27 @@ describe('MyQueries.vue', () => {
})
it('Shows an error if try to rename to empty string', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- sinon.stub(storedQueries, 'getStoredQueries').returns([
- { id: 1, name: 'foo', query: '', chart: [], createdAt: '2020-11-03T19:57:56.299Z' }
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([
+ {
+ id: 1,
+ name: 'foo',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-11-03T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'updateStorage')
+ sinon.stub(storedInquiries, 'updateStorage')
const state = {
tabs: [{ id: 1, name: 'foo' }],
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
// click Rename icon in the grid
@@ -339,38 +430,40 @@ describe('MyQueries.vue', () => {
.trigger('click')
expect(wrapper.find('.dialog-body .text-field-error').text())
- .to.equals("Query name can't be empty")
+ .to.equals("Inquiry name can't be empty")
// check that rename dialog is still open
expect(wrapper.find('[data-modal="rename"]').exists()).to.equal(true)
})
- it('Imports queries', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- const queryInStorage = {
+ it('Imports inquiries', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ const inquiryInStorage = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-11-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([queryInStorage])
- sinon.stub(storedQueries, 'updateStorage')
- const importedQuery = {
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([inquiryInStorage])
+ sinon.stub(storedInquiries, 'updateStorage')
+ const importedInquiry = {
id: 2,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-12-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'importQueries').resolves([importedQuery])
+ sinon.stub(storedInquiries, 'importInquiries').resolves([importedInquiry])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = shallowMount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = shallowMount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
// click Import
@@ -380,38 +473,40 @@ describe('MyQueries.vue', () => {
expect(rows).to.have.lengthOf(2)
expect(rows.at(1).findAll('td').at(0).text()).to.equals('bar')
expect(rows.at(1).findAll('td').at(1).text()).to.equals('3 December 2020 20:57')
- expect(storedQueries.updateStorage.calledOnceWith(
- sinon.match([queryInStorage, importedQuery])
+ expect(storedInquiries.updateStorage.calledOnceWith(
+ sinon.match([inquiryInStorage, importedInquiry])
)).to.equals(true)
})
- it('Imported queries are selected if master check box is checked', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
- const queryInStorage = {
+ it('Imported inquiries are selected if master check box is checked', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
+ const inquiryInStorage = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-11-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([queryInStorage])
- sinon.stub(storedQueries, 'updateStorage')
- const importedQuery = {
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([inquiryInStorage])
+ sinon.stub(storedInquiries, 'updateStorage')
+ const importedInquiry = {
id: 2,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-12-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'importQueries').resolves([importedQuery])
+ sinon.stub(storedInquiries, 'importInquiries').resolves([importedInquiry])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
// click on master checkbox
@@ -425,52 +520,61 @@ describe('MyQueries.vue', () => {
expect(checkboxes.at(1).vm.checked).to.equals(true)
})
- it('Deletion is not available for predefined queries', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([
- { id: 0, name: 'hello_world', query: '', chart: [], createdAt: '2020-03-08T19:57:56.299Z' }
+ it('Deletion is not available for predefined inquiries', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([
+ {
+ id: 0,
+ name: 'hello_world',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-03-08T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'getStoredQueries').returns([])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
expect(wrapper.findComponent({ name: 'DeleteIcon' }).exists()).to.equals(false)
})
- it('Delete a query', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
+ it('Delete an inquiry', async () => {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
const foo = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-11-03T19:57:56.299Z'
}
const bar = {
id: 2,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-11-03T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([foo, bar])
- sinon.stub(storedQueries, 'updateStorage')
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([foo, bar])
+ sinon.stub(storedInquiries, 'updateStorage')
const state = {
tabs: [{ id: 1 }, { id: 2 }],
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
// click Delete icon in the first row of the grid
await wrapper.findComponent({ name: 'DeleteIcon' }).find('svg').trigger('click')
@@ -491,33 +595,47 @@ describe('MyQueries.vue', () => {
expect(wrapper.findAll('tbody tr')).to.have.lengthOf(1)
expect(wrapper.findAll('tbody tr').at(0).find('td').text()).to.equals('bar')
- // check that deleted query was also deleted from tabs
+ // check that deleted inquiry was also deleted from tabs
expect(state.tabs).to.have.lengthOf(1)
expect(state.tabs[0].id).to.equals(2)
// check that storage is updated
- expect(storedQueries.updateStorage.calledOnceWith(sinon.match([bar]))).to.equals(true)
+ expect(storedInquiries.updateStorage.calledOnceWith(sinon.match([bar]))).to.equals(true)
// check that delete dialog is closed
expect(wrapper.find('[data-modal="delete"]').exists()).to.equal(false)
})
it('Group operations are available when there are checked rows', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([
- { id: 0, name: 'hello_world', query: '', chart: [], createdAt: '2020-03-08T19:57:56.299Z' }
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([
+ {
+ id: 0,
+ name: 'hello_world',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-03-08T19:57:56.299Z'
+ }
])
- sinon.stub(storedQueries, 'getStoredQueries').returns([
- { id: 1, name: 'foo', query: '', chart: [], createdAt: '2020-11-03T19:57:56.299Z' }
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([
+ {
+ id: 1,
+ name: 'foo',
+ query: '',
+ viewType: 'chart',
+ viewOptions: [],
+ createdAt: '2020-11-03T19:57:56.299Z'
+ }
])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
expect(wrapper.find('#toolbar-btns-export').isVisible()).to.equal(false)
@@ -525,105 +643,110 @@ describe('MyQueries.vue', () => {
const rows = wrapper.findAll('tbody tr')
- // Select a predefined query
+ // Select a predefined inquiry
await rows.at(0).find('.checkbox-container').trigger('click')
expect(wrapper.find('#toolbar-btns-export').isVisible()).to.equal(true)
expect(wrapper.find('#toolbar-btns-delete').isVisible()).to.equal(false)
- // Select also not predefined query
+ // Select also not predefined inquiry
await rows.at(1).find('.checkbox-container').trigger('click')
expect(wrapper.find('#toolbar-btns-export').isVisible()).to.equal(true)
expect(wrapper.find('#toolbar-btns-delete').isVisible()).to.equal(true)
- // Uncheck a predefined query
+ // Uncheck a predefined inquiry
await rows.at(0).find('.checkbox-container').trigger('click')
expect(wrapper.find('#toolbar-btns-export').isVisible()).to.equal(true)
expect(wrapper.find('#toolbar-btns-delete').isVisible()).to.equal(true)
})
- it('Exports a group of queries', async () => {
- const predefinedQuery = {
+ it('Exports a group of inquiries', async () => {
+ const predefinedInquiry = {
id: 0,
name: 'hello_world',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([predefinedQuery])
- const queryInStore = {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([predefinedInquiry])
+ const inquiryInStore = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([queryInStore, {
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([inquiryInStore, {
id: 2,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}])
- sinon.stub(storedQueries, 'serialiseQueries').returns('I am a serialized queries')
+ sinon.stub(storedInquiries, 'serialiseInquiries').returns('I am a serialized inquiries')
sinon.stub(fu, 'exportToFile')
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
const rows = wrapper.findAll('tbody tr')
- // Select queries
+ // Select inquiries
await rows.at(0).find('.checkbox-container').trigger('click')
await rows.at(1).find('.checkbox-container').trigger('click')
await wrapper.find('#toolbar-btns-export').trigger('click')
- expect(storedQueries.serialiseQueries.calledOnceWith(
- sinon.match([predefinedQuery, queryInStore])
+ expect(storedInquiries.serialiseInquiries.calledOnceWith(
+ sinon.match([predefinedInquiry, inquiryInStore])
)).to.equals(true)
expect(
- fu.exportToFile.calledOnceWith('I am a serialized queries', 'My sqliteviz queries.json')
+ fu.exportToFile.calledOnceWith('I am a serialized inquiries', 'My sqliteviz inquiries.json')
).to.equals(true)
})
- it('Exports all queries', async () => {
- const predefinedQuery = {
+ it('Exports all inquiries', async () => {
+ const predefinedInquiry = {
id: 0,
name: 'hello_world',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([predefinedQuery])
- const queryInStore = {
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([predefinedInquiry])
+ const inquiryInStore = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([queryInStore])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([inquiryInStore])
- sinon.stub(storedQueries, 'serialiseQueries').returns('I am a serialized queries')
+ sinon.stub(storedInquiries, 'serialiseInquiries').returns('I am a serialized inquiries')
sinon.stub(fu, 'exportToFile')
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
await wrapper.findComponent({ ref: 'mainCheckBox' }).find('.checkbox-container')
@@ -631,63 +754,67 @@ describe('MyQueries.vue', () => {
await wrapper.find('#toolbar-btns-export').trigger('click')
- expect(storedQueries.serialiseQueries.calledOnceWith(
- sinon.match([predefinedQuery, queryInStore])
+ expect(storedInquiries.serialiseInquiries.calledOnceWith(
+ sinon.match([predefinedInquiry, inquiryInStore])
)).to.equals(true)
expect(
- fu.exportToFile.calledOnceWith('I am a serialized queries', 'My sqliteviz queries.json')
+ fu.exportToFile.calledOnceWith('I am a serialized inquiries', 'My sqliteviz inquiries.json')
).to.equals(true)
})
- it('Deletes a group of queries', async () => {
- const predefinedQuery = {
+ it('Deletes a group of inquiries', async () => {
+ const predefinedInquiry = {
id: 0,
name: 'hello_world',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([predefinedQuery])
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([predefinedInquiry])
const foo = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
const bar = {
id: 2,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
const baz = {
id: 3,
name: 'baz',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([foo, bar, baz])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([foo, bar, baz])
- sinon.stub(storedQueries, 'updateStorage')
+ sinon.stub(storedInquiries, 'updateStorage')
const state = {
tabs: [{ id: 1 }, { id: 2 }, { id: 0 }, { id: 3 }],
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
const rows = wrapper.findAll('tbody tr')
- // Select queries (don't select predefined queries)
+ // Select inquiries (don't select predefined inquiries)
await rows.at(1).find('.checkbox-container').trigger('click')
await rows.at(2).find('.checkbox-container').trigger('click')
@@ -698,7 +825,7 @@ describe('MyQueries.vue', () => {
// check the message in the dialog
expect(wrapper.find('.dialog-body').text())
- .to.contains('Are you sure you want to delete 2 queries?')
+ .to.contains('Are you sure you want to delete 2 inquiries?')
// find Delete in the dialog and click
await wrapper
@@ -711,58 +838,61 @@ describe('MyQueries.vue', () => {
expect(wrapper.findAll('tbody tr').at(0).find('td').text()).to.contains('hello_world')
expect(wrapper.findAll('tbody tr').at(1).find('td').text()).to.equals('baz')
- // check that deleted query was also deleted from tabs
+ // check that deleted inquiry was also deleted from tabs
expect(state.tabs).to.have.lengthOf(2)
expect(state.tabs[0].id).to.equals(0)
expect(state.tabs[1].id).to.equals(3)
// check that storage is updated
- expect(storedQueries.updateStorage.calledOnceWith(sinon.match([baz]))).to.equals(true)
+ expect(storedInquiries.updateStorage.calledOnceWith(sinon.match([baz]))).to.equals(true)
// check that delete dialog is closed
expect(wrapper.find('[data-modal="delete"]').exists()).to.equal(false)
})
- it('Ignores predefined queries during deletion', async () => {
- const predefinedQuery = {
+ it('Ignores predefined inquiries during deletion', async () => {
+ const predefinedInquiry = {
id: 0,
name: 'hello_world',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([predefinedQuery])
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([predefinedInquiry])
const foo = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
const bar = {
id: 2,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([foo, bar])
- sinon.stub(storedQueries, 'updateStorage')
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([foo, bar])
+ sinon.stub(storedInquiries, 'updateStorage')
const state = {
tabs: [],
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
const rows = wrapper.findAll('tbody tr')
- // Select queries (select also predefined queries)
+ // Select inquiries (select also predefined inquiries)
await rows.at(0).find('.checkbox-container').trigger('click')
await rows.at(1).find('.checkbox-container').trigger('click')
@@ -773,7 +903,7 @@ describe('MyQueries.vue', () => {
// check the message in the dialog
expect(wrapper.find('.dialog-body').text())
- .to.contains('Are you sure you want to delete 1 query?')
+ .to.contains('Are you sure you want to delete 1 inquiry?')
expect(wrapper.find('.dialog-body #note').isVisible()).to.equals(true)
@@ -789,47 +919,50 @@ describe('MyQueries.vue', () => {
expect(wrapper.findAll('tbody tr').at(1).find('td').text()).to.equals('bar')
// check that storage is updated
- expect(storedQueries.updateStorage.calledOnceWith(sinon.match([bar]))).to.equals(true)
+ expect(storedInquiries.updateStorage.calledOnceWith(sinon.match([bar]))).to.equals(true)
// check that delete dialog is closed
expect(wrapper.find('[data-modal="delete"]').exists()).to.equal(false)
})
- it('Deletes all queries ignoring predefined ones', async () => {
- const predefinedQuery = {
+ it('Deletes all inquiries ignoring predefined ones', async () => {
+ const predefinedInquiry = {
id: 0,
name: 'hello_world',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([predefinedQuery])
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([predefinedInquiry])
const foo = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
const bar = {
id: 2,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([foo, bar])
- sinon.stub(storedQueries, 'updateStorage')
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([foo, bar])
+ sinon.stub(storedInquiries, 'updateStorage')
const state = {
tabs: [],
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
await wrapper.findComponent({ ref: 'mainCheckBox' }).find('.checkbox-container')
@@ -842,7 +975,7 @@ describe('MyQueries.vue', () => {
// check the message in the dialog
expect(wrapper.find('.dialog-body').text())
- .to.contains('Are you sure you want to delete 2 queries?')
+ .to.contains('Are you sure you want to delete 2 inquiries?')
expect(wrapper.find('.dialog-body #note').isVisible()).to.equals(true)
@@ -857,38 +990,40 @@ describe('MyQueries.vue', () => {
expect(wrapper.findAll('tbody tr').at(0).find('td').text()).to.contains('hello_world')
// check that storage is updated
- expect(storedQueries.updateStorage.calledOnceWith(sinon.match([]))).to.equals(true)
+ expect(storedInquiries.updateStorage.calledOnceWith(sinon.match([]))).to.equals(true)
// check that delete dialog is closed
expect(wrapper.find('[data-modal="delete"]').exists()).to.equal(false)
})
it('Main checkbox', async () => {
- sinon.stub(storedQueries, 'readPredefinedQueries').resolves([])
+ sinon.stub(storedInquiries, 'readPredefinedInquiries').resolves([])
const foo = {
id: 1,
name: 'foo',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
const bar = {
id: 2,
name: 'bar',
query: '',
- chart: [],
+ viewType: 'chart',
+ viewOptions: [],
createdAt: '2020-03-08T19:57:56.299Z'
}
- sinon.stub(storedQueries, 'getStoredQueries').returns([foo, bar])
+ sinon.stub(storedInquiries, 'getStoredInquiries').returns([foo, bar])
const state = {
- predefinedQueries: []
+ predefinedInquiries: []
}
const store = new Vuex.Store({ state, mutations })
- const wrapper = mount(MyQueries, { store })
- await storedQueries.readPredefinedQueries.returnValues[0]
- await storedQueries.getStoredQueries.returnValues[0]
+ const wrapper = mount(Inquiries, { store })
+ await storedInquiries.readPredefinedInquiries.returnValues[0]
+ await storedInquiries.getStoredInquiries.returnValues[0]
await wrapper.vm.$nextTick()
const mainCheckBox = wrapper.findComponent({ ref: 'mainCheckBox' })
diff --git a/tests/views/MainView/MainMenu.spec.js b/tests/views/Main/MainMenu.spec.js
similarity index 66%
rename from tests/views/MainView/MainMenu.spec.js
rename to tests/views/Main/MainMenu.spec.js
index 9acb4ff..4fb9393 100644
--- a/tests/views/MainView/MainMenu.spec.js
+++ b/tests/views/Main/MainMenu.spec.js
@@ -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')
})
})
diff --git a/tests/views/Main/Workspace/Editor.spec.js b/tests/views/Main/Workspace/Editor.spec.js
new file mode 100644
index 0000000..f129cd4
--- /dev/null
+++ b/tests/views/Main/Workspace/Editor.spec.js
@@ -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)
+ })
+})
diff --git a/tests/views/MainView/Editor/Schema/Schema.spec.js b/tests/views/Main/Workspace/Schema/Schema.spec.js
similarity index 95%
rename from tests/views/MainView/Editor/Schema/Schema.spec.js
rename to tests/views/Main/Workspace/Schema/Schema.spec.js
index 4d18d0f..6f8a429 100644
--- a/tests/views/MainView/Editor/Schema/Schema.spec.js
+++ b/tests/views/Main/Workspace/Schema/Schema.spec.js
@@ -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']
})
})
})
diff --git a/tests/views/MainView/Editor/Schema/TableDescription.spec.js b/tests/views/Main/Workspace/Schema/TableDescription.spec.js
similarity index 94%
rename from tests/views/MainView/Editor/Schema/TableDescription.spec.js
rename to tests/views/Main/Workspace/Schema/TableDescription.spec.js
index d26080e..cc227e7 100644
--- a/tests/views/MainView/Editor/Schema/TableDescription.spec.js
+++ b/tests/views/Main/Workspace/Schema/TableDescription.spec.js
@@ -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', () => {
diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Chart.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Chart.spec.js
new file mode 100644
index 0000000..48f9aac
--- /dev/null
+++ b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Chart.spec.js
@@ -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)
+ })
+})
diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/DataView.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/DataView.spec.js
new file mode 100644
index 0000000..e0d9ab6
--- /dev/null
+++ b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/DataView.spec.js
@@ -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' })
+ })
+})
diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/Pivot.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/Pivot.spec.js
new file mode 100644
index 0000000..dab042e
--- /dev/null
+++ b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/Pivot.spec.js
@@ -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([])
+ })
+})
diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotSortBtn.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotSortBtn.spec.js
new file mode 100644
index 0000000..4a79e93
--- /dev/null
+++ b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotSortBtn.spec.js
@@ -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'])
+ })
+})
diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotUi.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotUi.spec.js
new file mode 100644
index 0000000..1933f3e
--- /dev/null
+++ b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/PivotUi.spec.js
@@ -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'])
+ })
+})
diff --git a/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/pivotHelper.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/pivotHelper.spec.js
new file mode 100644
index 0000000..581668e
--- /dev/null
+++ b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/Pivot/PivotUi/pivotHelper.spec.js
@@ -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]
+ })
+ })
+})
diff --git a/tests/views/MainView/Editor/Tabs/Tab/Chart/chartHelper.spec.js b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/chartHelper.spec.js
similarity index 68%
rename from tests/views/MainView/Editor/Tabs/Tab/Chart/chartHelper.spec.js
rename to tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/chartHelper.spec.js
index 5cc94d5..b35550c 100644
--- a/tests/views/MainView/Editor/Tabs/Tab/Chart/chartHelper.spec.js
+++ b/tests/views/Main/Workspace/Tabs/Tab/DataView/Chart/chartHelper.spec.js
@@ -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)
diff --git a/tests/views/Main/Workspace/Tabs/Tab/SqlEditor/SqlEditor.spec.js b/tests/views/Main/Workspace/Tabs/Tab/SqlEditor/SqlEditor.spec.js
new file mode 100644
index 0000000..118b899
--- /dev/null
+++ b/tests/views/Main/Workspace/Tabs/Tab/SqlEditor/SqlEditor.spec.js
@@ -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)
+ })
+})
diff --git a/tests/views/MainView/Editor/Tabs/Tab/SqlEditor/hint.spec.js b/tests/views/Main/Workspace/Tabs/Tab/SqlEditor/hint.spec.js
similarity index 98%
rename from tests/views/MainView/Editor/Tabs/Tab/SqlEditor/hint.spec.js
rename to tests/views/Main/Workspace/Tabs/Tab/SqlEditor/hint.spec.js
index abe5ec6..81a74b9 100644
--- a/tests/views/MainView/Editor/Tabs/Tab/SqlEditor/hint.spec.js
+++ b/tests/views/Main/Workspace/Tabs/Tab/SqlEditor/hint.spec.js
@@ -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', () => {
diff --git a/tests/views/MainView/Editor/Tabs/Tab/Tab.spec.js b/tests/views/Main/Workspace/Tabs/Tab/Tab.spec.js
similarity index 65%
rename from tests/views/MainView/Editor/Tabs/Tab/Tab.spec.js
rename to tests/views/Main/Workspace/Tabs/Tab/Tab.spec.js
index 87ab756..d9a0441 100644
--- a/tests/views/MainView/Editor/Tabs/Tab/Tab.spec.js
+++ b/tests/views/Main/Workspace/Tabs/Tab/Tab.spec.js
@@ -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)
+ })
})
diff --git a/tests/views/MainView/Editor/Tabs/Tabs.spec.js b/tests/views/Main/Workspace/Tabs/Tabs.spec.js
similarity index 90%
rename from tests/views/MainView/Editor/Tabs/Tabs.spec.js
rename to tests/views/Main/Workspace/Tabs/Tabs.spec.js
index 479f4f6..edc1522 100644
--- a/tests/views/MainView/Editor/Tabs/Tabs.spec.js
+++ b/tests/views/Main/Workspace/Tabs/Tabs.spec.js
@@ -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
}
diff --git a/tests/views/MainView/Editor/Tabs/Tab/Chart/Chart.spec.js b/tests/views/MainView/Editor/Tabs/Tab/Chart/Chart.spec.js
deleted file mode 100644
index 115cb3d..0000000
--- a/tests/views/MainView/Editor/Tabs/Tab/Chart/Chart.spec.js
+++ /dev/null
@@ -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)
- })
-})
diff --git a/tests/views/MainView/Editor/Tabs/Tab/SqlEditor/SqlEditor.spec.js b/tests/views/MainView/Editor/Tabs/Tab/SqlEditor/SqlEditor.spec.js
deleted file mode 100644
index 2ed2b88..0000000
--- a/tests/views/MainView/Editor/Tabs/Tab/SqlEditor/SqlEditor.spec.js
+++ /dev/null
@@ -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'])
- })
-})
diff --git a/vue.config.js b/vue.config.js
index 325dba8..b9de711 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -15,7 +15,7 @@ module.exports = {
{ from: 'LICENSE', to: './' }
]),
new WorkboxPlugin.GenerateSW({
- exclude: [/\.map$/, 'LICENSE', 'queries.json'],
+ exclude: [/\.map$/, 'LICENSE', 'inquiries.json'],
clientsClaim: true,
skipWaiting: false,
maximumFileSizeToCacheInBytes: 40000000