Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: third_party/pkg/angular/test/directive/ng_src_boolean_spec.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 library ng_src_boolean_spec;
2
3 import '../_specs.dart';
4 import 'dart:html' as dom;
5
6 main() {
7 describe('boolean attr directives', () {
8 TestBed _;
9 beforeEach(inject((TestBed tb) => _ = tb));
10
11
12 it('should properly evaluate 0 as false', inject(() {
13 _.compile('<button ng-disabled="isDisabled">Button</button>');
14 _.rootScope.isDisabled = 0;
15 _.rootScope.$digest();
16 expect(_.rootElement.attributes['disabled']).toBeFalsy();
17 _.rootScope.isDisabled = 1;
18 _.rootScope.$digest();
19 expect(_.rootElement.attributes['disabled']).toBeTruthy();
20 }));
21
22
23 it('should bind disabled', inject(() {
24 _.compile('<button ng-disabled="isDisabled">Button</button>');
25 _.rootScope.isDisabled = false;
26 _.rootScope.$digest();
27 expect(_.rootElement.attributes['disabled']).toBeFalsy();
28 _.rootScope.isDisabled = true;
29 _.rootScope.$digest();
30 expect(_.rootElement.attributes['disabled']).toBeTruthy();
31 }));
32
33
34 it('should bind checked', inject(() {
35 _.compile('<input type="checkbox" ng-checked="isChecked" />');
36 _.rootScope.isChecked = false;
37 _.rootScope.$digest();
38 expect(_.rootElement.attributes['checked']).toBeFalsy();
39 _.rootScope.isChecked=true;
40 _.rootScope.$digest();
41 expect(_.rootElement.attributes['checked']).toBeTruthy();
42 }));
43
44
45 it('should bind selected', inject(() {
46 _.compile('<select><option value=""></option><option ng-selected="isSelect ed">Greetings!</option></select>');
47 _.rootScope.isSelected=false;
48 _.rootScope.$digest();
49 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeFa lsy();
50 _.rootScope.isSelected=true;
51 _.rootScope.$digest();
52 expect((_.rootElement.childNodes[1] as dom.OptionElement).selected).toBeTr uthy();
53 }));
54
55
56 it('should bind readonly', inject(() {
57 _.compile('<input type="text" ng-readonly="isReadonly" />');
58 _.rootScope.isReadonly=false;
59 _.rootScope.$digest();
60 expect(_.rootElement.attributes['readOnly']).toBeFalsy();
61 _.rootScope.isReadonly=true;
62 _.rootScope.$digest();
63 expect(_.rootElement.attributes['readOnly']).toBeTruthy();
64 }));
65
66
67 it('should bind open', inject(() {
68 _.compile('<details ng-open="isOpen"></details>');
69 _.rootScope.isOpen=false;
70 _.rootScope.$digest();
71 expect(_.rootElement.attributes['open']).toBeFalsy();
72 _.rootScope.isOpen=true;
73 _.rootScope.$digest();
74 expect(_.rootElement.attributes['open']).toBeTruthy();
75 }));
76
77
78 describe('multiple', () {
79 it('should NOT bind to multiple via ngMultiple', inject(() {
80 _.compile('<select ng-multiple="isMultiple"></select>');
81 _.rootScope.isMultiple=false;
82 _.rootScope.$digest();
83 expect(_.rootElement.attributes['multiple']).toBeFalsy();
84 _.rootScope.isMultiple='multiple';
85 _.rootScope.$digest();
86 expect(_.rootElement.attributes['multiple']).toBeFalsy(); // ignore
87 }));
88 });
89 });
90
91
92 describe('ngSrc', () {
93 TestBed _;
94 beforeEach(inject((TestBed tb) => _ = tb));
95
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.$digest();
101 expect(_.rootElement.attributes['src']).toEqual('');
102
103 _.rootScope.$apply(() {
104 _.rootScope.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>');
112
113 _.rootScope.$digest();
114 expect(_.rootElement.attributes['src']).toEqual(null);
115
116 _.rootScope.$apply(() {
117 _.rootScope.id = $sce.trustAsResourceUrl('http://somewhere');
118 });
119 expect(_.rootElement.attributes['src']).toEqual('http://somewhere');
120 }));
121
122
123 xit('should NOT interpolate a multi-part expression for non-img src attribut e', inject(() {
124 expect(() {
125 _.compile('<div ng-src="some/{{id}}"></div>');
126 }).toThrow("Error while interpolating: some/{{id}}\nStrict " +
127 "Contextual Escaping disallows interpolations that concatenate multipl e expressions " +
128 "when a trusted value is required. See http://docs.angularjs.org/api/ ng.\$sce");
129 }));
130
131
132 it('should interpolate a multi-part expression for regular attributes', inje ct(() {
133 _.compile('<div foo="some/{{id}}"></div>');
134 _.rootScope.$digest();
135 expect(_.rootElement.attributes['foo']).toEqual('some/');
136 _.rootScope.$apply(() {
137 _.rootScope.id = 1;
138 });
139 expect(_.rootElement.attributes['foo']).toEqual('some/1');
140 }));
141
142
143 xit('should NOT interpolate a wrongly typed expression', inject(($sce) {
144 expect(() {
145 _.compile('<div ng-src="{{id}}"></div>');
146 _.rootScope.$apply(() {
147 _.rootScope.id = $sce.trustAsUrl('http://somewhere');
148 });
149 _.rootElement.attributes['src'];
150 }).toThrow("Can't interpolate: {{id}}\nError: [\$sce:insecurl] Blocked " +
151 "loading resource from url not allowed by \$sceDelegate policy. URL: http://somewhere");
152 }));
153
154 });
155
156
157 describe('ngSrcset', () {
158 TestBed _;
159 beforeEach(inject((TestBed tb) => _ = tb));
160
161 it('should interpolate the expression and bind to srcset', inject(() {
162 _.compile('<div ng-srcset="some/{{id}} 2x"></div>');
163
164 _.rootScope.$digest();
165 expect(_.rootElement.attributes['srcset']).toEqual('some/ 2x');
166
167 _.rootScope.$apply(() {
168 _.rootScope.id = 1;
169 });
170 expect(_.rootElement.attributes['srcset']).toEqual('some/1 2x');
171 }));
172 });
173
174
175 describe('ngHref', () {
176 TestBed _;
177 beforeEach(inject((TestBed tb) => _ = tb));
178
179 it('should interpolate the expression and bind to href', inject(() {
180 _.compile('<div ng-href="some/{{id}}"></div>');
181 _.rootScope.$digest();
182 expect(_.rootElement.attributes['href']).toEqual('some/');
183
184 _.rootScope.$apply(() {
185 _.rootScope.id = 1;
186 });
187 expect(_.rootElement.attributes['href']).toEqual('some/1');
188 }));
189
190
191 it('should bind href and merge with other attrs', inject(() {
192 _.compile('<a ng-href="{{url}}" rel="{{rel}}"></a>');
193 _.rootScope.url = 'http://server';
194 _.rootScope.rel = 'REL';
195 _.rootScope.$digest();
196 expect(_.rootElement.attributes['href']).toEqual('http://server');
197 expect(_.rootElement.attributes['rel']).toEqual('REL');
198 }));
199
200
201 it('should bind href even if no interpolation', inject(() {
202 _.compile('<a ng-href="http://server"></a>');
203 _.rootScope.$digest();
204 expect(_.rootElement.attributes['href']).toEqual('http://server');
205 }));
206 });
207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698