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
|
import { GlDisclosureDropdownItem } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
// eslint-disable-next-line no-restricted-imports
import Vuex from 'vuex';
import { modalData } from 'jest/members/mock_data';
import RemoveMemberDropdownItem from '~/members/components/action_dropdowns/remove_member_dropdown_item.vue';
import { MEMBER_TYPES, MEMBER_MODEL_TYPE_GROUP_MEMBER } from '~/members/constants';
Vue.use(Vuex);
describe('RemoveMemberDropdownItem', () => {
let wrapper;
const text = 'dummy';
const actions = {
showRemoveMemberModal: jest.fn(),
};
const createStore = (state = {}) => {
return new Vuex.Store({
modules: {
[MEMBER_TYPES.user]: {
namespaced: true,
state: {
memberPath: '/groups/foo-bar/-/group_members/:id',
...state,
},
actions,
},
},
});
};
const createComponent = (propsData = {}, state) => {
wrapper = shallowMount(RemoveMemberDropdownItem, {
store: createStore(state),
provide: {
namespace: MEMBER_TYPES.user,
},
propsData: {
memberId: 1,
memberModelType: MEMBER_MODEL_TYPE_GROUP_MEMBER,
modalMessage: 'Are you sure you want to remove John Smith?',
isAccessRequest: true,
isInvite: true,
userDeletionObstacles: { name: 'user', obstacles: [] },
...propsData,
},
slots: {
default: text,
},
});
};
const findDropdownItem = () => wrapper.findComponent(GlDisclosureDropdownItem);
beforeEach(() => {
createComponent();
});
it('renders a slot with red text', () => {
expect(findDropdownItem().html()).toContain(`<span class="gl-text-red-500">${text}</span>`);
});
it('calls Vuex action to show `remove member` modal when clicked', () => {
findDropdownItem().vm.$emit('action');
expect(actions.showRemoveMemberModal).toHaveBeenCalledWith(expect.any(Object), {
...modalData,
preventRemoval: false,
});
});
});
|