Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-07 00:09:08 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-07 00:09:08 +0300
commitf2143c9986ad7b6206b8a41cc9aeb419e543d3f5 (patch)
tree215aecfdd982c53e2b8565cb5b2299d7dd4665b0 /spec/frontend/ide/components
parent5a73318262aab6ab952f2b7205b3674ea1f20053 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ide/components')
-rw-r--r--spec/frontend/ide/components/panes/right_spec.js33
-rw-r--r--spec/frontend/ide/components/switch_editors/switch_editors_view_spec.js214
2 files changed, 0 insertions, 247 deletions
diff --git a/spec/frontend/ide/components/panes/right_spec.js b/spec/frontend/ide/components/panes/right_spec.js
index b7349b8fed1..294f5eee863 100644
--- a/spec/frontend/ide/components/panes/right_spec.js
+++ b/spec/frontend/ide/components/panes/right_spec.js
@@ -3,16 +3,12 @@ import Vue, { nextTick } from 'vue';
import Vuex from 'vuex';
import CollapsibleSidebar from '~/ide/components/panes/collapsible_sidebar.vue';
import RightPane from '~/ide/components/panes/right.vue';
-import SwitchEditorsView from '~/ide/components/switch_editors/switch_editors_view.vue';
import { rightSidebarViews } from '~/ide/constants';
import { createStore } from '~/ide/stores';
import extendStore from '~/ide/stores/extend';
-import { __ } from '~/locale';
Vue.use(Vuex);
-const SWITCH_EDITORS_VIEW_NAME = 'switch-editors';
-
describe('ide/components/panes/right.vue', () => {
let wrapper;
let store;
@@ -45,7 +41,6 @@ describe('ide/components/panes/right.vue', () => {
it('renders collapsible-sidebar', () => {
expect(wrapper.findComponent(CollapsibleSidebar).props()).toMatchObject({
side: 'right',
- initOpenView: SWITCH_EDITORS_VIEW_NAME,
});
});
});
@@ -130,32 +125,4 @@ describe('ide/components/panes/right.vue', () => {
);
});
});
-
- describe('switch editors tab', () => {
- beforeEach(() => {
- createComponent();
- });
-
- it.each`
- desc | canUseNewWebIde | expectedShow
- ${'is shown'} | ${true} | ${true}
- ${'is not shown'} | ${false} | ${false}
- `('with canUseNewWebIde=$canUseNewWebIde, $desc', async ({ canUseNewWebIde, expectedShow }) => {
- Object.assign(store.state, { canUseNewWebIde });
-
- await nextTick();
-
- expect(wrapper.findComponent(CollapsibleSidebar).props('extensionTabs')).toEqual(
- expect.arrayContaining([
- expect.objectContaining({
- show: expectedShow,
- title: __('Switch editors'),
- views: [
- { component: SwitchEditorsView, name: SWITCH_EDITORS_VIEW_NAME, keepAlive: true },
- ],
- }),
- ]),
- );
- });
- });
});
diff --git a/spec/frontend/ide/components/switch_editors/switch_editors_view_spec.js b/spec/frontend/ide/components/switch_editors/switch_editors_view_spec.js
deleted file mode 100644
index 7a958391fea..00000000000
--- a/spec/frontend/ide/components/switch_editors/switch_editors_view_spec.js
+++ /dev/null
@@ -1,214 +0,0 @@
-import { GlButton, GlEmptyState, GlLink } from '@gitlab/ui';
-import { shallowMount } from '@vue/test-utils';
-import MockAdapter from 'axios-mock-adapter';
-import waitForPromises from 'helpers/wait_for_promises';
-import { useMockLocationHelper } from 'helpers/mock_window_location_helper';
-import { createAlert } from '~/flash';
-import axios from '~/lib/utils/axios_utils';
-import { logError } from '~/lib/logger';
-import { __ } from '~/locale';
-import { confirmAction } from '~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal';
-import SwitchEditorsView, {
- MSG_ERROR_ALERT,
- MSG_CONFIRM,
- MSG_TITLE,
- MSG_LEARN_MORE,
- MSG_DESCRIPTION,
-} from '~/ide/components/switch_editors/switch_editors_view.vue';
-import eventHub from '~/ide/eventhub';
-import { createStore } from '~/ide/stores';
-
-jest.mock('~/flash');
-jest.mock('~/lib/logger');
-jest.mock('~/lib/utils/confirm_via_gl_modal/confirm_via_gl_modal');
-
-const TEST_USER_PREFERENCES_PATH = '/test/user-pref/path';
-const TEST_SWITCH_EDITOR_SVG_PATH = '/test/switch/editor/path.svg';
-const TEST_HREF = '/test/new/web/ide/href';
-
-describe('~/ide/components/switch_editors/switch_editors_view.vue', () => {
- useMockLocationHelper();
-
- let store;
- let wrapper;
- let confirmResolve;
- let requestSpy;
- let skipBeforeunloadSpy;
- let axiosMock;
-
- // region: finders ------------------
- const findButton = () => wrapper.findComponent(GlButton);
- const findEmptyState = () => wrapper.findComponent(GlEmptyState);
-
- // region: actions ------------------
- const triggerSwitchPreference = () => findButton().vm.$emit('click');
- const submitConfirm = async (val) => {
- confirmResolve(val);
-
- // why: We need to wait for promises for the immediate next lines to be executed
- await waitForPromises();
- };
-
- const createComponent = () => {
- wrapper = shallowMount(SwitchEditorsView, {
- store,
- stubs: {
- GlEmptyState,
- },
- });
- };
-
- // region: test setup ------------------
- beforeEach(() => {
- // Setup skip-beforeunload side-effect
- skipBeforeunloadSpy = jest.fn();
- eventHub.$on('skip-beforeunload', skipBeforeunloadSpy);
-
- // Setup request side-effect
- requestSpy = jest.fn().mockImplementation(() => new Promise(() => {}));
- axiosMock = new MockAdapter(axios);
- axiosMock.onPut(TEST_USER_PREFERENCES_PATH).reply(({ data }) => requestSpy(data));
-
- // Setup store
- store = createStore();
- store.state.userPreferencesPath = TEST_USER_PREFERENCES_PATH;
- store.state.switchEditorSvgPath = TEST_SWITCH_EDITOR_SVG_PATH;
- store.state.links = {
- newWebIDEHelpPagePath: TEST_HREF,
- };
-
- // Setup user confirm side-effect
- confirmAction.mockImplementation(
- () =>
- new Promise((resolve) => {
- confirmResolve = resolve;
- }),
- );
- });
-
- afterEach(() => {
- eventHub.$off('skip-beforeunload', skipBeforeunloadSpy);
-
- axiosMock.restore();
- });
-
- // region: tests ------------------
- describe('default', () => {
- beforeEach(() => {
- createComponent();
- });
-
- it('render empty state', () => {
- expect(findEmptyState().props()).toMatchObject({
- svgPath: TEST_SWITCH_EDITOR_SVG_PATH,
- svgHeight: 150,
- title: MSG_TITLE,
- });
- });
-
- it('render link', () => {
- expect(wrapper.findComponent(GlLink).attributes('href')).toBe(TEST_HREF);
- expect(wrapper.findComponent(GlLink).text()).toBe(MSG_LEARN_MORE);
- });
-
- it('renders description', () => {
- expect(findEmptyState().text()).toContain(MSG_DESCRIPTION);
- });
-
- it('is not loading', () => {
- expect(findButton().props('loading')).toBe(false);
- });
- });
-
- describe('when user triggers switch preference', () => {
- beforeEach(() => {
- createComponent();
-
- triggerSwitchPreference();
- });
-
- it('creates a single confirm', () => {
- // Call again to ensure that we only show 1 confirm action
- triggerSwitchPreference();
-
- expect(confirmAction).toHaveBeenCalledTimes(1);
- expect(confirmAction).toHaveBeenCalledWith(MSG_CONFIRM, {
- primaryBtnText: __('Switch editors'),
- cancelBtnText: __('Cancel'),
- });
- });
-
- it('starts loading', () => {
- expect(findButton().props('loading')).toBe(true);
- });
-
- describe('when user cancels confirm', () => {
- beforeEach(async () => {
- await submitConfirm(false);
- });
-
- it('does not make request', () => {
- expect(requestSpy).not.toHaveBeenCalled();
- });
-
- it('can be triggered again', () => {
- triggerSwitchPreference();
-
- expect(confirmAction).toHaveBeenCalledTimes(2);
- });
- });
-
- describe('when user accepts confirm and response success', () => {
- beforeEach(async () => {
- requestSpy.mockReturnValue([200, {}]);
- await submitConfirm(true);
- });
-
- it('does not handle error', () => {
- expect(logError).not.toHaveBeenCalled();
- expect(createAlert).not.toHaveBeenCalled();
- });
-
- it('emits "skip-beforeunload" and reloads', () => {
- expect(skipBeforeunloadSpy).toHaveBeenCalledTimes(1);
- expect(window.location.reload).toHaveBeenCalledTimes(1);
- });
-
- it('calls request', () => {
- expect(requestSpy).toHaveBeenCalledTimes(1);
- expect(requestSpy).toHaveBeenCalledWith(
- JSON.stringify({ user: { use_legacy_web_ide: false } }),
- );
- });
-
- it('is not loading', () => {
- expect(findButton().props('loading')).toBe(false);
- });
- });
-
- describe('when user accepts confirm and response fails', () => {
- beforeEach(async () => {
- requestSpy.mockReturnValue([400, {}]);
- await submitConfirm(true);
- });
-
- it('handles error', () => {
- expect(logError).toHaveBeenCalledTimes(1);
- expect(logError).toHaveBeenCalledWith(
- 'Error while updating user preferences',
- expect.any(Error),
- );
-
- expect(createAlert).toHaveBeenCalledTimes(1);
- expect(createAlert).toHaveBeenCalledWith({
- message: MSG_ERROR_ALERT,
- });
- });
-
- it('does not reload', () => {
- expect(skipBeforeunloadSpy).not.toHaveBeenCalled();
- expect(window.location.reload).not.toHaveBeenCalled();
- });
- });
- });
-});