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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
import { GlSkeletonLoader } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import MRPopover from '~/issuable/popover/components/mr_popover.vue';
import mergeRequestQuery from '~/issuable/popover/queries/merge_request.query.graphql';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
describe('MR Popover', () => {
let wrapper;
Vue.use(VueApollo);
const mrQueryResponse = {
data: {
project: {
__typename: 'Project',
id: '1',
mergeRequest: {
__typename: 'Merge Request',
id: 'gid://gitlab/Merge_Request/1',
createdAt: '2020-07-01T04:08:01Z',
state: 'opened',
title: 'MR title',
headPipeline: {
id: '1',
detailedStatus: {
id: '1',
icon: 'status_success',
group: 'success',
},
},
},
},
},
};
const mrQueryResponseWithoutDetailedStatus = {
data: {
project: {
__typename: 'Project',
id: '1',
mergeRequest: {
__typename: 'Merge Request',
id: 'gid://gitlab/Merge_Request/1',
createdAt: '2020-07-01T04:08:01Z',
state: 'opened',
title: 'MR title',
headPipeline: {
id: '1',
detailedStatus: null,
},
},
},
},
};
const mountComponent = ({
queryResponse = jest.fn().mockResolvedValue(mrQueryResponse),
} = {}) => {
wrapper = shallowMount(MRPopover, {
apolloProvider: createMockApollo([[mergeRequestQuery, queryResponse]]),
propsData: {
target: document.createElement('a'),
projectPath: 'foo/bar',
iid: '1',
cachedTitle: 'Cached Title',
},
});
};
it('shows skeleton-loader while apollo is loading', () => {
mountComponent();
expect(wrapper.findComponent(GlSkeletonLoader).exists()).toBe(true);
});
describe('when loaded', () => {
beforeEach(() => {
mountComponent();
return waitForPromises();
});
it('shows opened time', () => {
expect(wrapper.text()).toContain('Opened 4 days ago');
});
it('shows title', () => {
expect(wrapper.find('h5').text()).toBe(mrQueryResponse.data.project.mergeRequest.title);
});
it('shows reference', () => {
expect(wrapper.text()).toContain('foo/bar!1');
});
it('shows CI Icon if there is pipeline data', () => {
expect(wrapper.findComponent(CiIcon).exists()).toBe(true);
});
});
describe('without detailed status', () => {
beforeEach(() => {
mountComponent({
queryResponse: jest.fn().mockResolvedValue(mrQueryResponseWithoutDetailedStatus),
});
return waitForPromises();
});
it('does not show CI icon if there is no pipeline data', () => {
expect(wrapper.findComponent(CiIcon).exists()).toBe(false);
});
});
});
|