forked from angular/code.angularjs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs-scenario.js
2327 lines (1772 loc) · 67.3 KB
/
docs-scenario.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
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
describe("api/angular.mock", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.mock");
});
});
describe("api/angular.mock.service.$browser", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.mock.service.$browser");
});
});
describe("api/angular.mock.service.$exceptionHandler", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.mock.service.$exceptionHandler");
});
});
describe("api/angular.mock.service.$log", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.mock.service.$log");
});
});
describe("api/angular.lowercase", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.lowercase");
});
});
describe("api/angular.uppercase", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.uppercase");
});
});
describe("api/angular.forEach", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.forEach");
});
});
describe("api/angular.extend", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.extend");
});
});
describe("api/angular.noop", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.noop");
});
});
describe("api/angular.identity", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.identity");
});
});
describe("api/angular.isUndefined", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.isUndefined");
});
});
describe("api/angular.isDefined", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.isDefined");
});
});
describe("api/angular.isObject", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.isObject");
});
});
describe("api/angular.isString", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.isString");
});
});
describe("api/angular.isNumber", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.isNumber");
});
});
describe("api/angular.isDate", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.isDate");
});
});
describe("api/angular.isArray", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.isArray");
});
});
describe("api/angular.isFunction", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.isFunction");
});
});
describe("api/angular.Object.size", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Object.size");
});
it('should print correct sizes for an array and an object', function() {
expect(binding('[1,2].$size()')).toBe('2');
expect(binding('{a:1, b:2, c:3}.$size()')).toBe('3');
});
});
describe("api/angular.Object.copy", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Object.copy");
});
it('should print that initialy the form object is NOT equal to master', function() {
expect(element('.doc-example-live input[name=master.salutation]').val()).toBe('Hello');
expect(element('.doc-example-live input[name=master.name]').val()).toBe('world');
expect(element('.doc-example-live span').css('display')).toBe('inline');
});
it('should make form and master equal when the copy button is clicked', function() {
element('.doc-example-live button').click();
expect(element('.doc-example-live span').css('display')).toBe('none');
});
});
describe("api/angular.Object.equals", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Object.equals");
});
it('should print that initialy greeting is equal to the hardcoded value object', function() {
expect(element('.doc-example-live input[name=greeting.salutation]').val()).toBe('Hello');
expect(element('.doc-example-live input[name=greeting.name]').val()).toBe('world');
expect(element('.doc-example-live span').css('display')).toBe('none');
});
it('should say that the objects are not equal when the form is modified', function() {
input('greeting.name').enter('kitty');
expect(element('.doc-example-live span').css('display')).toBe('inline');
});
});
describe("api/angular.bind", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.bind");
});
});
describe("api/angular.directive.ng:autobind", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:autobind");
});
});
describe("api/angular.service.$browser", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.service.$browser");
});
});
describe("api/angular.Object", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Object");
});
});
describe("api/angular.Array", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array");
});
});
describe("api/angular.Array.indexOf", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array.indexOf");
});
it('should correctly calculate the initial index', function() {
expect(binding('books.$indexOf(bookName)')).toBe('2');
});
it('should recalculate', function() {
input('bookName').enter('foo');
expect(binding('books.$indexOf(bookName)')).toBe('-1');
input('bookName').enter('Moby Dick');
expect(binding('books.$indexOf(bookName)')).toBe('0');
});
});
describe("api/angular.Array.sum", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array.sum");
});
//TODO: these specs are lame because I had to work around issues #164 and #167
it('should initialize and calculate the totals', function() {
expect(repeater('.doc-example-live table tr', 'item in invoice.items').count()).toBe(3);
expect(repeater('.doc-example-live table tr', 'item in invoice.items').row(1)).
toEqual(['$99.50']);
expect(binding("invoice.items.$sum('qty*cost')")).toBe('$99.50');
expect(binding("invoice.items.$sum('qty*cost')")).toBe('$99.50');
});
it('should add an entry and recalculate', function() {
element('.doc-example-live a:contains("add item")').click();
using('.doc-example-live tr:nth-child(3)').input('item.qty').enter('20');
using('.doc-example-live tr:nth-child(3)').input('item.cost').enter('100');
expect(repeater('.doc-example-live table tr', 'item in invoice.items').row(2)).
toEqual(['$2,000.00']);
expect(binding("invoice.items.$sum('qty*cost')")).toBe('$2,099.50');
});
});
describe("api/angular.Array.remove", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array.remove");
});
it('should initialize the task list with for tasks', function() {
expect(repeater('.doc-example-live ul li', 'task in tasks').count()).toBe(4);
expect(repeater('.doc-example-live ul li', 'task in tasks').column('task')).
toEqual(['Learn Angular', 'Read Documentation', 'Check out demos',
'Build cool applications']);
});
it('should initialize the task list with for tasks', function() {
element('.doc-example-live ul li a:contains("X"):first').click();
expect(repeater('.doc-example-live ul li', 'task in tasks').count()).toBe(3);
element('.doc-example-live ul li a:contains("X"):last').click();
expect(repeater('.doc-example-live ul li', 'task in tasks').count()).toBe(2);
expect(repeater('.doc-example-live ul li', 'task in tasks').column('task')).
toEqual(['Read Documentation', 'Check out demos']);
});
});
describe("api/angular.Array.filter", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array.filter");
});
it('should search across all fields when filtering with a string', function() {
input('searchText').enter('m');
expect(repeater('#searchTextResults tr', 'friend in friends').column('name')).
toEqual(['Mary', 'Mike', 'Adam']);
input('searchText').enter('76');
expect(repeater('#searchTextResults tr', 'friend in friends').column('name')).
toEqual(['John', 'Julie']);
});
it('should search in specific fields when filtering with a predicate object', function() {
input('search.$').enter('i');
expect(repeater('#searchObjResults tr', 'friend in friends').column('name')).
toEqual(['Mary', 'Mike', 'Julie']);
});
});
describe("api/angular.Array.add", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array.add");
});
beforeEach(function() {
expect(binding('people')).toBe('people = []');
});
it('should create an empty record when "add empty" is clicked', function() {
element('.doc-example-live a:contains("add empty")').click();
expect(binding('people')).toBe('people = [{\n "name":"",\n "sex":null}]');
});
it('should create a "John" record when "add \'John\'" is clicked', function() {
element('.doc-example-live a:contains("add \'John\'")').click();
expect(binding('people')).toBe('people = [{\n "name":"John",\n "sex":"male"}]');
});
it('should create a "Mary" record when "add \'Mary\'" is clicked', function() {
element('.doc-example-live a:contains("add \'Mary\'")').click();
expect(binding('people')).toBe('people = [{\n "name":"Mary",\n "sex":"female"}]');
});
it('should delete a record when "X" is clicked', function() {
element('.doc-example-live a:contains("add empty")').click();
element('.doc-example-live li a:contains("X"):first').click();
expect(binding('people')).toBe('people = []');
});
});
describe("api/angular.Array.count", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array.count");
});
it('should calculate counts', function() {
expect(binding('items.$count(\'points==1\')')).toEqual(2);
expect(binding('items.$count(\'points>1\')')).toEqual(1);
});
it('should recalculate when updated', function() {
using('.doc-example-live li:first-child').input('item.points').enter('23');
expect(binding('items.$count(\'points==1\')')).toEqual(1);
expect(binding('items.$count(\'points>1\')')).toEqual(2);
});
});
describe("api/angular.Array.orderBy", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array.orderBy");
});
it('should be reverse ordered by aged', function() {
expect(binding('predicate')).toBe('Sorting predicate = -age; reverse = ');
expect(repeater('.doc-example-live table', 'friend in friends').column('friend.age')).
toEqual(['35', '29', '21', '19', '10']);
expect(repeater('.doc-example-live table', 'friend in friends').column('friend.name')).
toEqual(['Adam', 'Julie', 'Mike', 'Mary', 'John']);
});
it('should reorder the table when user selects different predicate', function() {
element('.doc-example-live a:contains("Name")').click();
expect(repeater('.doc-example-live table', 'friend in friends').column('friend.name')).
toEqual(['Adam', 'John', 'Julie', 'Mary', 'Mike']);
expect(repeater('.doc-example-live table', 'friend in friends').column('friend.age')).
toEqual(['35', '10', '29', '19', '21']);
element('.doc-example-live a:contains("Phone")').click();
expect(repeater('.doc-example-live table', 'friend in friends').column('friend.phone')).
toEqual(['555-9876', '555-8765', '555-5678', '555-4321', '555-1212']);
expect(repeater('.doc-example-live table', 'friend in friends').column('friend.name')).
toEqual(['Mary', 'Julie', 'Adam', 'Mike', 'John']);
});
});
describe("api/angular.Array.limitTo", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.Array.limitTo");
});
it('should limit the numer array to first three items', function() {
expect(element('.doc-example-live input[name=limit]').val()).toBe('3');
expect(binding('numbers.$limitTo(limit) | json')).toEqual('[1,2,3]');
});
it('should update the output when -3 is entered', function() {
input('limit').enter(-3);
expect(binding('numbers.$limitTo(limit) | json')).toEqual('[7,8,9]');
});
});
describe("api/angular.compile", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.compile");
});
});
describe("api/angular.directive.ng:eval-order", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:eval-order");
});
it('should check ng:format', function(){
expect(using('.doc-example-live div:first').binding("items.$sum('total')")).toBe('$9.99');
expect(using('.doc-example-live div:last').binding("items.$sum('total')")).toBe('$9.99');
input('item.qty').enter('2');
expect(using('.doc-example-live div:first').binding("items.$sum('total')")).toBe('$9.99');
expect(using('.doc-example-live div:last').binding("items.$sum('total')")).toBe('$19.98');
});
});
describe("api/angular.directive", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive");
});
});
describe("api/angular.directive.ng:init", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:init");
});
it('should check greeting', function(){
expect(binding('greeting')).toBe('Hello');
expect(binding('person')).toBe('World');
});
});
describe("api/angular.directive.ng:controller", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:controller");
});
it('should check controller', function(){
expect(element('.doc-example-live div>:input').val()).toBe('John Smith');
expect(element('.doc-example-live li[ng\\:repeat-index="0"] input').val()).toBe('408 555 1212');
expect(element('.doc-example-live li[ng\\:repeat-index="1"] input').val()).toBe('[email protected]');
element('.doc-example-live li:first a:contains("clear")').click();
expect(element('.doc-example-live li:first input').val()).toBe('');
element('.doc-example-live li:last a:contains("add")').click();
expect(element('.doc-example-live li[ng\\:repeat-index="2"] input').val()).toBe('[email protected]');
});
});
describe("api/angular.directive.ng:eval", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:eval");
});
it('should check eval', function(){
expect(binding('obj.divide')).toBe('3');
expect(binding('obj.updateCount')).toBe('2');
input('obj.a').enter('12');
expect(binding('obj.divide')).toBe('6');
expect(binding('obj.updateCount')).toBe('3');
});
});
describe("api/angular.directive.ng:bind", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:bind");
});
it('should check ng:bind', function(){
expect(using('.doc-example-live').binding('name')).toBe('Whirled');
using('.doc-example-live').input('name').enter('world');
expect(using('.doc-example-live').binding('name')).toBe('world');
});
});
describe("api/angular.directive.ng:bind-template", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:bind-template");
});
it('should check ng:bind', function(){
expect(using('.doc-example-live').binding('{{salutation}} {{name}}')).
toBe('Hello World!');
using('.doc-example-live').input('salutation').enter('Greetings');
using('.doc-example-live').input('name').enter('user');
expect(using('.doc-example-live').binding('{{salutation}} {{name}}')).
toBe('Greetings user!');
});
});
describe("api/angular.directive.ng:bind-attr", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:bind-attr");
});
it('should check ng:bind-attr', function(){
expect(using('.doc-example-live').element('a').attr('href')).
toBe('http://www.google.com/search?q=AngularJS');
using('.doc-example-live').input('query').enter('google');
expect(using('.doc-example-live').element('a').attr('href')).
toBe('http://www.google.com/search?q=google');
});
});
describe("api/angular.directive.ng:click", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:click");
});
it('should check ng:click', function(){
expect(binding('count')).toBe('0');
element('.doc-example-live :button').click();
expect(binding('count')).toBe('1');
});
});
describe("api/angular.directive.ng:submit", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:submit");
});
it('should check ng:submit', function(){
expect(binding('list')).toBe('list=[]');
element('.doc-example-live form input').click();
this.addFutureAction('submit from', function($window, $document, done) {
$window.angular.element(
$document.elements('.doc-example-live form')).
trigger('submit');
done();
});
expect(binding('list')).toBe('list=["hello"]');
});
});
describe("api/angular.directive.ng:class", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:class");
});
it('should check ng:class', function(){
expect(element('.doc-example-live span').attr('className')).not().
toMatch(/ng-input-indicator-wait/);
using('.doc-example-live').element(':button:first').click();
expect(element('.doc-example-live span').attr('className')).
toMatch(/ng-input-indicator-wait/);
using('.doc-example-live').element(':button:last').click();
expect(element('.doc-example-live span').attr('className')).not().
toMatch(/ng-input-indicator-wait/);
});
});
describe("api/angular.directive.ng:class-odd", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:class-odd");
});
it('should check ng:class-odd and ng:class-even', function(){
expect(element('.doc-example-live li:first span').attr('className')).
toMatch(/ng-format-negative/);
expect(element('.doc-example-live li:last span').attr('className')).
toMatch(/ng-input-indicator-wait/);
});
});
describe("api/angular.directive.ng:class-even", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:class-even");
});
it('should check ng:class-odd and ng:class-even', function(){
expect(element('.doc-example-live li:first span').attr('className')).
toMatch(/ng-format-negative/);
expect(element('.doc-example-live li:last span').attr('className')).
toMatch(/ng-input-indicator-wait/);
});
});
describe("api/angular.directive.ng:show", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:show");
});
it('should check ng:show / ng:hide', function(){
expect(element('.doc-example-live span:first:hidden').count()).toEqual(1);
expect(element('.doc-example-live span:last:visible').count()).toEqual(1);
input('checked').check();
expect(element('.doc-example-live span:first:visible').count()).toEqual(1);
expect(element('.doc-example-live span:last:hidden').count()).toEqual(1);
});
});
describe("api/angular.directive.ng:hide", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:hide");
});
it('should check ng:show / ng:hide', function(){
expect(element('.doc-example-live span:first:hidden').count()).toEqual(1);
expect(element('.doc-example-live span:last:visible').count()).toEqual(1);
input('checked').check();
expect(element('.doc-example-live span:first:visible').count()).toEqual(1);
expect(element('.doc-example-live span:last:hidden').count()).toEqual(1);
});
});
describe("api/angular.directive.ng:style", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:style");
});
it('should check ng:style', function(){
expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)');
element('.doc-example-live :button[value=set]').click();
expect(element('.doc-example-live span').css('color')).toBe('red');
element('.doc-example-live :button[value=clear]').click();
expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)');
});
});
describe("api/angular.filter", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter");
});
});
describe("api/angular.filter.currency", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter.currency");
});
it('should init with 1234.56', function(){
expect(binding('amount | currency')).toBe('$1,234.56');
});
it('should update', function(){
input('amount').enter('-1234');
expect(binding('amount | currency')).toBe('$-1,234.00');
expect(element('.doc-example-live .ng-binding').attr('className')).
toMatch(/ng-format-negative/);
});
});
describe("api/angular.filter.number", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter.number");
});
it('should format numbers', function(){
expect(binding('val | number')).toBe('1,234.57');
expect(binding('val | number:0')).toBe('1,235');
expect(binding('-val | number:4')).toBe('-1,234.5679');
});
it('should update', function(){
input('val').enter('3374.333');
expect(binding('val | number')).toBe('3,374.33');
expect(binding('val | number:0')).toBe('3,374');
expect(binding('-val | number:4')).toBe('-3,374.3330');
});
});
describe("api/angular.filter.date", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter.date");
});
it('should format date', function(){
expect(binding("1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'")).
toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} \-?\d{4}/);
expect(binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).
toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(am|pm)/);
});
});
describe("api/angular.filter.json", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter.json");
});
it('should jsonify filtered objects', function() {
expect(binding('obj | json')).toBe('{\n "a":1,\n "b":[]}');
});
it('should update', function() {
input('objTxt').enter('[1, 2, 3]');
expect(binding('obj | json')).toBe('[1,2,3]');
});
});
describe("api/angular.filter.lowercase", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter.lowercase");
});
});
describe("api/angular.filter.uppercase", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter.uppercase");
});
});
describe("api/angular.filter.html", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter.html");
});
it('should sanitize the html snippet ', function(){
expect(using('#html-filter').binding('snippet | html')).
toBe('<p>an html\n<em>click here</em>\nsnippet</p>');
});
it('should escape snippet without any filter', function() {
expect(using('#escaped-html').binding('snippet')).
toBe("<p style=\"color:blue\">an html\n" +
"<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" +
"snippet</p>");
});
it('should inline raw snippet if filtered as unsafe', function() {
expect(using('#html-unsafe-filter').binding("snippet | html:'unsafe'")).
toBe("<p style=\"color:blue\">an html\n" +
"<em onmouseover=\"this.textContent='PWN3D!'\">click here</em>\n" +
"snippet</p>");
});
it('should update', function(){
input('snippet').enter('new <b>text</b>');
expect(using('#html-filter').binding('snippet | html')).toBe('new <b>text</b>');
expect(using('#escaped-html').binding('snippet')).toBe("new <b>text</b>");
expect(using('#html-unsafe-filter').binding("snippet | html:'unsafe'")).toBe('new <b>text</b>');
});
});
describe("api/angular.filter.linky", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.filter.linky");
});
it('should linkify the snippet with urls', function(){
expect(using('#linky-filter').binding('snippet | linky')).
toBe('Pretty text with some links:\n' +
'<a href="http://angularjs.org/">http://angularjs.org/</a>,\n' +
'<a href="mailto:[email protected]">[email protected]</a>,\n' +
'<a href="mailto:[email protected]">[email protected]</a>,\n' +
'and one more: <a href="ftp://127.0.0.1/">ftp://127.0.0.1/</a>.');
});
it ('should not linkify snippet without the linky filter', function() {
expect(using('#escaped-html').binding('snippet')).
toBe("Pretty text with some links:\n" +
"http://angularjs.org/,\n" +
"mailto:[email protected],\n" +
"[email protected],\n" +
"and one more: ftp://127.0.0.1/.");
});
it('should update', function(){
input('snippet').enter('new http://link.');
expect(using('#linky-filter').binding('snippet | linky')).
toBe('new <a href="http://link">http://link</a>.');
expect(using('#escaped-html').binding('snippet')).toBe('new http://link.');
});
});
describe("api/angular.formatter", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.formatter");
});
});
describe("api/angular.formatter.json", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.formatter.json");
});
it('should format json', function(){
expect(binding('data')).toEqual('data={\n \"name\":\"misko\",\n \"project\":\"angular\"}');
input('data').enter('{}');
expect(binding('data')).toEqual('data={\n }');
});
});
describe("api/angular.formatter.boolean", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.formatter.boolean");
});
it('should format boolean', function(){
expect(binding('value')).toEqual('value=false');
input('value').enter('truthy');
expect(binding('value')).toEqual('value=true');
});
});
describe("api/angular.formatter.number", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.formatter.number");
});
it('should format numbers', function(){
expect(binding('value')).toEqual('value=1234');
input('value').enter('5678');
expect(binding('value')).toEqual('value=5678');
});
});
describe("api/angular.formatter.list", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.formatter.list");
});
it('should format lists', function(){
expect(binding('value')).toEqual('value=["chair","table"]');
this.addFutureAction('change to XYZ', function($window, $document, done){
$document.elements('.doc-example-live :input:last').val(',,a,b,').trigger('change');
done();
});
expect(binding('value')).toEqual('value=["a","b"]');
});
});
describe("api/angular.formatter.trim", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.formatter.trim");
});
it('should format trim', function(){
expect(binding('value')).toEqual('value="book"');
this.addFutureAction('change to XYZ', function($window, $document, done){
$document.elements('.doc-example-live :input:last').val(' text ').trigger('change');
done();
});
expect(binding('value')).toEqual('value="text"');
});
});
describe("api/angular.injector", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.injector");
});
});
describe("api/angular.element", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.element");
});
});
describe("api/angular.toJson", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.toJson");
});
});
describe("api/angular.fromJson", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.fromJson");
});
});
describe("api/angular.markup", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.markup");
});
});
describe("api/angular.attrMarkup", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.attrMarkup");
});
});
describe("api/angular.directive.ng:href", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:href");
});
it('should execute ng:click but not reload when href without value', function() {
element('#link-1').click();
expect(input('value').val()).toEqual('1');
expect(element('#link-1').attr('href')).toBe("");
});
it('should execute ng:click but not reload when href empty string', function() {
element('#link-2').click();
expect(input('value').val()).toEqual('2');
expect(element('#link-2').attr('href')).toBe("");
});
it('should execute ng:click and change url when ng:href specified', function() {
element('#link-3').click();
expect(input('value').val()).toEqual('3');
expect(element('#link-3').attr('href')).toBe("#123");
expect(browser().location().hash()).toEqual('123');
});
it('should execute ng:click but not reload when href empty string and name specified', function() {
element('#link-4').click();
expect(input('value').val()).toEqual('4');
expect(element('#link-4').attr('href')).toBe("");
});
it('should execute ng:click but not reload when no href but name specified', function() {
element('#link-5').click();
expect(input('value').val()).toEqual('5');
expect(element('#link-5').attr('href')).toBe(undefined);
});
it('should only change url when only ng:href', function() {
input('value').enter('6');
element('#link-6').click();
expect(browser().location().hash()).toEqual('/6');
expect(element('#link-6').attr('href')).toBe("#/6");
});
});
describe("api/angular.directive.ng:src", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:src");
});
});
describe("api/angular.directive.ng:disabled", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:disabled");
});
it('should toggle button', function() {
expect(element('.doc-example-live :button').attr('disabled')).toBeFalsy();
input('checked').check();
expect(element('.doc-example-live :button').attr('disabled')).toBeTruthy();
});
});
describe("api/angular.directive.ng:checked", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:checked");
});
it('should check both checkBoxes', function() {
expect(element('.doc-example-live #checkSlave').attr('checked')).toBeFalsy();
input('master').check();
expect(element('.doc-example-live #checkSlave').attr('checked')).toBeTruthy();
});
});
describe("api/angular.directive.ng:multiple", function(){
beforeEach(function(){
browser().navigateTo("index.html#!/api/angular.directive.ng:multiple");