OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:html'; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:unittest/html_config.dart'; |
| 8 import 'package:polymer/polymer.dart'; |
| 9 |
| 10 @CustomTag('x-foo') |
| 11 class XFoo extends PolymerElement { |
| 12 XFoo.created() : super.created(); |
| 13 |
| 14 @published bool boolean = false; |
| 15 @published num number = 42; |
| 16 @published String str = "don't panic"; |
| 17 } |
| 18 |
| 19 @CustomTag('x-bar') |
| 20 class XBar extends PolymerElement { |
| 21 XBar.created() : super.created(); |
| 22 |
| 23 @observable bool boolean = false; |
| 24 @observable num number = 42; |
| 25 @observable String str = "don't panic"; |
| 26 } |
| 27 |
| 28 @CustomTag('x-zot') |
| 29 class XZot extends XBar { |
| 30 XZot.created() : super.created(); |
| 31 @observable num number = 84; |
| 32 } |
| 33 |
| 34 @CustomTag('x-date') |
| 35 class XDate extends PolymerElement { |
| 36 XDate.created() : super.created(); |
| 37 @observable var value = new DateTime(2013, 9, 25); |
| 38 } |
| 39 |
| 40 @CustomTag('x-array') |
| 41 class XArray extends PolymerElement { |
| 42 XArray.created() : super.created(); |
| 43 @observable List values; |
| 44 } |
| 45 |
| 46 @CustomTag('x-obj') |
| 47 class XObj extends PolymerElement { |
| 48 XObj.created() : super.created(); |
| 49 @observable var values = {}; |
| 50 } |
| 51 |
| 52 main() => initPolymer().then((zone) => zone.run(() { |
| 53 useHtmlConfiguration(); |
| 54 |
| 55 setUp(() => Polymer.onReady); |
| 56 |
| 57 test('take attributes', () { |
| 58 queryXTag(x) => document.querySelector(x); |
| 59 |
| 60 expect(queryXTag("#foo0").boolean, true); |
| 61 expect(queryXTag("#foo1").boolean, false); |
| 62 expect(queryXTag("#foo2").boolean, true); |
| 63 expect(queryXTag("#foo3").boolean, false); |
| 64 // this one is only 'truthy' |
| 65 expect(queryXTag("#foo4").boolean, true); |
| 66 // this one is also 'truthy', but should it be? |
| 67 expect(queryXTag("#foo5").boolean, true); |
| 68 // |
| 69 expect(queryXTag("#foo0").number, 42); |
| 70 expect(queryXTag("#foo0").str, "don't panic"); |
| 71 // |
| 72 expect(queryXTag("#bar0").boolean, true); |
| 73 expect(queryXTag("#bar1").boolean, false); |
| 74 expect(queryXTag("#bar2").boolean, true); |
| 75 expect(queryXTag("#bar3").boolean, false); |
| 76 // this one is only 'truthy' |
| 77 expect(queryXTag("#bar4").boolean, true); |
| 78 // this one is also 'truthy', but should it be? |
| 79 expect(queryXTag("#bar5").boolean, true); |
| 80 // |
| 81 expect(queryXTag("#bar0").number, 42); |
| 82 expect(queryXTag("#bar0").str, "don't panic"); |
| 83 // |
| 84 expect(queryXTag("#zot0").boolean, true); |
| 85 expect(queryXTag("#zot1").boolean, false); |
| 86 expect(queryXTag("#zot2").boolean, true); |
| 87 expect(queryXTag("#zot3").boolean, false); |
| 88 // this one is only 'truthy' |
| 89 expect(queryXTag("#zot4").boolean, true); |
| 90 // this one is also 'truthy', but should it be? |
| 91 expect(queryXTag("#zot5").boolean, true); |
| 92 // |
| 93 // Issue 14096 - field initializers are in the incorrect order. |
| 94 // This should be expecting 84. |
| 95 //expect(queryXTag("#zot0").number, 84); |
| 96 expect(queryXTag("#zot6").number, 185); |
| 97 expect(queryXTag("#zot0").str, "don't panic"); |
| 98 // |
| 99 // Date deserialization tests |
| 100 expect(queryXTag("#date1").value, new DateTime(2014, 12, 25)); |
| 101 expect(queryXTag("#date2").value, isNot(equals(new DateTime(2014, 12, 25))), |
| 102 reason: 'Dart does not support this format'); |
| 103 expect(queryXTag("#date3").value, new DateTime(2014, 12, 25, 11, 45)); |
| 104 expect(queryXTag("#date4").value, new DateTime(2014, 12, 25, 11, 45, 30)); |
| 105 // Failures on Firefox. Need to fix this with custom parsing |
| 106 //expect(String(queryXTag("#date5").value), String(new Date(2014, 11, 25, 11
, 45, 30))); |
| 107 // |
| 108 // milliseconds in the Date string not supported on Firefox |
| 109 //expect(queryXTag("#date5").value.getMilliseconds(), new Date(2014, 11, 25,
11, 45, 30, 33).getMilliseconds()); |
| 110 // |
| 111 // Array deserialization tests |
| 112 expect(queryXTag("#arr1").values, [0, 1, 2]); |
| 113 expect(queryXTag("#arr2").values, [33]); |
| 114 // Object deserialization tests |
| 115 expect(queryXTag("#obj1").values, {'name': 'Brandon', 'nums': [1, 22, 33]}); |
| 116 expect(queryXTag("#obj2").values, {"color": "Red"}); |
| 117 expect(queryXTag("#obj3").values, { |
| 118 'movie': 'Buckaroo Banzai', |
| 119 'DOB': '07/31/1978' |
| 120 }); |
| 121 }); |
| 122 })); |
OLD | NEW |