debian-mirror-gitlab/spec/frontend/ide/components/panes/right_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

162 lines
4.3 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
2020-03-13 15:44:24 +05:30
import Vuex from 'vuex';
import CollapsibleSidebar from '~/ide/components/panes/collapsible_sidebar.vue';
2021-03-11 19:13:27 +05:30
import RightPane from '~/ide/components/panes/right.vue';
2023-01-13 00:05:48 +05:30
import SwitchEditorsView from '~/ide/components/switch_editors/switch_editors_view.vue';
2018-11-08 19:23:39 +05:30
import { rightSidebarViews } from '~/ide/constants';
2021-03-11 19:13:27 +05:30
import { createStore } from '~/ide/stores';
2020-06-23 00:09:42 +05:30
import extendStore from '~/ide/stores/extend';
2023-01-13 00:05:48 +05:30
import { __ } from '~/locale';
2018-11-08 19:23:39 +05:30
2022-04-04 11:22:00 +05:30
Vue.use(Vuex);
2018-11-08 19:23:39 +05:30
2023-01-13 00:05:48 +05:30
const SWITCH_EDITORS_VIEW_NAME = 'switch-editors';
2020-03-13 15:44:24 +05:30
describe('ide/components/panes/right.vue', () => {
let wrapper;
let store;
2018-11-08 19:23:39 +05:30
2021-03-08 18:12:59 +05:30
const createComponent = (props) => {
2020-06-23 00:09:42 +05:30
extendStore(store, document.createElement('div'));
2020-03-13 15:44:24 +05:30
wrapper = shallowMount(RightPane, {
store,
propsData: {
...props,
},
});
};
2018-11-08 19:23:39 +05:30
2020-03-13 15:44:24 +05:30
beforeEach(() => {
store = createStore();
2018-11-08 19:23:39 +05:30
});
afterEach(() => {
2020-03-13 15:44:24 +05:30
wrapper.destroy();
wrapper = null;
2018-11-08 19:23:39 +05:30
});
2023-01-13 00:05:48 +05:30
describe('default', () => {
beforeEach(() => {
createComponent();
});
it('renders collapsible-sidebar', () => {
expect(wrapper.findComponent(CollapsibleSidebar).props()).toMatchObject({
side: 'right',
initOpenView: SWITCH_EDITORS_VIEW_NAME,
});
});
});
2020-03-13 15:44:24 +05:30
describe('pipelines tab', () => {
it('is always shown', () => {
createComponent();
2018-11-08 19:23:39 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(CollapsibleSidebar).props('extensionTabs')).toEqual(
2020-03-13 15:44:24 +05:30
expect.arrayContaining([
expect.objectContaining({
show: true,
title: 'Pipelines',
views: expect.arrayContaining([
expect.objectContaining({
name: rightSidebarViews.pipelines.name,
}),
expect.objectContaining({
name: rightSidebarViews.jobsDetail.name,
}),
]),
}),
]),
);
2018-11-08 19:23:39 +05:30
});
});
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
describe('clientside live preview tab', () => {
it('is shown if there is a packageJson and clientsidePreviewEnabled', () => {
Vue.set(store.state.entries, 'package.json', {
2020-01-01 13:55:28 +05:30
name: 'package.json',
});
2020-03-13 15:44:24 +05:30
store.state.clientsidePreviewEnabled = true;
2018-11-18 11:00:15 +05:30
2020-03-13 15:44:24 +05:30
createComponent();
2018-11-18 11:00:15 +05:30
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(CollapsibleSidebar).props('extensionTabs')).toEqual(
2020-03-13 15:44:24 +05:30
expect.arrayContaining([
expect.objectContaining({
show: true,
title: 'Live preview',
views: expect.arrayContaining([
expect.objectContaining({
name: rightSidebarViews.clientSidePreview.name,
}),
]),
}),
]),
);
2018-11-18 11:00:15 +05:30
});
});
2020-06-23 00:09:42 +05:30
describe('terminal tab', () => {
beforeEach(() => {
createComponent();
});
2022-04-04 11:22:00 +05:30
it('adds terminal tab', async () => {
2020-06-23 00:09:42 +05:30
store.state.terminal.isVisible = true;
2022-04-04 11:22:00 +05:30
await nextTick();
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(CollapsibleSidebar).props('extensionTabs')).toEqual(
2022-04-04 11:22:00 +05:30
expect.arrayContaining([
expect.objectContaining({
show: true,
title: 'Terminal',
}),
]),
);
2020-06-23 00:09:42 +05:30
});
it('hides terminal tab when not visible', () => {
store.state.terminal.isVisible = false;
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(CollapsibleSidebar).props('extensionTabs')).toEqual(
2020-06-23 00:09:42 +05:30
expect.arrayContaining([
expect.objectContaining({
show: false,
title: 'Terminal',
}),
]),
);
});
});
2023-01-13 00:05:48 +05:30
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 },
],
}),
]),
);
});
});
2018-11-08 19:23:39 +05:30
});