-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathconnect.test.js
269 lines (258 loc) · 9.36 KB
/
connect.test.js
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
import sinon from 'sinon';
import { readFile } from '@web/test-runner-commands';
import { setLibs, getLibs } from '../../../../creativecloud/scripts/utils.js';
import { expect } from '@esm-bundle/chai';
const miloLibs = '/libs';
setLibs(miloLibs);
const { setConfig } = await import(`${getLibs()}/utils/utils.js`);
const CONFIG = {
stage: { odinEndpoint: 'https://stage-odin.adobe.com/' },
live: { odinEndpoint: 'https://stage-odin.adobe.com/' },
prod: { odinEndpoint: 'https://odin.adobe.com/' },
};
setConfig(CONFIG);
window.adobeIMS = {
initialized: true,
getProfile: () => {
const pr = new Promise((res) => res({ countryCode: 'US', userId: 'mathuria' }));
return pr;
},
isSignedInUser: () => true,
getAccessToken: () => 'token',
adobeid: { locale: 'en' },
};
window.adobeid = {
api_parameters: {},
locale: 'en',
};
window.digitalData = {};
window.alloy_all = { 'data': { '_adobe_corpnew' : { 'digitalData' : {}}}};
function delay(ms) {
return new Promise((res) => { setTimeout(() => { res(); }, ms); });
}
const { default: init } = await import('../../../../creativecloud/blocks/cc-forms/cc-forms.js');
document.body.innerHTML = await readFile({ path: './mocks/connect-body.html' });
describe('ConnectTrials Form', () => {
const fetchStub = sinon.stub(window, 'fetch');
before(async () => {
const el = document.querySelector('.cc-forms');
fetchStub.callsFake((url) => {
let payload = {};
if (url.includes('countries')) {
payload = {'data':{'countryList':{'items':[{'_path':'/content/dam/acom/country/us/en/US','id':'US','title':'United States','value':'US','isTop':false},{'_path':'/content/dam/acom/country/us/en/IN','id':'IN','title':'India','value':'IN','isTop':false}]}}};
}
if (url.includes('connectregions')) {
payload = {
"data": {
"formfieldvaluesList": {
"items": [
{
"id": 2,
"title": "United States/Canada",
"value": "0"
},
{
"id": 0,
"title": "Asia Pacific",
"value": "20"
},
{
"id": 1,
"title": "EMEA",
"value": "10"
},
{
"id": 3,
"title": "Rest of the World",
"value": "30"
}
]
}
}
};
}
if (url.includes('timezone')) {
payload = {
"data": {
"formfieldvaluesList": {
"items": [
{
"id": 0,
"title": "(GMT-12:00) International Date Line West",
"value": "0"
},
{
"id": 1,
"title": "(GMT-11:00) Midway Island, Samoa",
"value": "1"
},
{
"id": 95,
"title": "(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague",
"value": "95"
}
]
}
}
};
}
if (url.includes('orgsize')) {
payload = {
"data": {
"formfieldvaluesList": {
"items": [
{
"id": 1,
"title": "10-99",
"value": "10-99"
},
{
"id": 2,
"title": "100-499",
"value": "100-499"
},
{
"id": 4,
"title": "1000-4999",
"value": "1000-4999"
},
{
"id": 0,
"title": "1-9",
"value": "1-9"
},
{
"id": 3,
"title": "500-999",
"value": "500-999"
},
{
"id": 5,
"title": "5000+",
"value": "5000+"
}
]
}
}
};
}
if (url.includes('industry')) {
payload = {
"data": {
"formfieldvaluesList": {
"items": [
{
"id": 1,
"title": "Advertising",
"value": "ADVERTISING"
},
{
"id": 40,
"title": "Agriculture & Forestry",
"value": "AGRICULTURE_AND_FORESTRY"
},
{
"id": 41,
"title": "Construction",
"value": "CONSTRUCTION"
},
{
"id": 56,
"title": "Education - Higher Ed",
"value": "EDUCATION_HIGHER_ED"
},
{
"id": 53,
"title": "Utilities",
"value": "UTILITIES"
}
]
}
}
}
}
if (url.includes('jobfunction')) {
payload = {
"data": {
"formfieldvaluesList": {
"items": [
{
"id": 1,
"title": "Accounting/Finance",
"value": "ACCOUNTING_FINANCE"
},
{
"id": 2,
"title": "Administrative Support",
"value": "ADMINISTRATIVE_SUPPORT"
},
{
"id": 66,
"title": "Training and Development",
"value": "TRAINING_AND_DEVELOPMENT"
}
]
}
}
}
}
if (url.includes('connecttrialpurchaseintent')) {
payload = {
"data": {
"formfieldvaluesList": {
"items": [
{
"id": 0,
"title": "Adobe Connect Learning",
"value": "learning"
},
{
"id": 0,
"title": "Adobe Connect Webinar",
"value": "webinars"
}
]
}
}
};
}
return Promise.resolve({
json: async () => payload,
status: 200,
ok: true,
});
});
await init(el);
await delay(1000);
});
after(() => {
fetchStub.restore();
});
it('Consent should be monitored', () => {
const checkbox1 = document.body.querySelector('#consentexplicitemail');
expect(checkbox1).to.exist;
});
it('Text patterns should be validated', () => {
const postalcode = document.body.querySelector('#postalcode');
postalcode.value = 'postal code';
postalcode.dispatchEvent(new Event('input'));
});
it('Submit check', () => {
document.body.querySelector('#email').value = 'email@gmail.com';
document.body.querySelector('#fname').value = 'val';
document.body.querySelector('#lname').value = 'val';
document.body.querySelector('#phonenumber').value = 'val';
document.body.querySelector('#orgname').value = 'val';
document.body.querySelector('#country').selectedIndex = 1;
document.body.querySelector('#state').selectedIndex = 1;
document.body.querySelector('#postalcode').value = 'val';
document.body.querySelector('#region').selectedIndex = 1;
document.body.querySelector('#timezone').selectedIndex = 1;
document.body.querySelector('#orgsize').selectedIndex = 1;
document.body.querySelector('#industry').selectedIndex = 1;
document.body.querySelector('#jobfunction').selectedIndex = 1;
document.body.querySelector('#connectpurchaseintent').selectedIndex = 1;
document.body.querySelector('#accept-agreement').checked = true;
document.body.querySelector('.cc-form-component.submit').dispatchEvent(new Event('click'));
});
});