diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/frontend/ide/components/ide_spec.js | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
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); }); }); |