1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
import Vuex from 'vuex';
import createMockApollo from 'helpers/mock_apollo_helper';
import BoardTopBar from '~/boards/components/board_top_bar.vue';
import BoardAddNewColumnTrigger from '~/boards/components/board_add_new_column_trigger.vue';
import BoardsSelector from '~/boards/components/boards_selector.vue';
import ConfigToggle from '~/boards/components/config_toggle.vue';
import IssueBoardFilteredSearch from '~/boards/components/issue_board_filtered_search.vue';
import NewBoardButton from '~/boards/components/new_board_button.vue';
import ToggleFocus from '~/boards/components/toggle_focus.vue';
import { WORKSPACE_GROUP, WORKSPACE_PROJECT } from '~/issues/constants';
import groupBoardQuery from '~/boards/graphql/group_board.query.graphql';
import projectBoardQuery from '~/boards/graphql/project_board.query.graphql';
import { mockProjectBoardResponse, mockGroupBoardResponse } from '../mock_data';
Vue.use(VueApollo);
Vue.use(Vuex);
describe('BoardTopBar', () => {
let wrapper;
let mockApollo;
const createStore = () => {
return new Vuex.Store({
state: {},
});
};
const projectBoardQueryHandlerSuccess = jest.fn().mockResolvedValue(mockProjectBoardResponse);
const groupBoardQueryHandlerSuccess = jest.fn().mockResolvedValue(mockGroupBoardResponse);
const createComponent = ({ provide = {} } = {}) => {
const store = createStore();
mockApollo = createMockApollo([
[projectBoardQuery, projectBoardQueryHandlerSuccess],
[groupBoardQuery, groupBoardQueryHandlerSuccess],
]);
wrapper = shallowMount(BoardTopBar, {
store,
apolloProvider: mockApollo,
propsData: {
boardId: 'gid://gitlab/Board/1',
isSwimlanesOn: false,
},
provide: {
swimlanesFeatureAvailable: false,
canAdminList: false,
isSignedIn: false,
fullPath: 'gitlab-org',
boardType: 'group',
releasesFetchPath: '/releases',
isIssueBoard: true,
isEpicBoard: false,
isGroupBoard: true,
isApolloBoard: false,
...provide,
},
stubs: { IssueBoardFilteredSearch },
});
};
afterEach(() => {
mockApollo = null;
});
describe('base template', () => {
beforeEach(() => {
createComponent();
});
it('renders BoardsSelector component', () => {
expect(wrapper.findComponent(BoardsSelector).exists()).toBe(true);
});
it('renders IssueBoardFilteredSearch component', () => {
expect(wrapper.findComponent(IssueBoardFilteredSearch).exists()).toBe(true);
});
it('renders NewBoardButton component', () => {
expect(wrapper.findComponent(NewBoardButton).exists()).toBe(true);
});
it('renders ConfigToggle component', () => {
expect(wrapper.findComponent(ConfigToggle).exists()).toBe(true);
});
it('renders ToggleFocus component', () => {
expect(wrapper.findComponent(ToggleFocus).exists()).toBe(true);
});
it('does not render BoardAddNewColumnTrigger component', () => {
expect(wrapper.findComponent(BoardAddNewColumnTrigger).exists()).toBe(false);
});
it('emits setFilters when setFilters is emitted by filtered search', () => {
wrapper.findComponent(IssueBoardFilteredSearch).vm.$emit('setFilters');
expect(wrapper.emitted('setFilters')).toHaveLength(1);
});
});
describe('when user can admin list', () => {
beforeEach(() => {
createComponent({ provide: { canAdminList: true } });
});
it('renders BoardAddNewColumnTrigger component', () => {
expect(wrapper.findComponent(BoardAddNewColumnTrigger).exists()).toBe(true);
});
});
describe('Apollo boards', () => {
it.each`
boardType | queryHandler | notCalledHandler
${WORKSPACE_GROUP} | ${groupBoardQueryHandlerSuccess} | ${projectBoardQueryHandlerSuccess}
${WORKSPACE_PROJECT} | ${projectBoardQueryHandlerSuccess} | ${groupBoardQueryHandlerSuccess}
`('fetches $boardType boards', async ({ boardType, queryHandler, notCalledHandler }) => {
createComponent({
provide: {
boardType,
isProjectBoard: boardType === WORKSPACE_PROJECT,
isGroupBoard: boardType === WORKSPACE_GROUP,
isApolloBoard: true,
},
});
await nextTick();
expect(queryHandler).toHaveBeenCalled();
expect(notCalledHandler).not.toHaveBeenCalled();
});
});
});
|