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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
import { GlAlert } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import VueApollo from 'vue-apollo';
import Draggable from 'vuedraggable';
import Vuex from 'vuex';
import waitForPromises from 'helpers/wait_for_promises';
import createMockApollo from 'helpers/mock_apollo_helper';
import EpicsSwimlanes from 'ee_component/boards/components/epics_swimlanes.vue';
import getters from 'ee_else_ce/boards/stores/getters';
import boardListsQuery from 'ee_else_ce/boards/graphql/board_lists.query.graphql';
import BoardColumn from '~/boards/components/board_column.vue';
import BoardContent from '~/boards/components/board_content.vue';
import BoardContentSidebar from '~/boards/components/board_content_sidebar.vue';
import { mockLists, boardListsQueryResponse } from '../mock_data';
Vue.use(VueApollo);
Vue.use(Vuex);
const actions = {
moveList: jest.fn(),
};
describe('BoardContent', () => {
let wrapper;
let fakeApollo;
window.gon = {};
const defaultState = {
isShowingEpicsSwimlanes: false,
boardLists: mockLists,
error: undefined,
issuableType: 'issue',
};
const createStore = (state = defaultState) => {
return new Vuex.Store({
actions,
getters,
state,
});
};
const createComponent = ({
state,
props = {},
canAdminList = true,
isApolloBoard = false,
issuableType = 'issue',
boardListQueryHandler = jest.fn().mockResolvedValue(boardListsQueryResponse),
} = {}) => {
fakeApollo = createMockApollo([[boardListsQuery, boardListQueryHandler]]);
const store = createStore({
...defaultState,
...state,
});
wrapper = shallowMount(BoardContent, {
apolloProvider: fakeApollo,
propsData: {
disabled: false,
boardId: 'gid://gitlab/Board/1',
...props,
},
provide: {
canAdminList,
boardType: 'group',
fullPath: 'gitlab-org/gitlab',
issuableType,
isApolloBoard,
},
store,
});
};
beforeAll(() => {
global.ResizeObserver = class MockResizeObserver {
constructor(callback) {
this.callback = callback;
this.entries = [];
}
observe(entry) {
this.entries.push(entry);
}
disconnect() {
this.entries = [];
this.callback = null;
}
trigger() {
this.callback(this.entries);
}
};
});
afterEach(() => {
wrapper.destroy();
fakeApollo = null;
});
describe('default', () => {
beforeEach(() => {
createComponent();
});
it('renders a BoardColumn component per list', () => {
expect(wrapper.findAllComponents(BoardColumn)).toHaveLength(mockLists.length);
});
it('renders BoardContentSidebar', () => {
expect(wrapper.findComponent(BoardContentSidebar).exists()).toBe(true);
});
it('does not display EpicsSwimlanes component', () => {
expect(wrapper.findComponent(EpicsSwimlanes).exists()).toBe(false);
expect(wrapper.findComponent(GlAlert).exists()).toBe(false);
});
it('resizes the list on resize', async () => {
window.innerHeight = 1000;
jest.spyOn(Element.prototype, 'getBoundingClientRect').mockReturnValue({ top: 100 });
wrapper.vm.resizeObserver.trigger();
await nextTick();
expect(wrapper.findComponent({ ref: 'list' }).attributes('style')).toBe('height: 900px;');
});
});
describe('when issuableType is not issue', () => {
beforeEach(() => {
createComponent({ issuableType: 'foo' });
});
it('does not render BoardContentSidebar', () => {
expect(wrapper.findComponent(BoardContentSidebar).exists()).toBe(false);
});
});
describe('can admin list', () => {
beforeEach(() => {
createComponent({ canAdminList: true });
});
it('renders draggable component', () => {
expect(wrapper.findComponent(Draggable).exists()).toBe(true);
});
});
describe('can not admin list', () => {
beforeEach(() => {
createComponent({ canAdminList: false });
});
it('does not render draggable component', () => {
expect(wrapper.findComponent(Draggable).exists()).toBe(false);
});
});
describe('when Apollo boards FF is on', () => {
beforeEach(async () => {
createComponent({ isApolloBoard: true });
await waitForPromises();
});
it('renders a BoardColumn component per list', () => {
expect(wrapper.findAllComponents(BoardColumn)).toHaveLength(mockLists.length);
});
it('renders BoardContentSidebar', () => {
expect(wrapper.findComponent(BoardContentSidebar).exists()).toBe(true);
});
});
});
|