-
Notifications
You must be signed in to change notification settings - Fork 857
/
Copy pathcheckboxes.js
530 lines (470 loc) · 17.5 KB
/
checkboxes.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
// import { frameworks, url, setOptions, initSurvey, getSurveyResult, getQuestionValue, getQuestionJson, checkSurveyWithEmptyQuestion, getData, setRowItemFlowDirection } from "../helper";
// import { Selector, ClientFunction, fixture, test } from "testcafe";
// // eslint-disable-next-line no-undef
// const assert = require("assert");
// const title = "checkboxes";
// const columnClassName = ".sd-selectbase__column";
// const checkboxControlClassName = ".sd-checkbox__control";
// const json = {
// elements: [
// {
// type: "checkbox",
// name: "car",
// title: "What car are you driving?",
// isRequired: true,
// colCount: 4,
// hasOther: true,
// hasNone: true,
// choices: [
// "Unknown",
// "Ford",
// "Vauxhall",
// "Volkswagen",
// "Nissan",
// "Audi",
// "Mercedes-Benz",
// "BMW",
// "Peugeot",
// "Toyota",
// "Citroen",
// ],
// },
// ],
// };
// const controlLabelSelector = Selector(".sd-item__control-label");
// frameworks.forEach((framework) => {
// fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
// async (ctx) => {
// await initSurvey(framework, json);
// }
// );
// test("choose empty", async (t) => {
// await checkSurveyWithEmptyQuestion(t);
// });
// test("choose none", async (t) => {
// let surveyResult;
// await t
// .click(controlLabelSelector.withText("Nissan"))
// .click(controlLabelSelector.withText("Audi"))
// .click(controlLabelSelector.withText("Vauxhall"))
// .click(controlLabelSelector.withText("None"))
// .click("input[value=Complete]");
// surveyResult = await getSurveyResult();
// await t.expect(surveyResult.car).eql(["none"]);
// });
// test("choose value", async (t) => {
// let surveyResult;
// await t
// .click(controlLabelSelector.withText("Nissan"))
// .click("input[value=Complete]");
// surveyResult = await getSurveyResult();
// assert.equal(surveyResult.car, "Nissan");
// });
// test("choose several values", async (t) => {
// let surveyResult;
// await t
// .click(controlLabelSelector.withText("BMW"))
// .click(controlLabelSelector.withText("Nissan"))
// .click("input[value=Complete]");
// surveyResult = await getSurveyResult();
// await t.expect(surveyResult.car).eql(["BMW", "Nissan"]);
// });
// test("change column count", async (t) => {
// const getClassName = ClientFunction(
// () => document.querySelector("div[id*=sq_1] fieldset > div > div").className
// );
// let className = await getClassName();
// assert.notEqual(className.indexOf("sv-q-column-4"), -1);
// await setOptions("car", { colCount: 1 });
// const getClassNameOneCol = ClientFunction(
// () => document.querySelector("div[id*=sq_1] fieldset > div").className
// );
// className = await getClassNameOneCol();
// assert.notEqual(className.indexOf("sv-q-col-1"), -1);
// await setOptions("car", { colCount: 2 });
// className = await getClassName();
// assert.notEqual(className.indexOf("sv-q-column-2"), -1);
// });
// test("change choices order", async (t) => {
// await setRowItemFlowDirection();
// const getChoicesCount = ClientFunction(
// () => {
// const checkboxControlClassName = ".sd-checkbox__control";
// return document.querySelectorAll(
// `div[id*=sq_1] fieldset ${checkboxControlClassName}`
// ).length;
// }
// );
// const getFirst = Selector(
// `div[id*=sq_1] ${columnClassName}:nth-child(1) .sv-string-viewer`
// ).nth(0);
// const getSecond = Selector(
// `div[id*=sq_1] ${columnClassName}:nth-child(2) .sv-string-viewer`
// ).nth(0);
// let rnd_count = 0;
// let first, second, first_2;
// let choicesCount = await getChoicesCount();
// // asc
// await setOptions("car", { choicesOrder: "asc" });
// first = await getFirst();
// second = await getSecond();
// assert.equal(first.textContent.trim(), "Audi");
// assert.equal(second.textContent.trim(), "BMW");
// // desc
// await setOptions("car", { choicesOrder: "desc" });
// first = await getFirst();
// second = await getSecond();
// assert.equal(first.textContent.trim(), "Volkswagen");
// assert.equal(second.textContent.trim(), "Vauxhall");
// // rnd
// if (choicesCount === 1) {
// assert(false, "need to more than one choices");
// }
// for (let i = 0; i < 15; i++) {
// await setOptions("car", { choicesOrder: "asc" });
// await setOptions("car", { choicesOrder: "random" });
// first_2 = await getFirst();
// if (first.textContent.trim() !== first_2.textContent.trim()) {
// rnd_count++;
// }
// first = first_2;
// if (rnd_count >= 4) {
// break;
// }
// }
// assert(rnd_count >= 4); // because of 'none', 'asc', 'desc' and if 4 it is really rnd
// });
// test("check integrity", async (t) => {
// let i;
// const getChoicesCount = ClientFunction(
// () => {
// const columnClassName = ".sd-selectbase__column";
// const checkboxControlClassName = ".sd-checkbox__control";
// return document.querySelectorAll(
// `div[id*=sq_1] fieldset ${checkboxControlClassName}`
// ).length;
// }
// );
// const getChoicesExistence = ClientFunction(() => {
// var choices = [
// "None",
// "Ford",
// "Vauxhall",
// "Volkswagen",
// "Nissan",
// "Audi",
// "Mercedes-Benz",
// "BMW",
// "Peugeot",
// "Toyota",
// "Citroen",
// "Other (describe)",
// ];
// var result;
// for (var i = 0; i < choices.length; i++) {
// if (document.documentElement.innerHTML.indexOf(choices[i]) === -1)
// return false;
// }
// return true;
// });
// let choicesCount, choicesExistence;
// let checkIntegrity = async () => {
// choicesCount = await getChoicesCount();
// assert.equal(choicesCount, 13);
// choicesExistence = await getChoicesExistence();
// assert(choicesExistence);
// };
// await setOptions("car", { choicesOrder: "asc" });
// await checkIntegrity();
// await setOptions("car", { choicesOrder: "desc" });
// await checkIntegrity();
// await setOptions("car", { choicesOrder: "random" });
// await checkIntegrity();
// });
// test("show \"other\" choice", async (t) => {
// await setOptions("car", { hasOther: true });
// await t.expect(Selector(".sv-string-viewer").withText("Other").visible).ok();
// });
// test("check \"other\" choice doesn't change order", async (t) => {
// await setRowItemFlowDirection();
// const getOtherChoice = Selector(
// () => {
// const columnClassName = ".sd-selectbase__column";
// return document.querySelectorAll(
// `div[id*=sq_1] fieldset ${columnClassName}:nth-child(1) div:nth-of-type(4)`
// )[0];
// }
// );
// let otherChoice;
// await setOptions("car", { hasOther: true });
// await setOptions("car", { choicesOrder: "desc" });
// otherChoice = await getOtherChoice();
// assert.equal(otherChoice.textContent.trim(), "Other (describe)");
// });
// test("choose other", async (t) => {
// const getOtherInput = Selector(
// () => document.querySelectorAll("textarea")[0]
// );
// let surveyResult;
// await setOptions("car", { hasOther: true });
// await t
// .click(Selector("span").withText("Other (describe)"))
// .typeText(getOtherInput, "Zaporozec")
// .click("input[value=Complete]");
// surveyResult = await getSurveyResult();
// assert.equal(surveyResult.car, "other");
// assert.equal(surveyResult["car-Comment"], "Zaporozec");
// });
// test("choose other and storeOthersAsComment=false", async (t) => {
// const setSurveyOptions = ClientFunction(() => {
// window["survey"].storeOthersAsComment = false;
// });
// const getOtherInput = Selector(
// () => document.querySelectorAll("textarea")[0]
// );
// let surveyResult;
// await setSurveyOptions();
// await setOptions("car", { hasOther: true });
// await t
// .click(Selector("span").withText("Other (describe)"))
// .typeText(getOtherInput, "New_Producer")
// .click("input[value=Complete]");
// surveyResult = await getSurveyResult();
// assert.equal(surveyResult.car, "New_Producer");
// });
// test("choose other and \"textUpdateMode\": \"onTyping\"", async (t) => {
// const setSurveyOptions = ClientFunction(() => {
// window["survey"].textUpdateMode = "onTyping";
// });
// const getOtherInput = Selector(
// () => document.querySelectorAll("textarea")[0]
// );
// let surveyResult;
// await setSurveyOptions();
// await setOptions("car", { hasOther: true });
// await t
// .click(Selector("span").withText("Other (describe)"))
// .click(getOtherInput)
// .pressKey("C o m m e n t")
// .click("input[value=Complete]");
// surveyResult = await getSurveyResult();
// assert.equal(surveyResult.car, "other");
// assert.equal(surveyResult["car-Comment"], "Comment");
// });
// test("trim other", async (t) => {
// const getOtherInput = Selector(
// () => document.querySelectorAll("textarea")[0]
// );
// let surveyResult;
// await setOptions("car", { hasOther: true });
// await t
// .click(Selector("span").withText("Other (describe)"))
// .typeText(getOtherInput, " ");
// await t.pressKey("shift+tab")
// .pressKey("tab")
// .typeText(getOtherInput, "ab ");
// await t.pressKey("shift+tab")
// .pressKey("tab")
// .typeText(getOtherInput, "cd ");
// await t.click("input[value=Complete]");
// surveyResult = await getSurveyResult();
// assert.equal(surveyResult.car, "other");
// assert.equal(surveyResult["car-Comment"], "abcd");
// });
// test("checked class", async (t) => {
// const isCheckedClassExistsByIndex = ClientFunction((index) =>
// {
// const columnClassName = ".sd-selectbase__column";
// return document
// .querySelector(
// `fieldset ${columnClassName}:nth-child(3) div:nth-of-type(${index})`
// )
// .classList.contains("sd-checkbox--checked");
// });
// assert.equal(await isCheckedClassExistsByIndex(2), false);
// assert.equal(await isCheckedClassExistsByIndex(3), false);
// await t
// .click(
// `fieldset ${columnClassName}:nth-child(3) div:nth-of-type(2) label input`
// )
// .click(
// `fieldset ${columnClassName}:nth-child(3) div:nth-of-type(3) label input`
// );
// assert.equal(await isCheckedClassExistsByIndex(2), true);
// assert.equal(await isCheckedClassExistsByIndex(3), true);
// });
// test("Check that selectAll item is checked after loading data - https://surveyjs.answerdesk.io/internal/ticket/details/T4979", async (t) => {
// const enableHasSelectAll = ClientFunction(() => {
// window["survey"].getAllQuestions()[0].hasSelectAll = true;
// });
// const isSelectAllChecked = ClientFunction(() => {
// const columnClassName = ".sd-selectbase__column";
// return document.querySelector(
// `fieldset ${columnClassName}:nth-of-type(1) div:nth-of-type(1) input`
// ).checked;
// });
// const surveyData = {
// car: [
// "Unknown",
// "Ford",
// "Vauxhall",
// "Volkswagen",
// "Nissan",
// "Audi",
// "Mercedes-Benz",
// "BMW",
// "Peugeot",
// "Toyota",
// "Citroen",
// ],
// };
// const setData = ClientFunction(() => {
// window["survey"].data = {
// car: [
// "Unknown",
// "Ford",
// "Vauxhall",
// "Volkswagen",
// "Nissan",
// "Audi",
// "Mercedes-Benz",
// "BMW",
// "Peugeot",
// "Toyota",
// "Citroen",
// ],
// };
// });
// await enableHasSelectAll();
// await setData();
// assert.equal(await isSelectAllChecked(), true);
// await t.click(Selector("span").withText("Select All"));
// assert.deepEqual(await getData(), {});
// await t.click(Selector("span").withText("Select All"));
// assert.deepEqual(await getData(), surveyData);
// });
// test("showOtherItem&showCommentArea", async (t) => {
// const getOtherInput = Selector(
// () => document.querySelectorAll("textarea")[0]
// );
// const getCommentInput = Selector(
// () => document.querySelectorAll("textarea")[1]
// );
// let surveyResult;
// await setOptions("car", { showOtherItem: true, showCommentArea: true, commentText: "Comment on question", otherText: "Other text" });
// await t
// .click(Selector("span").withText("Other text"))
// .typeText(getOtherInput, " ")
// .selectText(getOtherInput)
// .pressKey("delete")
// .typeText(getOtherInput, "Audi")
// .selectText(getOtherInput)
// .pressKey("delete")
// .typeText(getOtherInput, "Other value")
// .typeText(getCommentInput, "Comment value")
// .click("input[value=Complete]");
// surveyResult = await getSurveyResult();
// assert.equal(surveyResult.car, "Other value");
// assert.equal(surveyResult["car-Comment"], "Comment value");
// });
// });
// frameworks.forEach((framework) => {
// fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(
// async (t) => {
// await initSurvey(framework, json, undefined, true);
// }
// );
// test("click on question title state editable", async (t) => {
// var newTitle = "MyText";
// var json = JSON.parse(await getQuestionJson());
// var questionValue = await getQuestionValue();
// assert.equal(questionValue.length, 0);
// var outerSelector = ".sd-question__title";
// var innerSelector = ".sv-string-editor";
// await t
// .click(outerSelector)
// .typeText(outerSelector + " " + innerSelector, newTitle, { replace: true })
// .click("body", { offsetX: 0, offsetY: 0 });
// questionValue = await getQuestionValue();
// assert.equal(questionValue.length, 0);
// json = JSON.parse(await getQuestionJson());
// assert.equal(json.title, newTitle);
// });
// test("click on checkbox title state editable", async (t) => {
// var newTitle = "MyText";
// var json = JSON.parse(await getQuestionJson());
// var questionValue = await getQuestionValue();
// assert.equal(questionValue.length, 0);
// var outerSelector = ".sd-item__control-label";
// var innerSelector = ".sv-string-editor";
// await t
// .click(outerSelector)
// .typeText(outerSelector + " " + innerSelector, newTitle, { replace: true })
// .click("body", { offsetX: 0, offsetY: 0 });
// questionValue = await getQuestionValue();
// assert.equal(questionValue.length, 0);
// json = JSON.parse(await getQuestionJson());
// assert.equal(json.choices[0].text, newTitle);
// });
// });
// frameworks.forEach((framework) => {
// fixture`${framework} ${title}`
// .page`${url}${framework}`
// .beforeEach(async (t) => {
// await initSurvey(framework, json);
// });
// test("maxSelectedChoices", async (t) => {
// const setSurveyOptions = ClientFunction(() => {
// window["survey"].questionsOnPageMode = "questionPerPage";
// window["survey"].getAllQuestions()[0].maxSelectedChoices = 2;
// });
// await setSurveyOptions();
// await t
// .click(Selector(".sd-item__control-label").withText("Nissan"))
// .click(Selector(".sd-item__control-label").withText("Audi"))
// .click(Selector(".sd-item__control-label").withText("Ford"))
// .click(Selector(".sd-item__control-label").withText("Audi"))
// .click(Selector(".sd-item__control-label").withText("BMW"))
// .click("input[value=Complete]");
// const surveyResult = await getSurveyResult();
// await t.expect(surveyResult.car).eql(["Nissan", "BMW"]);
// });
// test("check other comment is focused after other item is selected ", async (t) => {
// await t.click("input[value='other']").expect(Selector("textarea").focused).ok();
// });
// });
// frameworks.forEach((framework) => {
// fixture`${framework} ${title}`.page`${url}${framework}`.beforeEach(async t => {
// await t.resizeWindow(800, 600);
// });
// test("maxSelectedChoices in matrix with showInMultipleColumns", async (t) => {
// await initSurvey(framework, {
// "elements": [
// {
// "type": "matrixdropdown",
// "name": "q1",
// "columns": [
// {
// "name": "col1",
// "cellType": "checkbox",
// "showInMultipleColumns": true,
// "choices": ["a", "b", "c", "d", "e"],
// "maxSelectedChoices": 2
// }
// ],
// "rows": ["row1"]
// }
// ]
// });
// const checks = Selector("input[type='checkbox'");
// await t
// .click(checks.nth(0))
// .click(checks.nth(1))
// .click(checks.nth(2))
// .click(checks.nth(3))
// .click(checks.nth(4))
// .click("input[value=Complete]");
// const surveyResult = await getSurveyResult();
// await t.expect(surveyResult.q1.row1.col1).eql(["a", "b"]);
// });
// });