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
|
import { createWrapper } from '@vue/test-utils';
import MembersTabs from '~/members/components/members_tabs.vue';
import { MEMBER_TYPES } from '~/members/constants';
import { initMembersApp } from '~/members/index';
import { members, pagination, dataAttribute } from './mock_data';
describe('initMembersApp', () => {
let el;
let vm;
let wrapper;
const setup = () => {
vm = initMembersApp(el, {
[MEMBER_TYPES.user]: {
tableFields: ['account'],
tableAttrs: { table: { 'data-qa-selector': 'members_list' } },
tableSortableFields: ['account'],
requestFormatter: () => ({}),
filteredSearchBar: { show: false },
},
});
wrapper = createWrapper(vm);
};
beforeEach(() => {
el = document.createElement('div');
el.dataset.membersData = dataAttribute;
window.gon = { current_user_id: 123 };
});
afterEach(() => {
el = null;
});
it('renders `MembersTabs`', () => {
setup();
expect(wrapper.findComponent(MembersTabs).exists()).toBe(true);
});
it('parses and sets `members` in Vuex store', () => {
setup();
expect(vm.$store.state[MEMBER_TYPES.user].members).toEqual(members);
});
it('parses and sets `pagination` in Vuex store', () => {
setup();
expect(vm.$store.state[MEMBER_TYPES.user].pagination).toEqual(pagination);
});
it('sets `tableFields` in Vuex store', () => {
setup();
expect(vm.$store.state[MEMBER_TYPES.user].tableFields).toEqual(['account']);
});
it('sets `tableAttrs` in Vuex store', () => {
setup();
expect(vm.$store.state[MEMBER_TYPES.user].tableAttrs).toEqual({
table: { 'data-qa-selector': 'members_list' },
});
});
it('sets `tableSortableFields` in Vuex store', () => {
setup();
expect(vm.$store.state[MEMBER_TYPES.user].tableSortableFields).toEqual(['account']);
});
it('sets `requestFormatter` in Vuex store', () => {
setup();
expect(vm.$store.state[MEMBER_TYPES.user].requestFormatter()).toEqual({});
});
it('sets `filteredSearchBar` in Vuex store', () => {
setup();
expect(vm.$store.state[MEMBER_TYPES.user].filteredSearchBar).toEqual({ show: false });
});
it('sets `memberPath` in Vuex store', () => {
setup();
expect(vm.$store.state[MEMBER_TYPES.user].memberPath).toBe(
'/groups/foo-bar/-/group_members/:id',
);
});
});
|