2020-01-16 19:09:00 -05:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
2020-08-17 17:09:56 -04:00
|
|
|
import Vuex from 'vuex';
|
2021-02-14 13:09:20 -05:00
|
|
|
import IdeSidebarNav from '~/ide/components/ide_sidebar_nav.vue';
|
|
|
|
import CollapsibleSidebar from '~/ide/components/panes/collapsible_sidebar.vue';
|
2020-01-16 19:09:00 -05:00
|
|
|
import { createStore } from '~/ide/stores';
|
|
|
|
import paneModule from '~/ide/stores/modules/pane';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
describe('ide/components/panes/collapsible_sidebar.vue', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
|
|
|
|
const width = 350;
|
|
|
|
const fakeComponentName = 'fake-component';
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
const createComponent = (props) => {
|
2020-01-16 19:09:00 -05:00
|
|
|
wrapper = shallowMount(CollapsibleSidebar, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
propsData: {
|
|
|
|
extensionTabs: [],
|
|
|
|
side: 'right',
|
|
|
|
width,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
const findSidebarNav = () => wrapper.find(IdeSidebarNav);
|
2020-01-16 19:09:00 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
store = createStore();
|
|
|
|
store.registerModule('leftPane', paneModule());
|
2020-05-21 11:08:18 -04:00
|
|
|
jest.spyOn(store, 'dispatch').mockImplementation();
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('with a tab', () => {
|
|
|
|
let fakeView;
|
|
|
|
let extensionTabs;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
const FakeComponent = localVue.component(fakeComponentName, {
|
2021-01-11 04:10:46 -05:00
|
|
|
render: () => null,
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
fakeView = {
|
|
|
|
name: fakeComponentName,
|
|
|
|
keepAlive: true,
|
|
|
|
component: FakeComponent,
|
|
|
|
};
|
|
|
|
|
|
|
|
extensionTabs = [
|
|
|
|
{
|
|
|
|
show: true,
|
|
|
|
title: fakeComponentName,
|
|
|
|
views: [fakeView],
|
|
|
|
icon: 'text-description',
|
|
|
|
buttonClasses: ['button-class-1', 'button-class-2'],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
describe.each`
|
|
|
|
side
|
|
|
|
${'left'}
|
|
|
|
${'right'}
|
|
|
|
`('when side=$side', ({ side }) => {
|
2020-05-21 11:08:18 -04:00
|
|
|
beforeEach(() => {
|
2020-01-16 19:09:00 -05:00
|
|
|
createComponent({ extensionTabs, side });
|
|
|
|
});
|
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
it('correctly renders side specific attributes', () => {
|
|
|
|
expect(wrapper.classes()).toContain('multi-file-commit-panel');
|
|
|
|
expect(wrapper.classes()).toContain(`ide-${side}-sidebar`);
|
|
|
|
expect(wrapper.find('.multi-file-commit-panel-inner')).not.toBe(null);
|
|
|
|
expect(wrapper.find(`.ide-${side}-sidebar-${fakeComponentName}`)).not.toBe(null);
|
|
|
|
expect(findSidebarNav().props('side')).toBe(side);
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
it('nothing is dispatched', () => {
|
|
|
|
expect(store.dispatch).not.toHaveBeenCalled();
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
it('when sidebar emits open, dispatch open', () => {
|
|
|
|
const view = 'lorem-view';
|
2020-01-16 19:09:00 -05:00
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
findSidebarNav().vm.$emit('open', view);
|
2020-01-16 19:09:00 -05:00
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
expect(store.dispatch).toHaveBeenCalledWith(`${side}Pane/open`, view);
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
it('when sidebar emits close, dispatch toggleOpen', () => {
|
|
|
|
findSidebarNav().vm.$emit('close');
|
2020-01-16 19:09:00 -05:00
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
expect(store.dispatch).toHaveBeenCalledWith(`${side}Pane/toggleOpen`);
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
2020-05-21 11:08:18 -04:00
|
|
|
});
|
2020-01-16 19:09:00 -05:00
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
describe.each`
|
|
|
|
isOpen
|
|
|
|
${true}
|
|
|
|
${false}
|
|
|
|
`('when isOpen=$isOpen', ({ isOpen }) => {
|
|
|
|
beforeEach(() => {
|
|
|
|
store.state.rightPane.isOpen = isOpen;
|
|
|
|
store.state.rightPane.currentView = fakeComponentName;
|
|
|
|
|
|
|
|
createComponent({ extensionTabs });
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
it(`tab view is shown=${isOpen}`, () => {
|
|
|
|
expect(wrapper.find('.js-tab-view').exists()).toBe(isOpen);
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
|
|
|
|
2020-05-21 11:08:18 -04:00
|
|
|
it('renders sidebar nav', () => {
|
|
|
|
expect(findSidebarNav().props()).toEqual({
|
|
|
|
tabs: extensionTabs,
|
|
|
|
side: 'right',
|
|
|
|
currentView: fakeComponentName,
|
|
|
|
isOpen,
|
|
|
|
});
|
2020-01-16 19:09:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|