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
|
import { GlDropdownItem, GlModal } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import WorkItemActions from '~/work_items/components/work_item_actions.vue';
describe('WorkItemActions component', () => {
let wrapper;
let glModalDirective;
const findModal = () => wrapper.findComponent(GlModal);
const findDeleteButton = () => wrapper.findComponent(GlDropdownItem);
const createComponent = ({ canDelete = true } = {}) => {
glModalDirective = jest.fn();
wrapper = shallowMount(WorkItemActions, {
propsData: { workItemId: '123', canDelete },
directives: {
glModal: {
bind(_, { value }) {
glModalDirective(value);
},
},
},
});
};
afterEach(() => {
wrapper.destroy();
});
it('renders modal', () => {
createComponent();
expect(findModal().exists()).toBe(true);
expect(findModal().props('visible')).toBe(false);
});
it('shows confirm modal when clicking Delete work item', () => {
createComponent();
findDeleteButton().vm.$emit('click');
expect(glModalDirective).toHaveBeenCalled();
});
it('emits event when clicking OK button', () => {
createComponent();
findModal().vm.$emit('ok');
expect(wrapper.emitted('deleteWorkItem')).toEqual([[]]);
});
it('does not render when canDelete is false', () => {
createComponent({
canDelete: false,
});
expect(wrapper.html()).toBe('');
});
});
|