mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
add test for closing browser tab
This commit is contained in:
@@ -86,9 +86,6 @@ export default {
|
|||||||
created () {
|
created () {
|
||||||
window.addEventListener('beforeunload', this.leavingSqliteviz)
|
window.addEventListener('beforeunload', this.leavingSqliteviz)
|
||||||
},
|
},
|
||||||
unmounted () {
|
|
||||||
window.removeEventListener('beforeunload', this.leavingSqliteviz)
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
leavingSqliteviz (event) {
|
leavingSqliteviz (event) {
|
||||||
if (this.tabs.some(tab => tab.isUnsaved)) {
|
if (this.tabs.some(tab => tab.isUnsaved)) {
|
||||||
|
|||||||
@@ -229,4 +229,47 @@ describe('Tabs.vue', () => {
|
|||||||
// check that the dialog is closed
|
// check that the dialog is closed
|
||||||
expect(wrapper.find('[data-modal="close-warn"]').exists()).to.equal(false)
|
expect(wrapper.find('[data-modal="close-warn"]').exists()).to.equal(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Prevents closing a tab of a browser if there is unsaved query', () => {
|
||||||
|
// 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 }
|
||||||
|
],
|
||||||
|
currentTabId: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = new Vuex.Store({ state, mutations })
|
||||||
|
|
||||||
|
// mount the component
|
||||||
|
const wrapper = shallowMount(Tabs, { store })
|
||||||
|
|
||||||
|
const event = new Event('beforeunload')
|
||||||
|
sinon.spy(event, 'preventDefault')
|
||||||
|
wrapper.vm.leavingSqliteviz(event)
|
||||||
|
|
||||||
|
expect(event.preventDefault.calledOnce).to.equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Doesn't prevent closing a tab of a browser if there is unsaved query", () => {
|
||||||
|
// mock store state
|
||||||
|
const state = {
|
||||||
|
tabs: [
|
||||||
|
{ id: 1, name: 'foo', query: 'select * from foo', chart: [], isUnsaved: false }
|
||||||
|
],
|
||||||
|
currentTabId: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = new Vuex.Store({ state, mutations })
|
||||||
|
|
||||||
|
// mount the component
|
||||||
|
const wrapper = shallowMount(Tabs, { store })
|
||||||
|
|
||||||
|
const event = new Event('beforeunload')
|
||||||
|
sinon.spy(event, 'preventDefault')
|
||||||
|
wrapper.vm.leavingSqliteviz(event)
|
||||||
|
|
||||||
|
expect(event.preventDefault.calledOnce).to.equal(false)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user