www_app 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +36 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +21 -0
  5. data/README.md +84 -0
  6. data/TODO.md +13 -0
  7. data/VERSION +1 -0
  8. data/bin/www_app +46 -0
  9. data/doc/Design.md +123 -0
  10. data/doc/Why_this_arch.rb +104 -0
  11. data/lib/public/jquery-2.1.1.js +4 -0
  12. data/lib/public/jquery.serialize-object.min.js +8 -0
  13. data/lib/public/underscore-1.7.0.js +6 -0
  14. data/lib/public/underscore-min.map +1 -0
  15. data/lib/public/underscore.string-2.3.0.js +1 -0
  16. data/lib/public/www_app.js +824 -0
  17. data/lib/www_app/Clean.rb +169 -0
  18. data/lib/www_app/dsl.rb +86 -0
  19. data/lib/www_app/source.rb +53 -0
  20. data/lib/www_app.rb +1024 -0
  21. data/specs/as_ruby/0000-new.rb +23 -0
  22. data/specs/as_ruby/0010-attrs.rb +29 -0
  23. data/specs/as_ruby/0011-class.rb +39 -0
  24. data/specs/as_ruby/0011-href.rb +37 -0
  25. data/specs/as_ruby/0011-id.rb +39 -0
  26. data/specs/as_ruby/0020-tag.rb +21 -0
  27. data/specs/as_ruby/0020-tag_content.rb +43 -0
  28. data/specs/as_ruby/0021-body.rb +16 -0
  29. data/specs/as_ruby/0021-form.rb +22 -0
  30. data/specs/as_ruby/0021-link.rb +26 -0
  31. data/specs/as_ruby/0021-script.rb +44 -0
  32. data/specs/as_ruby/0030-mustache.rb +113 -0
  33. data/specs/as_ruby/0040-css.rb +174 -0
  34. data/specs/as_ruby/0050-on.rb +64 -0
  35. data/specs/client-side/index.html +90 -0
  36. data/specs/client-side/index.js +777 -0
  37. data/specs/lib/config.ru +96 -0
  38. data/specs/lib/helpers.rb +230 -0
  39. data/specs/lib/qunit/qunit-1.15.0.css +237 -0
  40. data/specs/lib/qunit/qunit-1.15.0.js +2495 -0
  41. data/specs/lib/sample.rb +23 -0
  42. data/specs/sampe.2.rb +14 -0
  43. data/specs/sample.3.rb +17 -0
  44. data/specs/sample.rb +44 -0
  45. data/www_app.gemspec +38 -0
  46. metadata +271 -0
@@ -0,0 +1,777 @@
1
+
2
+ "use strict";
3
+
4
+ /* global QUnit */
5
+ /* global WWW_App */
6
+ /* global _ */
7
+ /* global expect */
8
+ /*jshint multistr:true */
9
+
10
+
11
+ // ==== Helpers: ====================================================
12
+ var when_count = 0;
13
+ var do_this = function (do_f) {
14
+ return {
15
+ when: function (when_f) {
16
+ return setTimeout(function () {
17
+ if (when_f()) {
18
+ when_count = 0;
19
+ do_f();
20
+ } else {
21
+ when_count = when_count + 1;
22
+ if (when_count > 15) {
23
+ when_count = 0;
24
+ QUnit.start();
25
+ } else {
26
+ do_this(do_f).when(when_f);
27
+ }
28
+ }
29
+ }, 100);
30
+ }
31
+ };
32
+ }; // do_this
33
+
34
+ // ==================================================================
35
+
36
+
37
+ // ==================================================================
38
+ QUnit.module("WWW_App");
39
+ // ==================================================================
40
+
41
+ QUnit.test( "it runs the code", function ( assert ) {
42
+ WWW_App.run([
43
+ '#box_1',
44
+ "add class", ['weird']
45
+ ]);
46
+ assert.ok( $('#box_1').hasClass('weird') === true, "Passed!" );
47
+ });
48
+
49
+
50
+ QUnit.test( "it evals the args as code", function( assert ) {
51
+ var o = WWW_App.run([
52
+ "add to stack", ["array", [1,2,3]]
53
+ ]);
54
+ assert.deepEqual( o.right('all'), [[1,2,3]], "Args are eval'd before run." );
55
+ });
56
+
57
+
58
+ QUnit.test("throws error if not enough stack values", function (assert) {
59
+ assert.throws(function () {
60
+ WWW_App.run(['less or equal', [5]]);
61
+ }, /Not enough values in stack/);
62
+ });
63
+
64
+
65
+ QUnit.test("throws error if not enough arg values", function (assert) {
66
+ assert.throws(function () {
67
+ WWW_App.run(['less or equal', []]);
68
+ }, /Not enough values in args/);
69
+ });
70
+
71
+
72
+ // ==================================================================
73
+ QUnit.module("less or equal");
74
+ // ==================================================================
75
+
76
+ QUnit.test('it places true if: 5 <= 6', function (assert) {
77
+ var o = WWW_App.run([
78
+ 5, "less or equal", [ 6 ]
79
+ ]);
80
+ assert.equal( o.right('last'), true);
81
+ });
82
+
83
+ QUnit.test('it places true if: 6 <= 6', function (assert) {
84
+ var o = WWW_App.run([
85
+ 6, "less or equal", [ 6 ]
86
+ ]);
87
+ assert.equal( o.right('last'), true);
88
+ });
89
+
90
+ QUnit.test('it places false if: 7 <= 6', function (assert) {
91
+ var o = WWW_App.run([
92
+ 7, "less or equal", [ 6 ]
93
+ ]);
94
+ assert.equal( o.right('last'), false);
95
+ });
96
+
97
+ QUnit.test('throws error if first num is not a number', function (assert) {
98
+ assert.throws(function () {
99
+ WWW_App.run([
100
+ '5', 'less or equal', [5]
101
+ ]);
102
+ }, /Value in stack is not a Number: String: 5/);
103
+ });
104
+
105
+ QUnit.test('throws error if second num is not a number', function (assert) {
106
+ assert.throws(function () {
107
+ WWW_App.run([
108
+ 5, 'less or equal', ["6"]
109
+ ]);
110
+ }, /Value in args is not a Number: String: 6/);
111
+ });
112
+
113
+
114
+ // ==================================================================
115
+ QUnit.module("bigger or equal");
116
+ // ==================================================================
117
+
118
+ QUnit.test('it places true if: 6 >= 4', function (assert) {
119
+ var o = WWW_App.run([
120
+ 6, "bigger or equal", [ 4 ]
121
+ ]);
122
+ assert.equal( o.right('last'), true);
123
+ });
124
+
125
+ QUnit.test('it places true if: 6 >= 6', function (assert) {
126
+ var o = WWW_App.run([
127
+ 6, "bigger or equal", [ 6 ]
128
+ ]);
129
+ assert.equal( o.right('last'), true);
130
+ });
131
+
132
+ QUnit.test('it places false if: 6 >= 7', function (assert) {
133
+ var o = WWW_App.run([
134
+ 6, "bigger or equal", [ 7 ]
135
+ ]);
136
+ assert.equal( o.right('last'), false);
137
+ });
138
+
139
+ QUnit.test('throws error if first num is not a number', function (assert) {
140
+ assert.throws(function () {
141
+ WWW_App.run([
142
+ '3', 'bigger or equal', [5]
143
+ ]);
144
+ }, /Value in stack is not a Number: String: 3/);
145
+ });
146
+
147
+ QUnit.test('throws error if second num is not a number', function (assert) {
148
+ assert.throws(function () {
149
+ WWW_App.run([
150
+ 5, 'bigger or equal', ["9"]
151
+ ]);
152
+ }, /Value in args is not a Number: String: 9/);
153
+ });
154
+
155
+
156
+ // ==================================================================
157
+ QUnit.module('bigger');
158
+ // ==================================================================
159
+
160
+ QUnit.test('it places true on stack if: 6 > 1', function (assert) {
161
+ var o = WWW_App.run([
162
+ 6, 'bigger', [1]
163
+ ]);
164
+ assert.equal(o.right('last'), true);
165
+ });
166
+
167
+
168
+ QUnit.test('it places false on stack if: 6 > 6', function (assert) {
169
+ var o = WWW_App.run([
170
+ 6, 'bigger', [6]
171
+ ]);
172
+ assert.equal(o.right('last'), false);
173
+ });
174
+
175
+
176
+ // ==================================================================
177
+ QUnit.module('less');
178
+ // ==================================================================
179
+
180
+ QUnit.test('it places true on stack if: 1 < 6', function (assert) {
181
+ var o = WWW_App.run([
182
+ 1, 'less', [6]
183
+ ]);
184
+ assert.equal(o.right('last'), true);
185
+ });
186
+
187
+
188
+ QUnit.test('it places false on stack if: 6 < 6', function (assert) {
189
+ var o = WWW_App.run([
190
+ 6, 'less', [6]
191
+ ]);
192
+ assert.equal(o.right('last'), false);
193
+ });
194
+
195
+ QUnit.test('it places false on stack if: 6 < 1', function (assert) {
196
+ var o = WWW_App.run([
197
+ 6, 'less', [1]
198
+ ]);
199
+ assert.equal(o.right('last'), false);
200
+ });
201
+
202
+
203
+ // ==================================================================
204
+ QUnit.module('equal');
205
+ // ==================================================================
206
+
207
+ QUnit.test('it places true on stack if: 1 === 1', function (assert) {
208
+ var o = WWW_App.run([
209
+ 1, 'equal', [1]
210
+ ]);
211
+ assert.equal(o.right('last'), true);
212
+ });
213
+
214
+ QUnit.test('it places true on stack if: \'a\' === \'a\'', function (assert) {
215
+ var o = WWW_App.run([
216
+ "a", 'equal', ["a"]
217
+ ]);
218
+ assert.equal(o.right('last'), true);
219
+ });
220
+
221
+ QUnit.test('it places false on stack if: \'5\' === 5', function (assert) {
222
+ var o = WWW_App.run([
223
+ "5", 'equal', [5]
224
+ ]);
225
+ assert.equal(o.right('last'), false);
226
+ });
227
+
228
+
229
+ QUnit.test('it places false on stack if: 6 === \'6\'', function (assert) {
230
+ var o = WWW_App.run([
231
+ 6, 'equal', ["6"]
232
+ ]);
233
+ assert.equal(o.right('last'), false);
234
+ });
235
+
236
+
237
+ // ==================================================================
238
+ QUnit.module('and');
239
+ // ==================================================================
240
+
241
+ QUnit.test('throws error if last value on stack is not a bool', function (assert) {
242
+ assert.throws(function () {
243
+ var o = WWW_App.run([
244
+ 1, 'and', [true]
245
+ ]);
246
+ }, /Value in stack is not a Boolean: Number: 1/);
247
+ });
248
+
249
+ QUnit.test('throws if last value of args is not a bool', function (assert) {
250
+ assert.throws(function () {
251
+ var o = WWW_App.run([
252
+ true, 'and', [2]
253
+ ]);
254
+ }, /Value in args is not a Boolean: Number: 2/);
255
+ });
256
+
257
+ QUnit.test('it places true on stack if both conditions are true', function (assert) {
258
+ var o = WWW_App.run([
259
+ true, 'and', [6, 'equal', [6]]
260
+ ]);
261
+ assert.equal(o.right('last'), true);
262
+ });
263
+
264
+ QUnit.test('it places false on stack if first condition is false', function (assert) {
265
+ var o = WWW_App.run([
266
+ false, 'and', [6, 'equal', [6]]
267
+ ]);
268
+ assert.deepEqual(o.right('all'), [false, false]);
269
+ });
270
+
271
+ QUnit.test('it places false on stack if second condition is false', function (assert) {
272
+ var o = WWW_App.run([
273
+ true, 'and', [6, 'equal', [7]]
274
+ ]);
275
+ assert.deepEqual(o.right('all'), [true, false]);
276
+ });
277
+
278
+ QUnit.test('does not evaluate args if right-hand value is false', function (assert) {
279
+ var o = WWW_App.run([
280
+ false, 'and', ['unknown method', []]
281
+ ]);
282
+ assert.deepEqual(o.right('all'), [false, false]);
283
+ });
284
+
285
+
286
+ // ==================================================================
287
+ QUnit.module('or');
288
+ // ==================================================================
289
+
290
+ QUnit.test('it throws an error if first condition is not a bool', function (assert) {
291
+ assert.throws(function () {
292
+ WWW_App.run(["something", 'or', [false]]);
293
+ }, /Value in stack is not a Boolean: String: something/);
294
+ });
295
+
296
+ QUnit.test('it throws an error if second condition is not a bool', function (assert) {
297
+ assert.throws(function () {
298
+ WWW_App.run([false, 'or', [false, "something"]]);
299
+ }, /Value in args is not a Boolean: String: something/);
300
+ });
301
+
302
+ QUnit.test('it places true on stack if both conditions are true', function (assert) {
303
+ var o = WWW_App.run([
304
+ true, 'or', [6, 'equal', [6]]
305
+ ]);
306
+ assert.deepEqual(o.right('all'), [true, true]);
307
+ });
308
+
309
+ QUnit.test('it places true on stack if: true or false', function (assert) {
310
+ var o = WWW_App.run([
311
+ true, 'or', [9, 'equal', [6]]
312
+ ]);
313
+ assert.deepEqual(o.right('all'), [true, true]);
314
+ });
315
+
316
+ QUnit.test('it places true on stack if: false or true', function (assert) {
317
+ var o = WWW_App.run([
318
+ false, 'or', [9, 'equal', [9]]
319
+ ]);
320
+ assert.deepEqual(o.right('all'), [false, true]);
321
+ });
322
+
323
+ QUnit.test('does not evaluate args if first condition is true', function (assert) {
324
+ var o = WWW_App.run([
325
+ true, 'or', ['no known method', []]
326
+ ]);
327
+ assert.deepEqual(o.right('all'), [true, true]);
328
+ });
329
+
330
+
331
+ // ==================================================================
332
+ QUnit.module('if true');
333
+ // ==================================================================
334
+
335
+ QUnit.test('throws an error if righ hand value is not a bool', function (assert) {
336
+ assert.throws(function () {
337
+ WWW_App.run([
338
+ 6, "if true", [5]
339
+ ]);
340
+ }, /Value in stack is not a Boolean: Number: 6/);
341
+ });
342
+
343
+ QUnit.test('does not place a value on stack', function (assert) {
344
+ var o = WWW_App.run([
345
+ true, "if true", [
346
+ 100
347
+ ]
348
+ ]);
349
+
350
+ assert.deepEqual(o.right('all'), [true]);
351
+ });
352
+
353
+ QUnit.test('does not run tokens if stack value is false', function (assert) {
354
+ var o = WWW_App.run([
355
+ false, "if true", [
356
+ "something unknown", []
357
+ ]
358
+ ]);
359
+
360
+ assert.deepEqual(o.right('all'), [false]);
361
+ });
362
+
363
+
364
+ // ==================================================================
365
+ QUnit.module('if false');
366
+ // ==================================================================
367
+
368
+ QUnit.test('throws an error if righ hand value is not a bool', function (assert) {
369
+ assert.throws(function () {
370
+ WWW_App.run([
371
+ 7, "if false", [5]
372
+ ]);
373
+ }, /Value in stack is not a Boolean: Number: 7/);
374
+ });
375
+
376
+ QUnit.test('does not place a value on stack', function (assert) {
377
+ var o = WWW_App.run([
378
+ false, "if false", [ 100 ]
379
+ ]);
380
+
381
+ assert.deepEqual(o.right('all'), [false]);
382
+ });
383
+
384
+ QUnit.test('does not run tokens if stack value is true', function (assert) {
385
+ var o = WWW_App.run([
386
+ true, "if false", [ "something unknown", [] ]
387
+ ]);
388
+
389
+ assert.deepEqual(o.right('all'), [true]);
390
+ });
391
+
392
+
393
+ // ==================================================================
394
+ QUnit.module('on click button');
395
+ // ==================================================================
396
+
397
+ QUnit.test('only runs specified callback', function (assert) {
398
+
399
+ $('#event').html(
400
+ '\
401
+ <div class="the_box"> \
402
+ <div><div> \
403
+ <button class="red">Red</button> \
404
+ <button class="blue">Blue</button> \
405
+ </div></div> \
406
+ </div> \
407
+ '
408
+ );
409
+
410
+ var event = WWW_App.run([
411
+ '/red/div.the_box', 'does', [ 'add class', ['red'] ],
412
+ '/red/div.the_box', 'does', [ 'add class', ['red_two'] ],
413
+ '/blue/div.the_box', 'does', [ 'unknown func', ['blue'] ],
414
+ ]); // ======================
415
+
416
+ $('#event button.red').trigger('click');
417
+ assert.equal($('#event div.the_box').hasClass('red'), true);
418
+ assert.equal($('#event div.the_box').hasClass('red_two'), true);
419
+
420
+ }); // === only runs one callback
421
+
422
+ QUnit.test('adds event to element', function (assert) {
423
+
424
+ $('#event').html(
425
+ '\
426
+ <div class="the_box"> \
427
+ <div><div> \
428
+ <button class="red">Red</button> \
429
+ <button class="blue">Blue</button> \
430
+ </div></div> \
431
+ </div> \
432
+ '
433
+ );
434
+
435
+ var event = WWW_App.run([
436
+ '/red/div.the_box', 'does', [ 'add class', ['red'] ],
437
+ '/blue/div.the_box', 'does', [ 'reove class', ['red'], 'ad clss', ['blue'] ],
438
+ ]); // ======================
439
+
440
+ $('#event button.red').trigger('click');
441
+ assert.equal($('#event div.the_box').hasClass('red'), true);
442
+
443
+ }); // === adds event to element
444
+
445
+
446
+ // ==================================================================
447
+ QUnit.module('on click "a" link');
448
+ // ==================================================================
449
+
450
+ QUnit.test('adds event to element', function (assert) {
451
+
452
+ $('#event').html(
453
+ '\
454
+ <div class="the_box"> \
455
+ <div><div> \
456
+ <a href="#white">White</button> \
457
+ <a href="#blue">Blue</button> \
458
+ </div></div> \
459
+ </div> \
460
+ '
461
+ );
462
+
463
+ var event = WWW_App.run([
464
+ '/white/div.the_box', 'does', [ 'add class', ['white'] ]
465
+ ]); // ======================
466
+
467
+ $('#event a[href="#white"]').trigger('click');
468
+ assert.equal($('#event div.the_box').hasClass('white'), true);
469
+
470
+ }); // === adds event to element
471
+
472
+
473
+ // ==================================================================
474
+ QUnit.module('allow (event)');
475
+ // ==================================================================
476
+
477
+ QUnit.test('adds event to element', function (assert) {
478
+
479
+ $('#event').html(
480
+ '\
481
+ <div class="the_box"> \
482
+ <div><div> \
483
+ <div class="blue"></div> \
484
+ </div></div> \
485
+ </div> \
486
+ '
487
+ );
488
+
489
+ var event = WWW_App.run([
490
+ 'div.the_box div.blue', 'allows', [ 'mousedown' ],
491
+ '/blue/div.the_box', 'does', [ 'add class', ['blue'] ]
492
+ ]); // ======================
493
+
494
+ $('#event div.the_box div.blue').trigger('mousedown');
495
+ assert.equal($('#event div.the_box').hasClass('blue'), true);
496
+
497
+ }); // === adds event to element
498
+
499
+ QUnit.test('runs multiple defined "does"', function (assert) {
500
+
501
+ $('#event').html(
502
+ '\
503
+ <div class="the_box"> \
504
+ <div><div> \
505
+ <div class="orange"></div> \
506
+ </div></div> \
507
+ </div> \
508
+ '
509
+ );
510
+
511
+ var event = WWW_App.run([
512
+ 'div.the_box div.orange', 'allows', [ 'mousedown' ],
513
+ '/orange/div.the_box', 'does', [ 'add class', ['orange'] ],
514
+ '/orange/div.the_box', 'does', [ 'add class', ['white'] ],
515
+ '/orange/div.the_box', 'does', [ 'add class', ['black'] ]
516
+ ]); // ======================
517
+
518
+ $('#event div.the_box div.orange').trigger('mousedown');
519
+ assert.equal($('#event div.the_box').attr('class'), 'the_box orange white black');
520
+ });
521
+
522
+ QUnit.test('is ignored if called before on the same element', function (assert) {
523
+ $('#event').html(
524
+ '\
525
+ <div class="the_box"> \
526
+ <div></div> \
527
+ <div></div> \
528
+ <div></div> \
529
+ </div> \
530
+ '
531
+ );
532
+
533
+ var event = WWW_App.run([
534
+ 'div.the_box', 'allows', ['click'],
535
+ 'div.the_box', 'allows', ['click'],
536
+ 'div.the_box', 'allows', ['click'],
537
+ 'div.the_box', 'allows', ['click'],
538
+ '/click/div.the_box', 'does', ['remove', ['div:first']]
539
+ ]);
540
+
541
+ $('#event div.the_box').trigger('click');
542
+ assert.equal($('#event div.the_box div').length, 2);
543
+ });
544
+
545
+ QUnit.test('runs "does" on child elements of event target', function (assert) {
546
+
547
+ $('#event').html(
548
+ '\
549
+ <div class="the_box"> \
550
+ <div><div> \
551
+ <div class="grey"> \
552
+ <div><div class="child"></div></div> \
553
+ </div> \
554
+ </div></div> \
555
+ </div> \
556
+ '
557
+ );
558
+
559
+ var event = WWW_App.run([
560
+ 'div.the_box div.grey', 'allows', [ 'mousedown' ],
561
+ '/grey/div.child', 'does', [ 'add class', ['one'] ],
562
+ '/grey/div.child', 'does', [ 'add class', ['two'] ]
563
+ ]); // ======================
564
+
565
+ $('#event div.the_box div.grey').trigger('mousedown');
566
+ assert.equal($('#event div.the_box div.grey div.child').attr('class'), 'child one two');
567
+ });
568
+
569
+ QUnit.test('runs "does" on event target itself: /grey', function (assert) {
570
+
571
+ $('#event').html(
572
+ '\
573
+ <div class="the_box"> \
574
+ <div><div> \
575
+ <div class="grey"> \
576
+ <div><div class="child"></div></div> \
577
+ </div> \
578
+ </div></div> \
579
+ </div> \
580
+ '
581
+ );
582
+
583
+ var event = WWW_App.run([
584
+ 'div.the_box div.grey', 'allows', [ 'mousedown' ],
585
+ '/grey', 'does', [ 'add class', ['three'] ],
586
+ '/grey', 'does', [ 'add class', ['four'] ]
587
+ ]); // ======================
588
+
589
+ $('#event div.the_box div.grey').trigger('mousedown');
590
+ assert.equal($('#event div.the_box div.grey').attr('class'), 'grey three four');
591
+ });
592
+
593
+ QUnit.test('accepts path with /event_name/target/selector', function (assert) {
594
+
595
+ $('#event').html(
596
+ '\
597
+ <div class="the_box"> \
598
+ <div class="grey one"></div> \
599
+ <div class="grey two"></div> \
600
+ </div> \
601
+ '
602
+ );
603
+
604
+ var event = WWW_App.run([
605
+ 'div.the_box div.grey', 'allows', [ 'mousedown' ],
606
+ '/mousedown/div.grey:first/div.the_box', 'does', [ 'add class', ['one'] ],
607
+ '/mousedown/div.grey:last/div.the_box', 'does', [ 'add class', ['two'] ]
608
+ ]); // ======================
609
+
610
+ $('#event div.the_box div.grey.one').trigger('mousedown');
611
+ assert.equal($('#event div.the_box').attr('class'), 'the_box one');
612
+
613
+ $('#event div.the_box div.grey.two').trigger('mousedown');
614
+ assert.equal($('#event div.the_box').attr('class'), 'the_box one two');
615
+ });
616
+
617
+ // ==================================================================
618
+ QUnit.module('forms');
619
+ // ==================================================================
620
+
621
+ QUnit.test('throws error if url contains invalid char: :', function (assert) {
622
+ $('#form_1').attr('action', 'javascrip://alert');
623
+ assert.throws(function () {
624
+ $('#form_1 button.submit').trigger('click');
625
+ }, /Invalid chars in form action url: :/);
626
+ });
627
+
628
+ QUnit.test('throws error if url contains invalid char: &', function (assert) {
629
+ $('#form_1').attr('action', 'javascript&amp//alert');
630
+ assert.throws(function () {
631
+ $('#form_1 button.submit').trigger('click');
632
+ }, /Invalid chars in form action url: &/);
633
+ });
634
+
635
+ QUnit.test('throws error if url contains invalid char: ;', function (assert) {
636
+ $('#form_1').attr('action', 'http;amp//alert');
637
+ assert.throws(function () {
638
+ $('#form_1 button.submit').trigger('click');
639
+ }, /Invalid chars in form action url: ;/);
640
+ });
641
+
642
+
643
+ QUnit.asyncTest('submits form values', function (assert) {
644
+ expect(1);
645
+
646
+ $('#form_1').attr('action', '/repeat/vals');
647
+
648
+ var env = WWW_App.run([
649
+ '/success/#form_1', 'does', [
650
+ 'log', ['get', ['data']]
651
+ ]
652
+ ]);
653
+
654
+ var has_class = function () {
655
+ return $('#form_1').hasClass('complete');
656
+ }; // function
657
+
658
+ var run_tests = function () {
659
+ assert.deepEqual(_.last(env.log), {val_1: '1', val_2: '2', val_3: '3'});
660
+ QUnit.start();
661
+ }; // function
662
+
663
+ $('#form_1 button.submit').trigger('click');
664
+ do_this(run_tests).when(has_class);
665
+ });
666
+
667
+
668
+ QUnit.asyncTest('displays success msg', function (assert) {
669
+ expect(1);
670
+ $('#form_1').attr('action', '/repeat/success_msg');
671
+ var env = WWW_App.run([]);
672
+
673
+
674
+ var has_class = function () {
675
+ return $('#form_1').hasClass('complete');
676
+ }; // function
677
+
678
+ var run_tests = function () {
679
+ assert.equal($('#form_1 div.status_msg.success_msg').text() , 'The success msg.');
680
+ QUnit.start();
681
+ }; // function
682
+
683
+ $('#form_1 button.submit').trigger('click');
684
+ do_this(run_tests).when(has_class);
685
+ });
686
+
687
+
688
+ QUnit.asyncTest('displays error msg', function (assert) {
689
+ expect(1);
690
+ $('#form_1').attr('action', '/repeat/error_msg');
691
+ var env = WWW_App.run([]);
692
+
693
+
694
+ var has_class = function () {
695
+ return $('#form_1').hasClass('complete');
696
+ }; // function
697
+
698
+ var run_tests = function () {
699
+ assert.equal($('#form_1 div.status_msg.error_msg').text() , 'The error msg.');
700
+ QUnit.start();
701
+ }; // function
702
+
703
+ $('#form_1 button.submit').trigger('click');
704
+ do_this(run_tests).when(has_class);
705
+ });
706
+
707
+
708
+ // ==================================================================
709
+ QUnit.module("looping getting/inserting of partials");
710
+ // ==================================================================
711
+
712
+ QUnit.asyncTest('inserts status on top of parent', function (assert) {
713
+ expect(1);
714
+
715
+ $('#event').html(
716
+ '\
717
+ <div class="the_box"> \
718
+ <div data-refresh="items top fastest /repeat/item"></div> \
719
+ </div> \
720
+ '
721
+ );
722
+
723
+ var loop = WWW_App.run([]);
724
+
725
+ var items_status = function () {
726
+ return $('div.the_box div.items_status');
727
+ };
728
+
729
+ var has_dom = function () {
730
+ return items_status()().length > 0;
731
+ };
732
+
733
+ var the_test = function () {
734
+ assert.equal(items_status().html(), 'More items available. <a href="#show">Show them.</a>');
735
+ QUnit.start();
736
+ };
737
+
738
+ do_this(the_test).when(has_dom);
739
+
740
+ }); // === asyncTest
741
+
742
+ QUnit.asyncTest('removes status element after showing them', function (assert) {
743
+ expect(1);
744
+
745
+ $('#event').html(
746
+ '\
747
+ <div class="the_box"> \
748
+ <div data-refresh="items top fastest /repeat/item"></div> \
749
+ </div> \
750
+ '
751
+ );
752
+
753
+ var loop = WWW_App.run([]);
754
+
755
+ var items_status = function () {
756
+ return $('div.the_box div.items_status');
757
+ };
758
+
759
+ var has_dom = function () {
760
+ return items_status()().length > 0;
761
+ };
762
+
763
+ var the_test = function () {
764
+ items_status().find('a').trigger('click');
765
+ assert.equal(items_status().length, 0);
766
+ QUnit.start();
767
+ };
768
+
769
+ do_this(the_test).when(has_dom);
770
+
771
+ }); // === asyncTest
772
+
773
+
774
+
775
+
776
+
777
+