This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
next_steps_view.test.tsx
126 lines (111 loc) · 3.86 KB
/
next_steps_view.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
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
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow, ShallowWrapper} from 'enzyme';
import NextStepsView from 'components/next_steps_view/next_steps_view';
import {TestHelper} from 'utils/test_helper';
describe('components/next_steps_view', () => {
const baseProps = {
steps: [
{
id: 'step_1',
roles: [],
title: 'Step_1',
component: jest.fn(),
},
{
id: 'step_2',
title: 'Step_2',
roles: [],
component: jest.fn(),
},
{
id: 'step_3',
title: 'Step_3',
roles: [],
component: jest.fn(),
},
],
currentUser: TestHelper.getUserMock(),
preferences: [],
isFirstAdmin: true,
actions: {
setShowNextStepsView: jest.fn(),
savePreferences: jest.fn(),
closeRightHandSide: jest.fn(),
getProfiles: jest.fn(),
},
};
test('should match snapshot', () => {
const wrapper = shallow(
<NextStepsView {...baseProps}/>,
);
wrapper.setState({show: true});
expect(wrapper).toMatchSnapshot();
});
test('should return complete if pref exists', () => {
const props = {
...baseProps,
preferences: [{
category: 'recommended_next_steps',
name: 'step_1',
user_id: 'user_id',
value: 'true',
}],
};
const wrapper: ShallowWrapper<any, any, NextStepsView> = shallow(
<NextStepsView {...props}/>,
);
expect(wrapper.instance().isStepComplete('step_1')).toBe(true);
expect(wrapper.instance().isStepComplete('step_2')).toBe(false);
});
test('should expand next step when previous step is marked complete', () => {
const wrapper: ShallowWrapper<any, any, NextStepsView> = shallow(
<NextStepsView {...baseProps}/>,
);
const setExpanded = jest.fn();
wrapper.instance().nextStep(setExpanded, 'step_1');
expect(setExpanded).toBeCalledWith('step_2');
});
test('should go to first incomplete step when last step is marked complete', () => {
const wrapper: ShallowWrapper<any, any, NextStepsView> = shallow(
<NextStepsView {...baseProps}/>,
);
const setExpanded = jest.fn();
wrapper.instance().nextStep(setExpanded, 'step_3');
expect(setExpanded).toBeCalledWith('step_1');
});
test('should cascade through all steps when all marked complete', () => {
const props = {
...baseProps,
preferences: [
{
category: 'recommended_next_steps',
name: 'step_1',
user_id: 'user_id',
value: 'true',
},
{
category: 'recommended_next_steps',
name: 'step_2',
user_id: 'user_id',
value: 'true',
},
{
category: 'recommended_next_steps',
name: 'step_3',
user_id: 'user_id',
value: 'true',
},
],
};
jest.useFakeTimers();
const wrapper: ShallowWrapper<any, any, NextStepsView> = shallow(
<NextStepsView {...props}/>,
);
wrapper.instance().transitionToFinalScreen = jest.fn();
wrapper.instance().nextStep(jest.fn(), 'step_1');
jest.runOnlyPendingTimers();
expect(wrapper.instance().transitionToFinalScreen).toBeCalled();
});
});