-
Notifications
You must be signed in to change notification settings - Fork 483
/
ec_setprop.js
659 lines (594 loc) · 28.5 KB
/
ec_setprop.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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
import $ from 'jquery';
var testUtils = require('../../../util/testUtils');
var tickWrapper = require('../../util/tickWrapper');
var TestResults = require('@cdo/apps/constants').TestResults;
var _ = require('lodash');
import {expect} from '../../../util/configuredChai';
// take advantage of the fact that we expose the filesystem via
// localhost
var flappyImage = '/base/static/flappy_promo.png';
var facebookImage = '/base/static/facebook_purple.png';
module.exports = {
app: "applab",
skinId: "applab",
levelFile: "levels",
levelId: "ec_simple",
tests: [
{
description: "setProperty on API created button",
editCode: true,
xml:
`button("my_button", "text");
setProperty("my_button", "text", "newtext");
console.log("text: " + getProperty("my_button", "text"));
setProperty("my_button", "text-color", "red");
console.log("text-color: " + getProperty("my_button", "text-color"));
setProperty("my_button", "background-color", "green");
console.log("background-color: " + getProperty("my_button", "background-color"));
setProperty("my_button", "font-size", 21);
console.log("font-size: " + getProperty("my_button", "font-size"));
setProperty("my_button", "image", "${facebookImage}");
console.log("image: " + getProperty("my_button", "image"));
`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var button = document.getElementById('my_button');
assert.equal(button.textContent, 'newtext');
assert.equal(button.style.color, 'red');
assert.equal(button.style.backgroundColor, 'green');
assert.equal(button.style.fontSize, '21px');
assert(/facebook_purple.png$/.test(button.getAttribute('data-canonical-image-url')));
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
expect(debugOutput.textContent).to.contain('text: newtext\n');
expect(debugOutput.textContent).to.contain('text-color: red\n');
expect(debugOutput.textContent).to.contain('background-color: green\n');
expect(debugOutput.textContent).to.contain('font-size: 21\n');
expect(debugOutput.textContent).to.match(/image: .*facebook_purple.png$/);
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode created button",
editCode: true,
levelHtml: '<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern withCrosshair" style="width: 320px; height: 450px; display: none;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"><button id="my_button" style="padding: 0px; margin: 0px; height: 30px; width: 80px; font-size: 14px; color: rgb(255, 255, 255); position: absolute; left: 55px; top: 85px; background-color: rgb(26, 188, 156);">Button</button></div></div>',
xml:
`setProperty("my_button", "text", "newtext");
console.log("text: " + getProperty("my_button", "text"));
setProperty("my_button", "text-color", "red");
console.log("text-color: " + getProperty("my_button", "text-color"));
setProperty("my_button", "background-color", "green");
console.log("background-color: " + getProperty("my_button", "background-color"));
setProperty("my_button", "font-size", 21);
console.log("font-size: " + getProperty("my_button", "font-size"));
setProperty("my_button", "image", "${facebookImage}");
console.log("image: " + getProperty("my_button", "image"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var button = document.getElementById('my_button');
assert.equal(button.textContent, 'newtext');
assert.equal(button.style.color, 'red');
assert.equal(button.style.backgroundColor, 'green');
assert.equal(button.style.fontSize, '21px');
assert(/facebook_purple.png$/.test(button.getAttribute('data-canonical-image-url')));
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
expect(debugOutput.textContent).to.contain('text: newtext\n');
expect(debugOutput.textContent).to.contain('text-color: red\n');
expect(debugOutput.textContent).to.contain('background-color: green\n');
expect(debugOutput.textContent).to.contain('font-size: 21\n');
expect(debugOutput.textContent).to.match(/image: .*facebook_purple.png$/);
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on API created text input",
editCode: true,
xml:
`textInput("my_text_input", "text");
setProperty("my_text_input", "placeholder", "placeholdertext");
console.log("placeholder: " + getProperty("my_text_input", "placeholder"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var textInput = document.getElementById('my_text_input');
assert.equal(textInput.getAttribute('placeholder'), 'placeholdertext');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent, 'placeholder: placeholdertext');
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode slider ",
editCode: true,
levelHtml: '<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern withCrosshair" style="width: 320px; height: 450px; display: none;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"><input type="range" value="50" min="0" max="100" step="1" id="my_slider" style="margin: 0px; padding: 0px; width: 150px; height: 24px; position: absolute; left: 75px; top: 95px;" /></div></div>',
xml:
`setProperty("my_slider", "value", 51);
console.log("value: " + getProperty("my_slider", "value"));
setProperty("my_slider", "min", 1);
console.log("min: " + getProperty("my_slider", "min"));
setProperty("my_slider", "max", 101);
console.log("max: " + getProperty("my_slider", "max"));
setProperty("my_slider", "step", 3);
console.log("step: " + getProperty("my_slider", "step"));`
,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var slider = document.getElementById('my_slider');
assert.equal(slider.getAttribute('value'), '51');
assert.equal(slider.getAttribute('min'), '1');
assert.equal(slider.getAttribute('max'), '101');
assert.equal(slider.getAttribute('step'), '3');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent, `value: 51
min: 1
max: 101
step: 3`);
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on API created Image",
editCode: true,
xml:
`image("my_image", "${flappyImage}");
setProperty("my_image", "width", 11);
console.log("width: " + getProperty("my_image", "width"));
setProperty("my_image", "height", 12);
console.log("height: " + getProperty("my_image", "height"));
setProperty("my_image", "x", 13);
console.log("x: " + getProperty("my_image", "x"));
setProperty("my_image", "y", 14);
console.log("y: " + getProperty("my_image", "y"));
setProperty("my_image", "picture", "${facebookImage}");
console.log("picture: " + getProperty("my_image", "picture"));
setProperty("my_image", "hidden", true);
console.log("hidden: " + getProperty("my_image", "hidden"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var image = document.getElementById('my_image');
// we set style.width/height instead of the width/height attributes
assert.equal(image.style.width, '11px');
assert.equal(image.style.height, '12px');
assert.equal(image.getAttribute('width'), null);
assert.equal(image.getAttribute('height'), null);
assert.equal(image.style.left, '13px');
assert.equal(image.style.top, '14px');
assert(/facebook_purple.png$/.test(image.src));
// visibility is set via a class, so use getComputedStyle
assert(window.getComputedStyle(image).visibility, 'hidden');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
// No errors in output console
var debugOutput = document.getElementById('debug-output');
expect(debugOutput.textContent).to.contain('width: 11\n');
expect(debugOutput.textContent).to.contain('height: 12\n');
expect(debugOutput.textContent).to.contain('x: 13\n');
expect(debugOutput.textContent).to.contain('y: 14\n');
expect(debugOutput.textContent).to.match(/picture: .*facebook_purple.png\n/);
expect(debugOutput.textContent).to.contain('hidden: true');
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode created Image 1",
editCode: true,
levelHtml:
'<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern withCrosshair" style="width: 320px; height: 450px; display: none;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"><img src="/blockly/media/1x1.gif" data-canonical-image-url="" id="my_image" style="height: 100px; width: 100px; position: absolute; left: 80px; top: 75px; margin: 0px;" /></div></div>',
xml:
`setProperty("my_image", "width", 11);
console.log("width: " + getProperty("my_image", "width"));
setProperty("my_image", "height", 12);
console.log("height: " + getProperty("my_image", "height"));
setProperty("my_image", "x", 13);
console.log("x: " + getProperty("my_image", "x"));
setProperty("my_image", "y", 14);
console.log("y: " + getProperty("my_image", "y"));
setProperty("my_image", "picture", "${facebookImage}");
console.log("picture: " + getProperty("my_image", "picture"));
setProperty("my_image", "hidden", true);
console.log("hidden: " + getProperty("my_image", "hidden"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var image = document.getElementById('my_image');
// we set style.width/height instead of the width/height attributes
assert.equal(image.style.width, '11px');
assert.equal(image.style.height, '12px');
assert.equal(image.getAttribute('width'), null);
assert.equal(image.getAttribute('height'), null);
assert.equal(image.style.left, '13px');
assert.equal(image.style.top, '14px');
assert(/facebook_purple.png$/.test(image.src));
// visibility is set via a class, so use getComputedStyle
assert(window.getComputedStyle(image).visibility, 'hidden');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
// No errors in output console
var debugOutput = document.getElementById('debug-output');
expect(debugOutput.textContent).to.contain('width: 11\n');
expect(debugOutput.textContent).to.contain('height: 12\n');
expect(debugOutput.textContent).to.contain('x: 13\n');
expect(debugOutput.textContent).to.contain('y: 14\n');
expect(debugOutput.textContent).to.match(/picture: .*facebook_purple.png\n/);
expect(debugOutput.textContent).to.contain('hidden: true');
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on API created dropdown",
editCode: true,
xml:
`dropdown("my_drop", "option1", "option2", "option3", "option4", "option5");
setProperty("my_drop", "options", ["one", "two", "three"]);
console.log("options: " + getProperty("my_drop", "options"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var dropdown = $("#my_drop");
assert.equal(dropdown.children().length, 3);
assert.equal(dropdown.children().eq(0).text(), 'one');
assert.equal(dropdown.children().eq(1).text(), 'two');
assert.equal(dropdown.children().eq(2).text(), 'three');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent, 'options: one,two,three');
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode created dropdown",
editCode: true,
levelHtml:
'<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern withCrosshair" style="width: 320px; height: 450px;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"><select id="my_drop" style="width: 200px; height: 30px; font-size: 14px; margin: 0px; color: rgb(255, 255, 255); position: absolute; left: 35px; top: 75px; background-color: rgb(26, 188, 156);"><option>Option 1</option><option>Option 2</option></select></div></div>',
xml:
`setProperty("my_drop", "options", ["one", "two", "three"]);
console.log("options: " + getProperty("my_drop", "options"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var dropdown = $("#my_drop");
assert.equal(dropdown.children().length, 3);
assert.equal(dropdown.children().eq(0).text(), 'one');
assert.equal(dropdown.children().eq(1).text(), 'two');
assert.equal(dropdown.children().eq(2).text(), 'three');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent, "options: one,two,three");
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode created canvas",
editCode: true,
levelHtml:
'<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern withCrosshair" style="width: 320px; height: 450px; display: none;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"><canvas width="100px" height="100px" id="canvas1" style="position: absolute; left: 65px; top: 40px; margin: 0px;"></canvas></div></div>',
xml:
`setProperty("canvas1", "width", 12);
console.log("width: " + getProperty("canvas1", "width"));
setProperty("canvas1", "height", 13);
console.log("height: " + getProperty("canvas1", "height"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var canvas = $("#canvas1")[0];
// we set the width/height attributes instead of style.width/height
assert.equal(canvas.style.width, '');
assert.equal(canvas.style.height, '');
assert.equal(canvas.getAttribute('width'), '12px');
assert.equal(canvas.getAttribute('height'), '13px');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent, "width: 12\nheight: 13");
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode created screen",
editCode: true,
levelHtml:
'<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern" style="display: none; width: 320px; height: 450px;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"></div></div>',
xml:
`setProperty("screen1", "image", "${flappyImage}");
console.log("image: " + getProperty("screen1", "image"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var screen = $("#screen1")[0];
// we set the width/height attributes instead of style.width/height
console.log(screen.style.backgroundImage);
assert(/url\(.*flappy_promo.png['"]?\)$/.test(screen.style.backgroundImage),
'screen background image should be flappy_promo.png. Instead: '+screen.style.backgroundImage);
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
expect(debugOutput.textContent).to.match(/image: .*flappy_promo.png$/);
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode created image 2",
editCode: true,
levelHtml:
'<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern withCrosshair" style="width: 320px; height: 450px; display: block;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"><img src="/blockly/media/1x1.gif" data-canonical-image-url="" id="image1" style="height: 100px; width: 100px; position: absolute; left: 125px; top: 235px; margin: 0px;" /></div></div>',
xml:
`setProperty("image1", "picture", "${flappyImage}");
console.log("picture: " + getProperty("image1", "picture"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var image = $("#image1")[0];
// we set the width/height attributes instead of style.width/height
assert(/flappy_promo.png$/.test(image.getAttribute('data-canonical-image-url')));
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
expect(debugOutput.textContent).to.match(/picture: .*flappy_promo.png$/);
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode created radio button",
editCode: true,
levelHtml:
'<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern withCrosshair" style="width: 320px; height: 450px; display: block;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"><input type="radio" id="radio_button1" style="width: 12px; height: 12px; margin: 0px; position: absolute; left: 85px; top: 75px;" /></div></div>',
xml:
`setProperty("radio_button1", "group-id", "gid1");
console.log("group-id: " + getProperty("radio_button1", "group-id"));
setProperty("radio_button1", "checked", true);
console.log("checked: " + getProperty("radio_button1", "checked"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var radio = $("#radio_button1")[0];
assert.equal(radio.getAttribute('name'), "gid1");
assert.equal(radio.getAttribute('checked'), "checked");
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent, "group-id: gid1\nchecked: true");
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty on design mode created text area",
editCode: true,
levelHtml:
'<div xmlns="http://www.w3.org/1999/xhtml" id="designModeViz" class="appModern withCrosshair" style="width: 320px; height: 450px; display: block;"><div class="screen" tabindex="1" id="screen1" style="display: block; height: 450px; width: 320px; left: 0px; top: 0px; position: absolute; z-index: 0;"><div contenteditable="true" class="textArea" id="text_area1" style="width: 200px; height: 100px; font-size: 14px; color: rgb(0, 0, 0); position: absolute; left: 55px; top: 90px; margin: 0px; background-color: rgb(255, 255, 255);"></div></div></div>',
xml:
`console.log("readonly: " + JSON.stringify(getProperty("text_area1", "readonly")));
setProperty("text_area1", "readonly", false);
console.log("readonly: " + JSON.stringify(getProperty("text_area1", "readonly")));
setProperty("text_area1", "readonly", true);
console.log("readonly: " + JSON.stringify(getProperty("text_area1", "readonly")));
setProperty("text_area1", "text-align", "right");
console.log("text-align: " + getProperty("text_area1", "text-align"));`,
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var text = $("#text_area1")[0];
assert.equal(text.getAttribute('contenteditable'), "false");
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
var debugOutput = document.getElementById('debug-output');
assert.equal(
debugOutput.textContent,
"readonly: false\nreadonly: false\nreadonly: true\ntext-align: right");
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty invalid prop",
editCode: true,
xml:
'image("my_image", "' + flappyImage + '");' +
'setProperty("my_image", "cant_set_this", 11);',
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var image = document.getElementById('my_image');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
// No errors in output console
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent,
'ERROR: Line: 1: Cannot set property "cant_set_this" on element "my_image".');
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty invalid value",
editCode: true,
xml:
'image("my_image", "' + flappyImage + '");' +
'setProperty("my_image", "hidden", "true");',
runBeforeClick: function (assert) {
// add a completion on timeout since this is a freeplay level
tickWrapper.runOnAppTick(Applab, 2, function () {
var image = document.getElementById('my_image');
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
// No errors in output console
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent,
'WARNING: Line: 1: setProperty() value parameter value (true) is not a boolean.');
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "setProperty autocomplete",
editCode: true,
xml: '',
runBeforeClick: function (assert) {
$("#show-code-header").click();
assert.equal($(".ace_autocomplete").is(":visible"), false,
'no autocomplete to start');
testUtils.typeAceText('setProp');
assert.equal($(".ace_autocomplete").is(":visible"), true,
'setProperty shows up in autocomplete');
expect($(".ace_autocomplete").text()).to.match(/setProperty/);
// For some reason, testUtils.typeAceText triggers the autocomplete menu
// when typing a partial command name (e.g. above), but does now show arguments
// when typing the opening paren after typing a valid command name as it does
// when running the app in a real browser. If this is resolved, the following
// commented-out test code should be enabled, here and in getProperty autocomplete.
// testUtils.typeAceText('erty(');
// assert.equal($(".ace_autocomplete").is(":visible"), true,
// 'we have autocomplete options after typing');
// assert.equal($(".ace_autocomplete .ace_content").text(), '"screen1"');
// testUtils.typeAceText('"screen1",');
// assert.equal($(".ace_autocomplete").is(":visible"), true,
// 'we have autocomplete options after typing');
// assert.equal($(".ace_autocomplete .ace_content").text(), '"background-color""image"',
// 'autocompletes filtered list of properties');
// clear contents before run
testUtils.setAceText('');
tickWrapper.runOnAppTick(Applab, 2, function () {
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
// No errors in output console
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent, '');
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
},
{
description: "getProperty autocomplete",
editCode: true,
xml: '',
runBeforeClick: function (assert) {
$("#show-code-header").click();
assert.equal($(".ace_autocomplete").is(":visible"), false,
'no autocomplete to start');
testUtils.typeAceText('getProp');
assert.equal($(".ace_autocomplete").is(":visible"), true,
'getProperty shows up in autocomplete');
expect($(".ace_autocomplete").text()).to.match(/getProperty/);
// clear contents before run
testUtils.setAceText('');
tickWrapper.runOnAppTick(Applab, 2, function () {
Applab.onPuzzleComplete();
});
},
customValidator: function (assert) {
// No errors in output console
var debugOutput = document.getElementById('debug-output');
assert.equal(debugOutput.textContent, '');
return true;
},
expected: {
result: true,
testResult: TestResults.FREE_PLAY
}
}
]
};