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
|
import { shallowMount } from '@vue/test-utils';
import WorkItemAssignees from '~/work_items/components/work_item_assignees.vue';
import WorkItemDueDate from '~/work_items/components/work_item_due_date.vue';
import WorkItemState from '~/work_items/components/work_item_state.vue';
import WorkItemLabels from '~/work_items/components/work_item_labels.vue';
import WorkItemMilestone from '~/work_items/components/work_item_milestone.vue';
import WorkItemAttributesWrapper from '~/work_items/components/work_item_attributes_wrapper.vue';
import { workItemResponseFactory } from '../mock_data';
describe('WorkItemAttributesWrapper component', () => {
let wrapper;
const workItemQueryResponse = workItemResponseFactory({ canUpdate: true, canDelete: true });
const findWorkItemState = () => wrapper.findComponent(WorkItemState);
const findWorkItemDueDate = () => wrapper.findComponent(WorkItemDueDate);
const findWorkItemAssignees = () => wrapper.findComponent(WorkItemAssignees);
const findWorkItemLabels = () => wrapper.findComponent(WorkItemLabels);
const findWorkItemMilestone = () => wrapper.findComponent(WorkItemMilestone);
const createComponent = ({ workItem = workItemQueryResponse.data.workItem } = {}) => {
wrapper = shallowMount(WorkItemAttributesWrapper, {
propsData: {
workItem,
},
provide: {
hasIssueWeightsFeature: true,
hasIterationsFeature: true,
hasOkrsFeature: true,
hasIssuableHealthStatusFeature: true,
projectNamespace: 'namespace',
fullPath: 'group/project',
},
stubs: {
WorkItemWeight: true,
WorkItemIteration: true,
WorkItemHealthStatus: true,
},
});
};
describe('work item state', () => {
it('renders the work item state', () => {
createComponent();
expect(findWorkItemState().exists()).toBe(true);
});
});
describe('assignees widget', () => {
it('renders assignees component when widget is returned from the API', () => {
createComponent();
expect(findWorkItemAssignees().exists()).toBe(true);
});
it('does not render assignees component when widget is not returned from the API', () => {
createComponent({
workItem: workItemResponseFactory({ assigneesWidgetPresent: false }).data.workItem,
});
expect(findWorkItemAssignees().exists()).toBe(false);
});
});
describe('labels widget', () => {
it.each`
description | labelsWidgetPresent | exists
${'renders when widget is returned from API'} | ${true} | ${true}
${'does not render when widget is not returned from API'} | ${false} | ${false}
`('$description', ({ labelsWidgetPresent, exists }) => {
const response = workItemResponseFactory({ labelsWidgetPresent });
createComponent({ workItem: response.data.workItem });
expect(findWorkItemLabels().exists()).toBe(exists);
});
});
describe('dates widget', () => {
describe.each`
description | datesWidgetPresent | exists
${'when widget is returned from API'} | ${true} | ${true}
${'when widget is not returned from API'} | ${false} | ${false}
`('$description', ({ datesWidgetPresent, exists }) => {
it(`${datesWidgetPresent ? 'renders' : 'does not render'} due date component`, () => {
const response = workItemResponseFactory({ datesWidgetPresent });
createComponent({ workItem: response.data.workItem });
expect(findWorkItemDueDate().exists()).toBe(exists);
});
});
});
describe('milestone widget', () => {
it.each`
description | milestoneWidgetPresent | exists
${'renders when widget is returned from API'} | ${true} | ${true}
${'does not render when widget is not returned from API'} | ${false} | ${false}
`('$description', ({ milestoneWidgetPresent, exists }) => {
const response = workItemResponseFactory({ milestoneWidgetPresent });
createComponent({ workItem: response.data.workItem });
expect(findWorkItemMilestone().exists()).toBe(exists);
});
});
});
|