1
1
'use strict' ;
2
2
3
- ddescribe ( '$aria' , function ( ) {
3
+ describe ( '$aria' , function ( ) {
4
4
var scope , $compile , element ;
5
5
6
6
beforeEach ( module ( 'ngAria' ) ) ;
@@ -85,6 +85,28 @@ ddescribe('$aria', function() {
85
85
expect ( element . attr ( 'aria-checked' ) ) . toBe ( 'false' ) ;
86
86
} ) ;
87
87
88
+ it ( 'should handle checkbox with string model values using ng(True|False)Value' , function ( ) {
89
+ var element = $compile ( '<input type="checkbox" ng-model="val" ng-true-value="\'yes\'">' +
90
+ 'ng-false-value="\'no\'"'
91
+ ) ( scope ) ;
92
+
93
+ scope . $apply ( 'val="yes"' ) ;
94
+ expect ( element . eq ( 0 ) . attr ( 'aria-checked' ) ) . toBe ( 'true' ) ;
95
+
96
+ scope . $apply ( 'val="no"' ) ;
97
+ expect ( element . eq ( 0 ) . attr ( 'aria-checked' ) ) . toBe ( 'false' ) ;
98
+ } ) ;
99
+
100
+ it ( 'should handle checkbox with integer model values using ngTrueValue' , function ( ) {
101
+ var element = $compile ( '<input type="checkbox" ng-model="val" ng-true-value="0">' ) ( scope ) ;
102
+
103
+ scope . $apply ( 'val=0' ) ;
104
+ expect ( element . eq ( 0 ) . attr ( 'aria-checked' ) ) . toBe ( 'true' ) ;
105
+
106
+ scope . $apply ( 'val=1' ) ;
107
+ expect ( element . eq ( 0 ) . attr ( 'aria-checked' ) ) . toBe ( 'false' ) ;
108
+ } ) ;
109
+
88
110
it ( 'should attach itself to input type="radio"' , function ( ) {
89
111
var element = $compile ( '<input type="radio" ng-model="val" value="one">' +
90
112
'<input type="radio" ng-model="val" value="two">' ) ( scope ) ;
@@ -98,28 +120,36 @@ ddescribe('$aria', function() {
98
120
expect ( element . eq ( 1 ) . attr ( 'aria-checked' ) ) . toBe ( 'true' ) ;
99
121
} ) ;
100
122
101
- it ( 'should handle non-string model values for checkbox' , function ( ) {
102
- var element = $compile ( '<input type="checkbox" ng-model="val" ng-true-value="0">' ) ( scope ) ;
123
+
124
+ it ( 'should handle radios with integer model values' , function ( ) {
125
+ var element = $compile ( '<input type="radio" ng-model="val" value="0">' +
126
+ '<input type="radio" ng-model="val" value="1">' ) ( scope ) ;
103
127
104
128
scope . $apply ( "val=0" ) ;
105
129
expect ( element . eq ( 0 ) . attr ( 'aria-checked' ) ) . toBe ( 'true' ) ;
130
+ expect ( element . eq ( 1 ) . attr ( 'aria-checked' ) ) . toBe ( 'false' ) ;
106
131
107
- // scope.$apply("val=1");
108
- // // dump('bla', element.controller('ngModel').$viewValue);
109
- // expect(element.eq(0).attr('aria-checked')).toBe('false');
110
- // expect(element.eq(1).attr('aria-checked')).toBe('true');
132
+ scope . $apply ( "val=1" ) ;
133
+ expect ( element . eq ( 0 ) . attr ( 'aria-checked' ) ) . toBe ( 'false' ) ;
134
+ expect ( element . eq ( 1 ) . attr ( 'aria-checked' ) ) . toBe ( 'true' ) ;
111
135
} ) ;
112
136
113
- it ( 'should handle non-string model values' , function ( ) {
114
- var element = $compile ( '<input type="radio" ng-model="val" value="0">' +
115
- '<input type="radio" ng-model="val" value="1">' ) ( scope ) ;
137
+ it ( 'should handle radios with boolean model values using ngValue' , function ( ) {
138
+ var element = $compile ( '<input type="radio" ng-model="val" ng-value="valExp">' +
139
+ '<input type="radio" ng-model="val" ng-value="valExp2">' ) ( scope ) ;
140
+
141
+ scope . $apply ( function ( ) {
142
+ scope . valExp = true ;
143
+ scope . valExp2 = false ;
144
+ scope . val = true ;
145
+ } ) ;
116
146
117
- scope . $apply ( "val=0" ) ;
118
147
expect ( element . eq ( 0 ) . attr ( 'aria-checked' ) ) . toBe ( 'true' ) ;
119
148
expect ( element . eq ( 1 ) . attr ( 'aria-checked' ) ) . toBe ( 'false' ) ;
120
149
121
- scope . $apply ( "val=1" ) ;
122
- dump ( 'bla' , element . controller ( 'ngModel' ) . $viewValue ) ;
150
+ scope . $apply ( function ( ) {
151
+ scope . val = false ;
152
+ } ) ;
123
153
expect ( element . eq ( 0 ) . attr ( 'aria-checked' ) ) . toBe ( 'false' ) ;
124
154
expect ( element . eq ( 1 ) . attr ( 'aria-checked' ) ) . toBe ( 'true' ) ;
125
155
} ) ;
0 commit comments