forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apps_form_container.test.jsx
167 lines (146 loc) · 4.81 KB
/
apps_form_container.test.jsx
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {AppCallResponseTypes} from 'mattermost-redux/constants/apps';
import EmojiMap from 'utils/emoji_map';
import {shallowWithIntl} from 'tests/helpers/intl-test-helper';
import AppsFormContainer from './apps_form_container';
describe('components/apps_form/AppsFormContainer', () => {
const emojiMap = new EmojiMap(new Map());
const context = {
app_id: 'app',
channel_id: 'channel',
team_id: 'team',
post_id: 'post',
};
const baseProps = {
emojiMap,
form: {
title: 'Form Title',
header: 'Form Header',
fields: [
{
type: 'text',
name: 'field1',
value: 'initial_value_1',
},
{
type: 'static_select',
name: 'field2',
value: 'initial_value_2',
refresh: true,
},
],
},
call: {
context,
path: '/form_url',
},
actions: {
doAppCall: jest.fn().mockResolvedValue({}),
},
onExited: jest.fn(),
};
test('should match snapshot', () => {
const props = baseProps;
const wrapper = shallowWithIntl(<AppsFormContainer {...props}/>);
expect(wrapper).toMatchSnapshot();
});
describe('submitForm', () => {
test('should handle form submission result', async () => {
const response = {
data: {
type: AppCallResponseTypes.OK,
},
};
const props = {
...baseProps,
actions: {
...baseProps.actions,
doAppCall: jest.fn().mockResolvedValue(response),
},
};
const wrapper = shallowWithIntl(<AppsFormContainer {...props}/>);
const result = await wrapper.instance().submitForm({
values: {
field1: 'value1',
field2: {label: 'label2', value: 'value2'},
},
});
expect(props.actions.doAppCall).toHaveBeenCalledWith({
context: {
app_id: 'app',
channel_id: 'channel',
post_id: 'post',
team_id: 'team',
},
path: '/form_url',
expand: {},
values: {
field1: 'value1',
field2: {
label: 'label2',
value: 'value2',
},
},
}, 'submit', expect.any(Object));
expect(result).toEqual({
data: {
type: AppCallResponseTypes.OK,
},
});
});
});
describe('performLookupCall', () => {
test('should handle form user input', async () => {
const response = {
data: {
type: AppCallResponseTypes.OK,
data: {
items: [{
label: 'Fetched Label',
value: 'fetched_value',
}],
},
},
};
const props = {
...baseProps,
actions: {
...baseProps.actions,
doAppCall: jest.fn().mockResolvedValue(response),
},
};
const form = props.form;
const wrapper = shallowWithIntl(<AppsFormContainer {...props}/>);
const result = await wrapper.instance().performLookupCall(
form.fields[1],
{
field1: 'value1',
field2: {label: 'label2', value: 'value2'},
},
'My search',
);
expect(props.actions.doAppCall).toHaveBeenCalledWith({
context: {
app_id: 'app',
channel_id: 'channel',
post_id: 'post',
team_id: 'team',
},
path: '/form_url',
expand: {},
query: 'My search',
selected_field: 'field2',
values: {
field1: 'value1',
field2: {
label: 'label2',
value: 'value2',
},
},
}, 'lookup', expect.any(Object));
expect(result).toEqual(response);
});
});
});