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
|
import { GlButton } from '@gitlab/ui';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import IssuableEditActions from '~/issues/show/components/edit_actions.vue';
import eventHub from '~/issues/show/event_hub';
describe('Edit Actions component', () => {
let wrapper;
let fakeApollo;
let mockIssueStateData;
Vue.use(VueApollo);
const mockResolvers = {
Query: {
issueState() {
return {
__typename: 'IssueState',
rawData: mockIssueStateData(),
};
},
},
};
const createComponent = ({ props, data } = {}) => {
fakeApollo = createMockApollo([], mockResolvers);
wrapper = shallowMountExtended(IssuableEditActions, {
apolloProvider: fakeApollo,
propsData: {
formState: {
title: 'GitLab Issue',
},
canDestroy: true,
endpoint: 'gitlab-org/gitlab-test/-/issues/1',
issuableType: 'issue',
...props,
},
data() {
return {
issueState: {},
...data,
};
},
});
};
const findEditButtons = () => wrapper.findAllComponents(GlButton);
const findSaveButton = () => wrapper.findByTestId('issuable-save-button');
const findCancelButton = () => wrapper.findByTestId('issuable-cancel-button');
beforeEach(() => {
mockIssueStateData = jest.fn();
createComponent();
});
it('renders all buttons as enabled', () => {
const buttons = findEditButtons().wrappers;
buttons.forEach((button) => {
expect(button.attributes('disabled')).toBeUndefined();
});
});
it('disables save button when title is blank', () => {
createComponent({ props: { formState: { title: '', issue_type: '' } } });
expect(findSaveButton().attributes('disabled')).toBe('true');
});
describe('updateIssuable', () => {
beforeEach(() => {
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
});
it('sends update.issauble event when clicking save button', () => {
findSaveButton().vm.$emit('click', { preventDefault: jest.fn() });
expect(eventHub.$emit).toHaveBeenCalledWith('update.issuable');
});
});
describe('closeForm', () => {
beforeEach(() => {
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
});
it('emits close.form when clicking cancel', () => {
findCancelButton().vm.$emit('click');
expect(eventHub.$emit).toHaveBeenCalledWith('close.form');
});
});
});
|