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

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

223 lines
6.5 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';
2023-07-09 08:55:56 +05:30
import VueApollo from 'vue-apollo';
2020-10-24 23:57:45 +05:30
import Vuex from 'vuex';
2023-07-09 08:55:56 +05:30
import createMockApollo from 'helpers/mock_apollo_helper';
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';
2023-07-09 08:55:56 +05:30
import destroyBoardListMutation from '~/boards/graphql/board_list_destroy.mutation.graphql';
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';
2023-07-09 08:55:56 +05:30
import { mockLabelList, destroyBoardListMutationResponse } from '../mock_data';
2020-10-24 23:57:45 +05:30
2023-07-09 08:55:56 +05:30
Vue.use(VueApollo);
2021-11-11 11:23:49 +05:30
Vue.use(Vuex);
2020-10-24 23:57:45 +05:30
describe('BoardSettingsSidebar', () => {
let wrapper;
2023-07-09 08:55:56 +05:30
let mockApollo;
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
2023-07-09 08:55:56 +05:30
const destroyBoardListMutationHandlerSuccess = jest
.fn()
.mockResolvedValue(destroyBoardListMutationResponse);
2021-11-11 11:23:49 +05:30
const createComponent = ({
canAdminList = false,
list = {},
sidebarType = LIST,
activeId = inactiveId,
2023-07-09 08:55:56 +05:30
isApolloBoard = false,
2021-11-11 11:23:49 +05:30
} = {}) => {
const boardLists = {
[listId]: list,
};
const store = new Vuex.Store({
state: { sidebarType, activeId, boardLists },
getters,
mutations,
actions,
});
2023-07-09 08:55:56 +05:30
mockApollo = createMockApollo([
[destroyBoardListMutation, destroyBoardListMutationHandlerSuccess],
]);
2021-04-29 21:17:54 +05:30
wrapper = extendedWrapper(
shallowMount(BoardSettingsSidebar, {
store,
2023-07-09 08:55:56 +05:30
apolloProvider: mockApollo,
2021-04-29 21:17:54 +05:30
provide: {
canAdminList,
2021-11-11 11:23:49 +05:30
scopedLabelsAvailable: false,
2023-01-13 00:05:48 +05:30
isIssueBoard: true,
2023-07-09 08:55:56 +05:30
boardType: 'group',
issuableType: 'issue',
isApolloBoard,
},
propsData: {
listId: list.id || '',
boardId: 'gid://gitlab/Board/1',
list,
queryVariables: {},
2021-11-11 11:23:49 +05:30
},
2022-04-04 11:22:00 +05:30
directives: {
2023-05-27 22:25:52 +05:30
GlModal: createMockDirective('gl-modal'),
2022-04-04 11:22:00 +05:30
},
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
},
}),
);
2023-07-09 08:55:56 +05:30
// Necessary for cache update
mockApollo.clients.defaultClient.cache.updateQuery = jest.fn();
2020-10-24 23:57:45 +05:30
};
2022-08-27 11:52:29 +05:30
const findLabel = () => wrapper.findComponent(GlLabel);
const findDrawer = () => wrapper.findComponent(GlDrawer);
const findModal = () => wrapper.findComponent(GlModal);
const findRemoveButton = () => wrapper.findComponent(GlButton);
2020-10-24 23:57:45 +05:30
afterEach(() => {
jest.restoreAllMocks();
});
2021-09-30 23:02:18 +05:30
it('finds a MountingPortal component', () => {
createComponent();
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(MountingPortal).props()).toMatchObject({
2021-09-30 23:02:18 +05:30
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
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(GlDrawer).props('open')).toBe(false);
2020-11-24 15:15:51 +05:30
});
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
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(GlDrawer).props('open')).toBe(false);
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 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: '' });
2022-08-27 11:52:29 +05:30
expect(findDrawer().props('open')).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
2023-07-09 08:55:56 +05:30
it('removes the list', () => {
createComponent({
canAdminList: true,
activeId: listId,
list: mockLabelList,
isApolloBoard: true,
});
findRemoveButton().vm.$emit('click');
wrapper.findComponent(GlModal).vm.$emit('primary');
expect(destroyBoardListMutationHandlerSuccess).toHaveBeenCalled();
});
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
});