debian-mirror-gitlab/spec/frontend/boards/components/board_settings_sidebar_spec.js

182 lines
5.2 KiB
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { GlDrawer, GlLabel, GlModal, GlButton } from '@gitlab/ui';
2021-11-11 11:23:49 +05:30
import { shallowMount } from '@vue/test-utils';
2021-09-30 23:02:18 +05:30
import { MountingPortal } from 'portal-vue';
2022-04-04 11:22:00 +05:30
import Vue, { nextTick } from 'vue';
2020-10-24 23:57:45 +05:30
import Vuex from 'vuex';
2022-04-04 11:22:00 +05:30
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
2021-11-11 11:23:49 +05:30
import { stubComponent } from 'helpers/stub_component';
2021-04-29 21:17:54 +05:30
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
2020-10-24 23:57:45 +05:30
import BoardSettingsSidebar from '~/boards/components/board_settings_sidebar.vue';
2021-03-11 19:13:27 +05:30
import { inactiveId, LIST } from '~/boards/constants';
2021-11-11 11:23:49 +05:30
import actions from '~/boards/stores/actions';
import getters from '~/boards/stores/getters';
import mutations from '~/boards/stores/mutations';
2020-10-24 23:57:45 +05:30
import sidebarEventHub from '~/sidebar/event_hub';
2021-11-11 11:23:49 +05:30
import { mockLabelList } from '../mock_data';
2020-10-24 23:57:45 +05:30
2021-11-11 11:23:49 +05:30
Vue.use(Vuex);
2020-10-24 23:57:45 +05:30
describe('BoardSettingsSidebar', () => {
let wrapper;
2021-11-11 11:23:49 +05:30
const labelTitle = mockLabelList.label.title;
const labelColor = mockLabelList.label.color;
const listId = mockLabelList.id;
2022-04-04 11:22:00 +05:30
const modalID = 'board-settings-sidebar-modal';
2021-04-29 21:17:54 +05:30
2021-11-11 11:23:49 +05:30
const createComponent = ({
canAdminList = false,
list = {},
sidebarType = LIST,
activeId = inactiveId,
} = {}) => {
const boardLists = {
[listId]: list,
};
const store = new Vuex.Store({
state: { sidebarType, activeId, boardLists },
getters,
mutations,
actions,
});
2021-04-29 21:17:54 +05:30
wrapper = extendedWrapper(
shallowMount(BoardSettingsSidebar, {
store,
provide: {
canAdminList,
2021-11-11 11:23:49 +05:30
scopedLabelsAvailable: false,
},
2022-04-04 11:22:00 +05:30
directives: {
GlModal: createMockDirective(),
},
2021-11-11 11:23:49 +05:30
stubs: {
GlDrawer: stubComponent(GlDrawer, {
template: '<div><slot name="header"></slot><slot></slot></div>',
}),
2021-04-29 21:17:54 +05:30
},
}),
);
2020-10-24 23:57:45 +05:30
};
const findLabel = () => wrapper.find(GlLabel);
const findDrawer = () => wrapper.find(GlDrawer);
2022-04-04 11:22:00 +05:30
const findModal = () => wrapper.find(GlModal);
const findRemoveButton = () => wrapper.find(GlButton);
2020-10-24 23:57:45 +05:30
afterEach(() => {
jest.restoreAllMocks();
wrapper.destroy();
2021-11-11 11:23:49 +05:30
wrapper = null;
2020-10-24 23:57:45 +05:30
});
2021-09-30 23:02:18 +05:30
it('finds a MountingPortal component', () => {
createComponent();
expect(wrapper.find(MountingPortal).props()).toMatchObject({
mountTo: '#js-right-sidebar-portal',
append: true,
name: 'board-settings-sidebar',
});
});
2020-11-24 15:15:51 +05:30
describe('when sidebarType is "list"', () => {
it('finds a GlDrawer component', () => {
createComponent();
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
expect(findDrawer().exists()).toBe(true);
});
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
describe('on close', () => {
it('closes the sidebar', async () => {
createComponent();
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
findDrawer().vm.$emit('close');
2020-10-24 23:57:45 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
expect(wrapper.find(GlDrawer).exists()).toBe(false);
});
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
it('closes the sidebar when emitting the correct event', async () => {
createComponent();
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
sidebarEventHub.$emit('sidebar.closeAll');
2020-10-24 23:57:45 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
expect(wrapper.find(GlDrawer).exists()).toBe(false);
});
2020-10-24 23:57:45 +05:30
});
2020-11-24 15:15:51 +05:30
describe('when activeId is zero', () => {
it('renders GlDrawer with open false', () => {
createComponent();
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
expect(findDrawer().props('open')).toBe(false);
});
2020-10-24 23:57:45 +05:30
});
2020-11-24 15:15:51 +05:30
describe('when activeId is greater than zero', () => {
2021-11-11 11:23:49 +05:30
it('renders GlDrawer with open true', () => {
createComponent({ list: mockLabelList, activeId: listId });
2020-11-24 15:15:51 +05:30
expect(findDrawer().props('open')).toBe(true);
});
2020-10-24 23:57:45 +05:30
});
2021-11-11 11:23:49 +05:30
describe('when activeId is in state', () => {
2020-11-24 15:15:51 +05:30
it('renders label title', () => {
2021-11-11 11:23:49 +05:30
createComponent({ list: mockLabelList, activeId: listId });
2020-11-24 15:15:51 +05:30
expect(findLabel().props('title')).toBe(labelTitle);
});
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
it('renders label background color', () => {
2021-11-11 11:23:49 +05:30
createComponent({ list: mockLabelList, activeId: listId });
2020-11-24 15:15:51 +05:30
expect(findLabel().props('backgroundColor')).toBe(labelColor);
});
2020-10-24 23:57:45 +05:30
});
2021-11-11 11:23:49 +05:30
describe('when activeId is not in state', () => {
2020-11-24 15:15:51 +05:30
it('does not render GlLabel', () => {
2021-11-11 11:23:49 +05:30
createComponent({ list: mockLabelList });
2020-11-24 15:15:51 +05:30
expect(findLabel().exists()).toBe(false);
});
2020-10-24 23:57:45 +05:30
});
2020-11-24 15:15:51 +05:30
});
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
describe('when sidebarType is not List', () => {
it('does not render GlDrawer', () => {
2021-11-11 11:23:49 +05:30
createComponent({ sidebarType: '' });
2020-11-24 15:15:51 +05:30
expect(findDrawer().exists()).toBe(false);
2020-10-24 23:57:45 +05:30
});
});
2021-04-29 21:17:54 +05:30
it('does not render "Remove list" when user cannot admin the boards list', () => {
createComponent();
expect(findRemoveButton().exists()).toBe(false);
});
describe('when user can admin the boards list', () => {
it('renders "Remove list" button', () => {
2021-11-11 11:23:49 +05:30
createComponent({ canAdminList: true, activeId: listId, list: mockLabelList });
2021-04-29 21:17:54 +05:30
expect(findRemoveButton().exists()).toBe(true);
});
2022-04-04 11:22:00 +05:30
it('has the correct ID on the button', () => {
createComponent({ canAdminList: true, activeId: listId, list: mockLabelList });
const binding = getBinding(findRemoveButton().element, 'gl-modal');
expect(binding.value).toBe(modalID);
});
it('has the correct ID on the modal', () => {
createComponent({ canAdminList: true, activeId: listId, list: mockLabelList });
expect(findModal().props('modalId')).toBe(modalID);
});
2021-04-29 21:17:54 +05:30
});
2020-10-24 23:57:45 +05:30
});