diff options
Diffstat (limited to 'spec/frontend/ide/components/ide_spec.js')
-rw-r--r-- | spec/frontend/ide/components/ide_spec.js | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/spec/frontend/ide/components/ide_spec.js b/spec/frontend/ide/components/ide_spec.js index 48c670757a2..a575f428a69 100644 --- a/spec/frontend/ide/components/ide_spec.js +++ b/spec/frontend/ide/components/ide_spec.js @@ -3,9 +3,11 @@ import Vue from 'vue'; import Vuex from 'vuex'; import waitForPromises from 'helpers/wait_for_promises'; import { stubPerformanceWebAPI } from 'helpers/performance'; +import { __ } from '~/locale'; import CannotPushCodeAlert from '~/ide/components/cannot_push_code_alert.vue'; import ErrorMessage from '~/ide/components/error_message.vue'; import Ide from '~/ide/components/ide.vue'; +import eventHub from '~/ide/eventhub'; import { MSG_CANNOT_PUSH_CODE_GO_TO_FORK, MSG_GO_TO_FORK } from '~/ide/messages'; import { createStore } from '~/ide/stores'; import { file } from '../helpers'; @@ -14,6 +16,7 @@ import { projectData } from '../mock_data'; Vue.use(Vuex); const TEST_FORK_IDE_PATH = '/test/ide/path'; +const MSG_ARE_YOU_SURE = __('Are you sure you want to lose unsaved changes?'); describe('WebIDE', () => { const emptyProjData = { ...projectData, empty_repo: true, branches: {} }; @@ -40,6 +43,8 @@ describe('WebIDE', () => { const findAlert = () => wrapper.findComponent(CannotPushCodeAlert); + const callOnBeforeUnload = (e = {}) => window.onbeforeunload(e); + beforeEach(() => { stubPerformanceWebAPI(); @@ -49,6 +54,7 @@ describe('WebIDE', () => { afterEach(() => { wrapper.destroy(); wrapper = null; + window.onbeforeunload = null; }); describe('ide component, empty repo', () => { @@ -90,7 +96,8 @@ describe('WebIDE', () => { describe('onBeforeUnload', () => { it('returns undefined when no staged files or changed files', () => { createComponent(); - expect(wrapper.vm.onBeforeUnload()).toBe(undefined); + + expect(callOnBeforeUnload()).toBe(undefined); }); it('returns warning text when their are changed files', () => { @@ -100,7 +107,10 @@ describe('WebIDE', () => { }, }); - expect(wrapper.vm.onBeforeUnload()).toBe('Are you sure you want to lose unsaved changes?'); + const e = {}; + + expect(callOnBeforeUnload(e)).toBe(MSG_ARE_YOU_SURE); + expect(e.returnValue).toBe(MSG_ARE_YOU_SURE); }); it('returns warning text when their are staged files', () => { @@ -110,20 +120,27 @@ describe('WebIDE', () => { }, }); - expect(wrapper.vm.onBeforeUnload()).toBe('Are you sure you want to lose unsaved changes?'); + const e = {}; + + expect(callOnBeforeUnload(e)).toBe(MSG_ARE_YOU_SURE); + expect(e.returnValue).toBe(MSG_ARE_YOU_SURE); }); - it('updates event object', () => { - const event = {}; + it('returns undefined once after "skip-beforeunload" was emitted', () => { createComponent({ state: { stagedFiles: [file()], }, }); - wrapper.vm.onBeforeUnload(event); + eventHub.$emit('skip-beforeunload'); + const e = {}; + + expect(callOnBeforeUnload()).toBe(undefined); + expect(e.returnValue).toBe(undefined); - expect(event.returnValue).toBe('Are you sure you want to lose unsaved changes?'); + expect(callOnBeforeUnload(e)).toBe(MSG_ARE_YOU_SURE); + expect(e.returnValue).toBe(MSG_ARE_YOU_SURE); }); }); |