OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_config.dart'; | 7 import 'package:unittest/html_config.dart'; |
8 import 'package:polymer/polymer.dart'; | 8 import 'package:polymer/polymer.dart'; |
9 | 9 |
10 @CustomTag('my-element') | 10 @CustomTag('my-element') |
11 class MyElement extends PolymerElement { | 11 class MyElement extends PolymerElement { |
12 MyElement.created() : super.created(); | 12 MyElement.created() : super.created(); |
13 | 13 |
14 @published double volume; | 14 @published double volume; |
15 @published int factor; | 15 @published int factor; |
16 @published bool crankIt; | 16 @published bool crankIt; |
17 @published String msg; | 17 @published String msg; |
18 @published DateTime time; | 18 @published DateTime time; |
19 @published Object json; | 19 @published Object json; |
20 } | 20 } |
21 | 21 |
22 @initMethod | 22 main() => initPolymer().run(() { |
23 main() { | |
24 useHtmlConfiguration(); | 23 useHtmlConfiguration(); |
25 | 24 |
26 setUp(() => Polymer.onReady); | 25 setUp(() => Polymer.onReady); |
27 | 26 |
28 test('attributes were deserialized', () { | 27 test('attributes were deserialized', () { |
29 MyElement elem = querySelector('my-element'); | 28 MyElement elem = querySelector('my-element'); |
30 final msg = 'property should match attribute.'; | 29 final msg = 'property should match attribute.'; |
31 expect(elem.volume, 11.0, reason: '"volume" should match attribute'); | 30 expect(elem.volume, 11.0, reason: '"volume" should match attribute'); |
32 expect(elem.factor, 3, reason: '"factor" should match attribute'); | 31 expect(elem.factor, 3, reason: '"factor" should match attribute'); |
33 expect(elem.crankIt, true, reason: '"crankIt" should match attribute'); | 32 expect(elem.crankIt, true, reason: '"crankIt" should match attribute'); |
34 expect(elem.msg, "Yo!", reason: '"msg" should match attribute'); | 33 expect(elem.msg, "Yo!", reason: '"msg" should match attribute'); |
35 expect(elem.time, DateTime.parse('2013-08-08T18:34Z'), | 34 expect(elem.time, DateTime.parse('2013-08-08T18:34Z'), |
36 reason: '"time" should match attribute'); | 35 reason: '"time" should match attribute'); |
37 expect(elem.json, {'here': 'is', 'some': 'json', 'x': 123}, | 36 expect(elem.json, {'here': 'is', 'some': 'json', 'x': 123}, |
38 reason: '"json" should match attribute'); | 37 reason: '"json" should match attribute'); |
39 | 38 |
40 var text = elem.shadowRoot.text; | 39 var text = elem.shadowRoot.text; |
41 // Collapse adjacent whitespace like a browser would: | 40 // Collapse adjacent whitespace like a browser would: |
42 text = text.replaceAll('\n', ' ').replaceAll(new RegExp(r'\s+'), ' '); | 41 text = text.replaceAll('\n', ' ').replaceAll(new RegExp(r'\s+'), ' '); |
43 | 42 |
44 // Note: using "${33.0}" because the toString differs in JS vs Dart VM. | 43 // Note: using "${33.0}" because the toString differs in JS vs Dart VM. |
45 expect(text, " Yo! The volume is ${33.0} !! The time is " | 44 expect(text, " Yo! The volume is ${33.0} !! The time is " |
46 "2013-08-08 18:34:00.000Z and here's some JSON: " | 45 "2013-08-08 18:34:00.000Z and here's some JSON: " |
47 "{here: is, some: json, x: 123} ", | 46 "{here: is, some: json, x: 123} ", |
48 reason: 'text should match expected HTML template'); | 47 reason: 'text should match expected HTML template'); |
49 }); | 48 }); |
50 } | 49 }); |
OLD | NEW |