2021-04-29 21:17:54 +05:30
|
|
|
import { GlDrawer } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { MountingPortal } from 'portal-vue';
|
2022-01-26 12:08:38 +05:30
|
|
|
import Vue from 'vue';
|
2021-04-29 21:17:54 +05:30
|
|
|
import Vuex from 'vuex';
|
2021-09-04 01:27:46 +05:30
|
|
|
import SidebarDropdownWidget from 'ee_else_ce/sidebar/components/sidebar_dropdown_widget.vue';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { stubComponent } from 'helpers/stub_component';
|
|
|
|
import BoardContentSidebar from '~/boards/components/board_content_sidebar.vue';
|
|
|
|
import BoardSidebarTitle from '~/boards/components/sidebar/board_sidebar_title.vue';
|
2023-03-17 16:20:25 +05:30
|
|
|
import { ISSUABLE, issuableTypes } from '~/boards/constants';
|
2021-09-04 01:27:46 +05:30
|
|
|
import SidebarDateWidget from '~/sidebar/components/date/sidebar_date_widget.vue';
|
2022-03-02 08:16:31 +05:30
|
|
|
import SidebarSeverity from '~/sidebar/components/severity/sidebar_severity.vue';
|
2021-06-08 01:23:25 +05:30
|
|
|
import SidebarSubscriptionsWidget from '~/sidebar/components/subscriptions/sidebar_subscriptions_widget.vue';
|
2021-09-30 23:02:18 +05:30
|
|
|
import SidebarTodoWidget from '~/sidebar/components/todo_toggle/sidebar_todo_widget.vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import SidebarLabelsWidget from '~/sidebar/components/labels/labels_select_widget/labels_select_root.vue';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { mockActiveIssue, mockIssue, mockIssueGroupPath, mockIssueProjectPath } from '../mock_data';
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
Vue.use(Vuex);
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('BoardContentSidebar', () => {
|
|
|
|
let wrapper;
|
|
|
|
let store;
|
|
|
|
|
|
|
|
const createStore = ({ mockGetters = {}, mockActions = {} } = {}) => {
|
|
|
|
store = new Vuex.Store({
|
|
|
|
state: {
|
|
|
|
sidebarType: ISSUABLE,
|
|
|
|
issues: { [mockIssue.id]: { ...mockIssue, epic: null } },
|
|
|
|
activeId: mockIssue.id,
|
|
|
|
},
|
|
|
|
getters: {
|
|
|
|
activeBoardItem: () => {
|
2021-09-30 23:02:18 +05:30
|
|
|
return { ...mockActiveIssue, epic: null };
|
2021-04-29 21:17:54 +05:30
|
|
|
},
|
|
|
|
groupPathForActiveIssue: () => mockIssueGroupPath,
|
|
|
|
projectPathForActiveIssue: () => mockIssueProjectPath,
|
|
|
|
isSidebarOpen: () => true,
|
|
|
|
...mockGetters,
|
|
|
|
},
|
|
|
|
actions: mockActions,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const createComponent = () => {
|
|
|
|
/*
|
|
|
|
Dynamically imported components (in our case ee imports)
|
|
|
|
aren't stubbed automatically in VTU v1:
|
|
|
|
https://github.com/vuejs/vue-test-utils/issues/1279.
|
|
|
|
|
|
|
|
This requires us to additionally mock apollo or vuex stores.
|
|
|
|
*/
|
|
|
|
wrapper = shallowMount(BoardContentSidebar, {
|
|
|
|
provide: {
|
|
|
|
canUpdate: true,
|
|
|
|
rootPath: '/',
|
|
|
|
groupId: 1,
|
2023-03-17 16:20:25 +05:30
|
|
|
issuableType: issuableTypes.issue,
|
|
|
|
isGroupBoard: false,
|
2021-04-29 21:17:54 +05:30
|
|
|
},
|
|
|
|
store,
|
|
|
|
stubs: {
|
|
|
|
GlDrawer: stubComponent(GlDrawer, {
|
|
|
|
template: '<div><slot name="header"></slot><slot></slot></div>',
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
mocks: {
|
|
|
|
$apollo: {
|
|
|
|
queries: {
|
|
|
|
participants: {
|
|
|
|
loading: false,
|
|
|
|
},
|
|
|
|
currentIteration: {
|
|
|
|
loading: false,
|
|
|
|
},
|
|
|
|
iterations: {
|
|
|
|
loading: false,
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
attributesList: {
|
|
|
|
loading: false,
|
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
createStore();
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('confirms we render GlDrawer', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(wrapper.findComponent(GlDrawer).exists()).toBe(true);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it('confirms we render MountingPortal', () => {
|
2022-03-02 08:16:31 +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-content-sidebar',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('does not render GlDrawer when isSidebarOpen is false', () => {
|
|
|
|
createStore({ mockGetters: { isSidebarOpen: () => false } });
|
|
|
|
createComponent();
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlDrawer).props('open')).toBe(false);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('applies an open attribute', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(wrapper.findComponent(GlDrawer).props('open')).toBe(true);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it('renders SidebarTodoWidget', () => {
|
|
|
|
expect(wrapper.findComponent(SidebarTodoWidget).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it('renders SidebarLabelsWidget', () => {
|
|
|
|
expect(wrapper.findComponent(SidebarLabelsWidget).exists()).toBe(true);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders BoardSidebarTitle', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(wrapper.findComponent(BoardSidebarTitle).exists()).toBe(true);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it('renders SidebarDateWidget', () => {
|
|
|
|
expect(wrapper.findComponent(SidebarDateWidget).exists()).toBe(true);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('renders BoardSidebarSubscription', () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
expect(wrapper.findComponent(SidebarSubscriptionsWidget).exists()).toBe(true);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
it('renders SidebarDropdownWidget for milestones', () => {
|
|
|
|
expect(wrapper.findComponent(SidebarDropdownWidget).exists()).toBe(true);
|
|
|
|
expect(wrapper.findComponent(SidebarDropdownWidget).props('issuableAttribute')).toEqual(
|
|
|
|
'milestone',
|
|
|
|
);
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
it('does not render SidebarSeverity', () => {
|
|
|
|
expect(wrapper.findComponent(SidebarSeverity).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('does not render SidebarHealthStatusWidget', async () => {
|
|
|
|
const SidebarHealthStatusWidget = (
|
|
|
|
await import('ee_component/sidebar/components/health_status/sidebar_health_status_widget.vue')
|
|
|
|
).default;
|
|
|
|
expect(wrapper.findComponent(SidebarHealthStatusWidget).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not render SidebarWeightWidget', async () => {
|
|
|
|
const SidebarWeightWidget = (
|
|
|
|
await import('ee_component/sidebar/components/weight/sidebar_weight_widget.vue')
|
|
|
|
).default;
|
|
|
|
expect(wrapper.findComponent(SidebarWeightWidget).exists()).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
describe('when we emit close', () => {
|
|
|
|
let toggleBoardItem;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
toggleBoardItem = jest.fn();
|
|
|
|
createStore({ mockActions: { toggleBoardItem } });
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('calls toggleBoardItem with correct parameters', async () => {
|
2021-09-04 01:27:46 +05:30
|
|
|
wrapper.findComponent(GlDrawer).vm.$emit('close');
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
expect(toggleBoardItem).toHaveBeenCalledTimes(1);
|
|
|
|
expect(toggleBoardItem).toHaveBeenCalledWith(expect.any(Object), {
|
2021-09-30 23:02:18 +05:30
|
|
|
boardItem: { ...mockActiveIssue, epic: null },
|
2021-04-29 21:17:54 +05:30
|
|
|
sidebarType: ISSUABLE,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
describe('incident sidebar', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createStore({
|
|
|
|
mockGetters: { activeBoardItem: () => ({ ...mockIssue, epic: null, type: 'INCIDENT' }) },
|
|
|
|
});
|
|
|
|
createComponent();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders SidebarSeverity', () => {
|
|
|
|
expect(wrapper.findComponent(SidebarSeverity).exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2021-04-29 21:17:54 +05:30
|
|
|
});
|