-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathboardSummary.test.tsx
88 lines (76 loc) · 3.59 KB
/
boardSummary.test.tsx
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
import React from 'react';
import { shallow, ShallowWrapper} from 'enzyme';
import { DetailsList } from 'office-ui-fabric-react/lib/DetailsList';
import { mockWorkItem, mockWorkItemType } from '../__mocks__/mocked_components/mockedWorkItemTracking';
import BoardSummary, { IBoardSummaryProps } from '../boardSummary';
const mockedDefaultProps: IBoardSummaryProps = {
actionItems: [],
pendingWorkItemsCount: 0,
resolvedActionItemsCount: 0,
boardName: '',
feedbackItemsCount: 0,
supportedWorkItemTypes: []
};
const mockedWorkItemCountProps: IBoardSummaryProps = {
actionItems: [],
pendingWorkItemsCount: 2,
resolvedActionItemsCount: 3,
boardName: '',
feedbackItemsCount: 8,
supportedWorkItemTypes: []
};
describe('Board Summary', () => {
it('renders with no action or work items.', () => {
const wrapper = shallow(<BoardSummary {...mockedDefaultProps} /> as any);
const component = wrapper.children().dive();
verifySummaryBoardCounts(component, mockedDefaultProps);
verifyActionItemsSummaryCard(component, false);
});
it('renders with one action item.', () => {
mockedDefaultProps.actionItems.push(mockWorkItem);
mockedDefaultProps.supportedWorkItemTypes.push(mockWorkItemType);
const wrapper = shallow(<BoardSummary {...mockedDefaultProps} /> as any);
const component = wrapper.children().dive();
verifySummaryBoardCounts(component, mockedDefaultProps);
verifyActionItemsSummaryCard(component, true);
});
it('renders when work item counts are greater than zero.', () => {
const wrapper = shallow(<BoardSummary {...mockedWorkItemCountProps} /> as any);
const component = wrapper.children().dive();
verifySummaryBoardCounts(component, mockedWorkItemCountProps);
verifyActionItemsSummaryCard(component, false);
});
it('renders with one action item when work item counts are greater than zero.', () => {
mockedWorkItemCountProps.actionItems.push(mockWorkItem);
mockedWorkItemCountProps.supportedWorkItemTypes.push(mockWorkItemType);
const wrapper = shallow(<BoardSummary {...mockedWorkItemCountProps} /> as any);
const component = wrapper.children().dive();
verifySummaryBoardCounts(component, mockedWorkItemCountProps);
verifyActionItemsSummaryCard(component, true);
});
});
const verifySummaryBoardCounts = (component: ShallowWrapper, props: IBoardSummaryProps) => {
expect(component.findWhere(
child => child.prop("aria-label") === "feedback item count").text()).toBe(
props.feedbackItemsCount.toString());
expect(component.findWhere(
child => child.prop("aria-label") === "total work items count").text()).toBe(
(props.actionItems.length).toString());
expect(component.findWhere(
child => child.prop("aria-label") === "pending work items count").text()).toBe(
props.pendingWorkItemsCount.toString());
expect(component.findWhere(
child => child.prop("aria-label") === "resolved work items count").text()).toBe(
props.resolvedActionItemsCount.toString());
};
const verifyActionItemsSummaryCard = (component: ShallowWrapper, wereActionItemsInclude: boolean) => {
if(wereActionItemsInclude){
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const child = component.findWhere((child: any) => child.prop('className') === 'action-items-summary-card').children();
expect(child.find(DetailsList)).toHaveLength(1);
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(component.findWhere((child: any) => child.prop('className') === 'action-items-summary-card').
text()).toBe('Looks like no work items were created for this board.');
}
}