| OLD | NEW |
| 1 library ng_src_boolean_spec; | 1 library ng_src_boolean_spec; |
| 2 | 2 |
| 3 import '../_specs.dart'; | 3 import '../_specs.dart'; |
| 4 import 'dart:html' as dom; | 4 import 'dart:html' as dom; |
| 5 | 5 |
| 6 main() { | 6 main() { |
| 7 describe('boolean attr directives', () { | 7 describe('boolean attr directives', () { |
| 8 TestBed _; | 8 TestBed _; |
| 9 beforeEach(inject((TestBed tb) => _ = tb)); | 9 beforeEach((TestBed tb) => _ = tb); |
| 10 | 10 |
| 11 | 11 |
| 12 it('should properly evaluate 0 as false', inject(() { | 12 it('should properly evaluate 0 as false', () { |
| 13 _.compile('<button ng-disabled="isDisabled">Button</button>'); | 13 _.compile('<button ng-disabled="isDisabled">Button</button>'); |
| 14 _.rootScope.context['isDisabled'] = 0; | 14 _.rootScope.context['isDisabled'] = 0; |
| 15 _.rootScope.apply(); | 15 _.rootScope.apply(); |
| 16 expect(_.rootElement.attributes['disabled']).toBeFalsy(); | 16 expect(_.rootElement.attributes['disabled']).toBeFalsy(); |
| 17 _.rootScope.context['isDisabled'] = 1; | 17 _.rootScope.context['isDisabled'] = 1; |
| 18 _.rootScope.apply(); | 18 _.rootScope.apply(); |
| 19 expect(_.rootElement.attributes['disabled']).toBeTruthy(); | 19 expect(_.rootElement.attributes['disabled']).toBeTruthy(); |
| 20 })); | 20 }); |
| 21 | 21 |
| 22 | 22 |
| 23 it('should bind disabled', inject(() { | 23 it('should bind disabled', () { |
| 24 _.compile('<button ng-disabled="isDisabled">Button</button>'); | 24 _.compile('<button ng-disabled="isDisabled">Button</button>'); |
| 25 _.rootScope.context['isDisabled'] = false; | 25 _.rootScope.context['isDisabled'] = false; |
| 26 _.rootScope.apply(); | 26 _.rootScope.apply(); |
| 27 expect(_.rootElement.attributes['disabled']).toBeFalsy(); | 27 expect(_.rootElement.attributes['disabled']).toBeFalsy(); |
| 28 _.rootScope.context['isDisabled'] = true; | 28 _.rootScope.context['isDisabled'] = true; |
| 29 _.rootScope.apply(); | 29 _.rootScope.apply(); |
| 30 expect(_.rootElement.attributes['disabled']).toBeTruthy(); | 30 expect(_.rootElement.attributes['disabled']).toBeTruthy(); |
| 31 })); | 31 }); |
| 32 | 32 |
| 33 | 33 |
| 34 it('should bind checked', inject(() { | 34 it('should bind checked', () { |
| 35 _.compile('<input type="checkbox" ng-checked="isChecked" />'); | 35 _.compile('<input type="checkbox" ng-checked="isChecked" />'); |
| 36 _.rootScope.context['isChecked'] = false; | 36 _.rootScope.context['isChecked'] = false; |
| 37 _.rootScope.apply(); | 37 _.rootScope.apply(); |
| 38 expect(_.rootElement.attributes['checked']).toBeFalsy(); | 38 expect(_.rootElement.attributes['checked']).toBeFalsy(); |
| 39 _.rootScope.context['isChecked']=true; | 39 _.rootScope.context['isChecked']=true; |
| 40 _.rootScope.apply(); | 40 _.rootScope.apply(); |
| 41 expect(_.rootElement.attributes['checked']).toBeTruthy(); | 41 expect(_.rootElement.attributes['checked']).toBeTruthy(); |
| 42 })); | 42 }); |
| 43 | 43 |
| 44 | 44 |
| 45 it('should bind selected', inject(() { | 45 it('should bind selected', () { |
| 46 _.compile('<select><option value=""></option><option ng-selected="isSelect
ed">Greetings!</option></select>'); | 46 _.compile('<select><option value=""></option><option ng-selected="isSelect
ed">Greetings!</option></select>'); |
| 47 _.rootScope.context['isSelected']=false; | 47 _.rootScope.context['isSelected']=false; |
| 48 _.rootScope.apply(); | 48 _.rootScope.apply(); |
| 49 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeFa
lsy(); | 49 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeFa
lsy(); |
| 50 _.rootScope.context['isSelected']=true; | 50 _.rootScope.context['isSelected']=true; |
| 51 _.rootScope.apply(); | 51 _.rootScope.apply(); |
| 52 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeTr
uthy(); | 52 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeTr
uthy(); |
| 53 })); | 53 }); |
| 54 | 54 |
| 55 | 55 |
| 56 it('should bind readonly', inject(() { | 56 it('should bind readonly', () { |
| 57 _.compile('<input type="text" ng-readonly="isReadonly" />'); | 57 _.compile('<input type="text" ng-readonly="isReadonly" />'); |
| 58 _.rootScope.context['isReadonly']=false; | 58 _.rootScope.context['isReadonly']=false; |
| 59 _.rootScope.apply(); | 59 _.rootScope.apply(); |
| 60 expect(_.rootElement.attributes['readOnly']).toBeFalsy(); | 60 expect(_.rootElement.attributes['readOnly']).toBeFalsy(); |
| 61 _.rootScope.context['isReadonly']=true; | 61 _.rootScope.context['isReadonly']=true; |
| 62 _.rootScope.apply(); | 62 _.rootScope.apply(); |
| 63 expect(_.rootElement.attributes['readOnly']).toBeTruthy(); | 63 expect(_.rootElement.attributes['readOnly']).toBeTruthy(); |
| 64 })); | 64 }); |
| 65 | 65 |
| 66 | 66 |
| 67 it('should bind open', inject(() { | 67 it('should bind open', () { |
| 68 _.compile('<details ng-open="isOpen"></details>'); | 68 _.compile('<details ng-open="isOpen"></details>'); |
| 69 _.rootScope.context['isOpen']=false; | 69 _.rootScope.context['isOpen']=false; |
| 70 _.rootScope.apply(); | 70 _.rootScope.apply(); |
| 71 expect(_.rootElement.attributes['open']).toBeFalsy(); | 71 expect(_.rootElement.attributes['open']).toBeFalsy(); |
| 72 _.rootScope.context['isOpen']=true; | 72 _.rootScope.context['isOpen']=true; |
| 73 _.rootScope.apply(); | 73 _.rootScope.apply(); |
| 74 expect(_.rootElement.attributes['open']).toBeTruthy(); | 74 expect(_.rootElement.attributes['open']).toBeTruthy(); |
| 75 })); | 75 }); |
| 76 | 76 |
| 77 | 77 |
| 78 describe('multiple', () { | 78 describe('multiple', () { |
| 79 it('should NOT bind to multiple via ngMultiple', inject(() { | 79 it('should NOT bind to multiple via ngMultiple', () { |
| 80 _.compile('<select ng-multiple="isMultiple"></select>'); | 80 _.compile('<select ng-multiple="isMultiple"></select>'); |
| 81 _.rootScope.context['isMultiple']=false; | 81 _.rootScope.context['isMultiple']=false; |
| 82 _.rootScope.apply(); | 82 _.rootScope.apply(); |
| 83 expect(_.rootElement.attributes['multiple']).toBeFalsy(); | 83 expect(_.rootElement.attributes['multiple']).toBeFalsy(); |
| 84 _.rootScope.context['isMultiple']='multiple'; | 84 _.rootScope.context['isMultiple']='multiple'; |
| 85 _.rootScope.apply(); | 85 _.rootScope.apply(); |
| 86 expect(_.rootElement.attributes['multiple']).toBeFalsy(); // ignore | 86 expect(_.rootElement.attributes['multiple']).toBeFalsy(); // ignore |
| 87 })); | 87 }); |
| 88 }); | 88 }); |
| 89 }); | 89 }); |
| 90 | 90 |
| 91 | 91 |
| 92 describe('ngSrc', () { | 92 describe('ngSrc', () { |
| 93 TestBed _; | 93 TestBed _; |
| 94 beforeEach(inject((TestBed tb) => _ = tb)); | 94 beforeEach((TestBed tb) => _ = tb); |
| 95 | 95 |
| 96 it('should interpolate the expression and bind to src with raw same-domain v
alue', | 96 it('should interpolate the expression and bind to src with raw same-domain v
alue', () { |
| 97 inject(() { | |
| 98 _.compile('<div ng-src="{{id}}"></div>'); | |
| 99 | |
| 100 _.rootScope.apply(); | |
| 101 expect(_.rootElement.attributes['src']).toEqual(''); | |
| 102 | |
| 103 _.rootScope.apply(() { | |
| 104 _.rootScope.context['id'] = '/somewhere/here'; | |
| 105 }); | |
| 106 expect(_.rootElement.attributes['src']).toEqual('/somewhere/here'); | |
| 107 })); | |
| 108 | |
| 109 | |
| 110 xit('should interpolate the expression and bind to src with a trusted value'
, inject(($sce) { | |
| 111 _.compile('<div ng-src="{{id}}"></div>'); | 97 _.compile('<div ng-src="{{id}}"></div>'); |
| 112 | 98 |
| 113 _.rootScope.apply(); | 99 _.rootScope.apply(); |
| 114 expect(_.rootElement.attributes['src']).toEqual(null); | 100 expect(_.rootElement.attributes['src']).toEqual(null); |
| 115 | 101 |
| 116 _.rootScope.apply(() { | 102 _.rootScope.apply(() { |
| 117 _.rootScope.context['id'] = $sce.trustAsResourceUrl('http://somewhere'); | 103 _.rootScope.context['id'] = '/somewhere/here'; |
| 104 }); |
| 105 expect(_.rootElement.attributes['src']).toEqual('/somewhere/here'); |
| 106 }); |
| 107 |
| 108 |
| 109 xit('should interpolate the expression and bind to src with a trusted value'
, (sce) { |
| 110 _.compile('<div ng-src="{{id}}"></div>'); |
| 111 |
| 112 _.rootScope.apply(); |
| 113 expect(_.rootElement.attributes['src']).toEqual(null); |
| 114 |
| 115 _.rootScope.apply(() { |
| 116 _.rootScope.context['id'] = sce.trustAsResourceUrl('http://somewhere'); |
| 118 }); | 117 }); |
| 119 expect(_.rootElement.attributes['src']).toEqual('http://somewhere'); | 118 expect(_.rootElement.attributes['src']).toEqual('http://somewhere'); |
| 120 })); | 119 }); |
| 121 | 120 |
| 122 | 121 |
| 123 xit('should NOT interpolate a multi-part expression for non-img src attribut
e', inject(() { | 122 xit('should NOT interpolate a multi-part expression for non-img src attribut
e', () { |
| 124 expect(() { | 123 expect(() { |
| 125 _.compile('<div ng-src="some/{{id}}"></div>'); | 124 _.compile('<div ng-src="some/{{id}}"></div>'); |
| 126 }).toThrow("Error while interpolating: some/{{id}}\nStrict " + | 125 }).toThrow("Error while interpolating: some/{{id}}\nStrict " + |
| 127 "Contextual Escaping disallows interpolations that concatenate multipl
e expressions " + | 126 "Contextual Escaping disallows interpolations that concatenate multipl
e expressions " + |
| 128 "when a trusted value is required. See http://docs.angularjs.org/api/
ng.\$sce"); | 127 "when a trusted value is required. See http://docs.angularjs.org/api/
ng.sce"); |
| 129 })); | 128 }); |
| 130 | 129 |
| 131 | 130 |
| 132 it('should interpolate a multi-part expression for regular attributes', inje
ct(() { | 131 it('should interpolate a multi-part expression for regular attributes', () { |
| 133 _.compile('<div foo="some/{{id}}"></div>'); | 132 _.compile('<div foo="some/{{id}}"></div>'); |
| 134 _.rootScope.apply(); | 133 _.rootScope.apply(); |
| 135 expect(_.rootElement.attributes['foo']).toEqual('some/'); | 134 expect(_.rootElement.attributes['foo']).toEqual('some/'); |
| 136 _.rootScope.apply(() { | 135 _.rootScope.apply(() { |
| 137 _.rootScope.context['id'] = 1; | 136 _.rootScope.context['id'] = 1; |
| 138 }); | 137 }); |
| 139 expect(_.rootElement.attributes['foo']).toEqual('some/1'); | 138 expect(_.rootElement.attributes['foo']).toEqual('some/1'); |
| 140 })); | 139 }); |
| 141 | 140 |
| 142 | 141 |
| 143 xit('should NOT interpolate a wrongly typed expression', inject(($sce) { | 142 xit('should NOT interpolate a wrongly typed expression', (sce) { |
| 144 expect(() { | 143 expect(() { |
| 145 _.compile('<div ng-src="{{id}}"></div>'); | 144 _.compile('<div ng-src="{{id}}"></div>'); |
| 146 _.rootScope.apply(() { | 145 _.rootScope.apply(() { |
| 147 _.rootScope.context['id'] = $sce.trustAsUrl('http://somewhere'); | 146 _.rootScope.context['id'] = sce.trustAsUrl('http://somewhere'); |
| 148 }); | 147 }); |
| 149 _.rootElement.attributes['src']; | 148 _.rootElement.attributes['src']; |
| 150 }).toThrow("Can't interpolate: {{id}}\nError: [\$sce:insecurl] Blocked " + | 149 }).toThrow("Can't interpolate: {{id}}\nError: [sce:insecurl] Viewed " + |
| 151 "loading resource from url not allowed by \$sceDelegate policy. URL:
http://somewhere"); | 150 "loading resource from url not allowed by sceDelegate policy. URL: ht
tp://somewhere"); |
| 152 })); | 151 }); |
| 153 | 152 |
| 154 }); | 153 }); |
| 155 | 154 |
| 156 | 155 |
| 157 describe('ngSrcset', () { | 156 describe('ngSrcset', () { |
| 158 TestBed _; | 157 TestBed _; |
| 159 beforeEach(inject((TestBed tb) => _ = tb)); | 158 beforeEach((TestBed tb) => _ = tb); |
| 160 | 159 |
| 161 it('should interpolate the expression and bind to srcset', inject(() { | 160 it('should interpolate the expression and bind to srcset', () { |
| 162 _.compile('<div ng-srcset="some/{{id}} 2x"></div>'); | 161 _.compile('<div ng-srcset="some/{{id}} 2x"></div>'); |
| 163 | 162 |
| 164 _.rootScope.apply(); | 163 _.rootScope.apply(); |
| 165 expect(_.rootElement.attributes['srcset']).toEqual('some/ 2x'); | 164 expect(_.rootElement.attributes['srcset']).toEqual('some/ 2x'); |
| 166 | 165 |
| 167 _.rootScope.apply(() { | 166 _.rootScope.apply(() { |
| 168 _.rootScope.context['id'] = 1; | 167 _.rootScope.context['id'] = 1; |
| 169 }); | 168 }); |
| 170 expect(_.rootElement.attributes['srcset']).toEqual('some/1 2x'); | 169 expect(_.rootElement.attributes['srcset']).toEqual('some/1 2x'); |
| 171 })); | 170 }); |
| 172 }); | 171 }); |
| 173 | 172 |
| 174 | 173 |
| 175 describe('ngHref', () { | 174 describe('ngHref', () { |
| 176 TestBed _; | 175 TestBed _; |
| 177 beforeEach(inject((TestBed tb) => _ = tb)); | 176 beforeEach((TestBed tb) => _ = tb); |
| 178 | 177 |
| 179 it('should interpolate the expression and bind to href', inject(() { | 178 it('should interpolate the expression and bind to href', () { |
| 180 _.compile('<div ng-href="some/{{id}}"></div>'); | 179 _.compile('<div ng-href="some/{{id}}"></div>'); |
| 181 _.rootScope.apply(); | 180 _.rootScope.apply(); |
| 182 expect(_.rootElement.attributes['href']).toEqual('some/'); | 181 expect(_.rootElement.attributes['href']).toEqual('some/'); |
| 183 | 182 |
| 184 _.rootScope.apply(() { | 183 _.rootScope.apply(() { |
| 185 _.rootScope.context['id'] = 1; | 184 _.rootScope.context['id'] = 1; |
| 186 }); | 185 }); |
| 187 expect(_.rootElement.attributes['href']).toEqual('some/1'); | 186 expect(_.rootElement.attributes['href']).toEqual('some/1'); |
| 188 })); | 187 }); |
| 189 | 188 |
| 190 | 189 |
| 191 it('should bind href and merge with other attrs', inject(() { | 190 it('should bind href and merge with other attrs', () { |
| 192 _.compile('<a ng-href="{{url}}" rel="{{rel}}"></a>'); | 191 _.compile('<a ng-href="{{url}}" rel="{{rel}}"></a>'); |
| 193 _.rootScope.context['url'] = 'http://server'; | 192 _.rootScope.context['url'] = 'http://server'; |
| 194 _.rootScope.context['rel'] = 'REL'; | 193 _.rootScope.context['rel'] = 'REL'; |
| 195 _.rootScope.apply(); | 194 _.rootScope.apply(); |
| 196 expect(_.rootElement.attributes['href']).toEqual('http://server'); | 195 expect(_.rootElement.attributes['href']).toEqual('http://server'); |
| 197 expect(_.rootElement.attributes['rel']).toEqual('REL'); | 196 expect(_.rootElement.attributes['rel']).toEqual('REL'); |
| 198 })); | 197 }); |
| 199 | 198 |
| 200 | 199 |
| 201 it('should bind href even if no interpolation', inject(() { | 200 it('should bind href even if no interpolation', () { |
| 202 _.compile('<a ng-href="http://server"></a>'); | 201 _.compile('<a ng-href="http://server"></a>'); |
| 203 _.rootScope.apply(); | 202 _.rootScope.apply(); |
| 204 expect(_.rootElement.attributes['href']).toEqual('http://server'); | 203 expect(_.rootElement.attributes['href']).toEqual('http://server'); |
| 205 })); | 204 }); |
| 206 }); | 205 }); |
| 207 | 206 |
| 208 describe('ngAttr', () { | 207 describe('ngAttr', () { |
| 209 TestBed _; | 208 TestBed _; |
| 210 beforeEach(inject((TestBed tb) => _ = tb)); | 209 beforeEach((TestBed tb) => _ = tb); |
| 211 | 210 |
| 212 it('should interpolate the expression and bind to *', inject(() { | 211 it('should interpolate the expression and bind to *', () { |
| 213 _.compile('<div ng-attr-foo="some/{{id}}"></div>'); | 212 _.compile('<div ng-attr-foo="some/{{id}}"></div>'); |
| 214 _.rootScope.apply(); | 213 _.rootScope.apply(); |
| 215 expect(_.rootElement.attributes['foo']).toEqual('some/'); | 214 expect(_.rootElement.attributes['foo']).toEqual('some/'); |
| 216 | 215 |
| 217 _.rootScope.apply(() { | 216 _.rootScope.apply(() { |
| 218 _.rootScope.context['id'] = 1; | 217 _.rootScope.context['id'] = 1; |
| 219 }); | 218 }); |
| 220 expect(_.rootElement.attributes['foo']).toEqual('some/1'); | 219 expect(_.rootElement.attributes['foo']).toEqual('some/1'); |
| 221 })); | 220 }); |
| 222 | 221 |
| 223 | 222 |
| 224 it('should bind * and merge with other attrs', inject(() { | 223 it('should bind * and merge with other attrs', () { |
| 225 _.compile('<div ng-attr-bar="{{bar}}" ng-attr-bar2="{{bar2}}" bam="{{bam}}
"></a>'); | 224 _.compile('<div ng-attr-bar="{{bar}}" ng-attr-bar2="{{bar2}}" bam="{{bam}}
"></a>'); |
| 226 _.rootScope.context['bar'] = 'foo'; | 225 _.rootScope.context['bar'] = 'foo'; |
| 227 _.rootScope.context['bar2'] = 'foo2'; | 226 _.rootScope.context['bar2'] = 'foo2'; |
| 228 _.rootScope.context['bam'] = 'boom'; | 227 _.rootScope.context['bam'] = 'boom'; |
| 229 _.rootScope.apply(); | 228 _.rootScope.apply(); |
| 230 expect(_.rootElement.attributes['bar']).toEqual('foo'); | 229 expect(_.rootElement.attributes['bar']).toEqual('foo'); |
| 231 expect(_.rootElement.attributes['bar2']).toEqual('foo2'); | 230 expect(_.rootElement.attributes['bar2']).toEqual('foo2'); |
| 232 expect(_.rootElement.attributes['bam']).toEqual('boom'); | 231 expect(_.rootElement.attributes['bam']).toEqual('boom'); |
| 233 _.rootScope.context['bar'] = 'FOO'; | 232 _.rootScope.context['bar'] = 'FOO'; |
| 234 _.rootScope.context['bar2'] = 'FOO2'; | 233 _.rootScope.context['bar2'] = 'FOO2'; |
| 235 _.rootScope.context['bam'] = 'BOOM'; | 234 _.rootScope.context['bam'] = 'BOOM'; |
| 236 _.rootScope.apply(); | 235 _.rootScope.apply(); |
| 237 expect(_.rootElement.attributes['bar']).toEqual('FOO'); | 236 expect(_.rootElement.attributes['bar']).toEqual('FOO'); |
| 238 expect(_.rootElement.attributes['bar2']).toEqual('FOO2'); | 237 expect(_.rootElement.attributes['bar2']).toEqual('FOO2'); |
| 239 expect(_.rootElement.attributes['bam']).toEqual('BOOM'); | 238 expect(_.rootElement.attributes['bam']).toEqual('BOOM'); |
| 240 })); | 239 }); |
| 241 | 240 |
| 242 | 241 |
| 243 it('should bind * even if no interpolation', inject(() { | 242 it('should bind * even if no interpolation', () { |
| 244 _.compile('<a ng-attr-quack="vanilla"></a>'); | 243 _.compile('<a ng-attr-quack="vanilla"></a>'); |
| 245 _.rootScope.apply(); | 244 _.rootScope.apply(); |
| 246 expect(_.rootElement.attributes['quack']).toEqual('vanilla'); | 245 expect(_.rootElement.attributes['quack']).toEqual('vanilla'); |
| 247 })); | 246 }); |
| 248 }); | 247 }); |
| 249 } | 248 } |
| OLD | NEW |