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
|
import { GlCollapsibleListbox } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
import Vuex from 'vuex';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import BranchesDropdown from '~/projects/commit/components/branches_dropdown.vue';
Vue.use(Vuex);
describe('BranchesDropdown', () => {
let wrapper;
let store;
const spyFetchBranches = jest.fn();
const createComponent = (props, state = { isFetching: false }) => {
store = new Vuex.Store({
getters: {
joinedBranches: () => ['_main_', '_branch_1_', '_branch_2_'],
},
actions: {
fetchBranches: spyFetchBranches,
},
state,
});
wrapper = extendedWrapper(
shallowMount(BranchesDropdown, {
store,
propsData: {
value: props.value,
blanked: props.blanked || false,
},
}),
);
};
const findDropdown = () => wrapper.findComponent(GlCollapsibleListbox);
beforeEach(() => {
createComponent({ value: '' });
});
afterEach(() => {
wrapper.destroy();
wrapper = null;
spyFetchBranches.mockReset();
});
describe('On mount', () => {
it('invokes fetchBranches', () => {
expect(spyFetchBranches).toHaveBeenCalled();
});
});
describe('Value prop changes in parent component', () => {
it('triggers fetchBranches call', async () => {
await wrapper.setProps({ value: 'new value' });
expect(spyFetchBranches).toHaveBeenCalled();
});
});
describe('Selecting Dropdown Item', () => {
it('emits event', async () => {
findDropdown().vm.$emit('select', '_anything_');
expect(wrapper.emitted()).toHaveProperty('input');
});
});
describe('When searching', () => {
it('invokes fetchBranches', async () => {
const spy = jest.spyOn(wrapper.vm, 'fetchBranches');
findDropdown().vm.$emit('search', '_anything_');
await nextTick();
expect(spy).toHaveBeenCalledWith('_anything_');
});
});
});
|