| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 @TestOn('browser') | 4 @TestOn('browser') |
| 5 library polymer_elements.test.iron_input_test; | 5 library polymer_elements.test.iron_input_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'dart:js'; | 9 import 'dart:js'; |
| 10 import 'package:polymer/polymer.dart'; |
| 10 import 'package:polymer_elements/iron_input.dart'; | 11 import 'package:polymer_elements/iron_input.dart'; |
| 11 import 'package:test/test.dart'; | 12 import 'package:test/test.dart'; |
| 12 import 'package:web_components/web_components.dart'; | 13 import 'package:web_components/web_components.dart'; |
| 13 import 'common.dart'; | 14 import 'common.dart'; |
| 14 | 15 |
| 15 main() async { | 16 main() async { |
| 16 await initWebComponents(); | 17 await initPolymer(); |
| 18 var x = 'hello'; |
| 17 | 19 |
| 18 group('basic', () { | 20 group('basic', () { |
| 19 test('setting bindValue sets value', () { | 21 test('setting bindValue sets value', () { |
| 20 IronInput input = fixture('basic'); | 22 IronInput input = fixture('basic'); |
| 21 input.bindValue = 'foobar'; | 23 input.bindValue = 'foobar'; |
| 22 expect(input.value, input.bindValue, reason: 'value equals to bindValue'); | 24 expect(input.value, input.bindValue, reason: 'value equals to bindValue'); |
| 23 }); | 25 }); |
| 24 | 26 |
| 25 test('changing the input triggers an event', () { | 27 test('changing the input triggers an event', () { |
| 26 var done = new Completer(); | 28 var done = new Completer(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 IronInput input = fixture('has-value'); | 42 IronInput input = fixture('has-value'); |
| 41 expect(input.bindValue, input.value, reason: 'bindValue equals value'); | 43 expect(input.bindValue, input.value, reason: 'bindValue equals value'); |
| 42 }); | 44 }); |
| 43 | 45 |
| 44 test('default bindValue sets value', () { | 46 test('default bindValue sets value', () { |
| 45 IronInput input = fixture('has-bind-value'); | 47 IronInput input = fixture('has-bind-value'); |
| 46 expect(input.value, input.bindValue, reason: 'value equals to bindValue'); | 48 expect(input.value, input.bindValue, reason: 'value equals to bindValue'); |
| 47 }); | 49 }); |
| 48 | 50 |
| 49 test('set bindValue to undefined', () { | 51 test('set bindValue to undefined', () { |
| 50 var scope = new JsObject.fromBrowserObject( | 52 DomBind scope = document.getElementById('bind-to-object'); |
| 51 document.getElementById('bind-to-object')); | |
| 52 scope['foo'] = null; | 53 scope['foo'] = null; |
| 53 expect(scope[r'$']['input'].bindValue, isNull, | 54 expect(scope.$['input'].bindValue, isNull, |
| 54 reason: 'bindValue is falsy'); | 55 reason: 'bindValue is falsy'); |
| 55 expect(scope[r'$']['input'].value, isEmpty, reason: 'value is falsy'); | 56 expect(scope.$['input'].value, isEmpty, reason: 'value is falsy'); |
| 56 }); | 57 }); |
| 57 | 58 |
| 58 test('validator used instead of constraints api if provided', () { | 59 test('validator used instead of constraints api if provided', () { |
| 59 IronInput input = fixture('has-validator')[1]; | 60 IronInput input = fixture('has-validator')[1]; |
| 60 input.value = '123'; | 61 input.value = '123'; |
| 61 input.validate(); | 62 input.validate(); |
| 62 expect(input.invalid, isTrue, reason: 'input is invalid'); | 63 expect(input.invalid, isTrue, reason: 'input is invalid'); |
| 63 }); | 64 }); |
| 64 | 65 |
| 65 test('prevent invalid input works in _onInput', () { | 66 test('prevent invalid input works in _onInput', () { |
| 66 IronInput input = fixture('prevent-invalid-input'); | 67 IronInput input = fixture('prevent-invalid-input'); |
| 67 input.value = '123'; | 68 input.value = '123'; |
| 68 input.jsElement.callMethod('_onInput'); | 69 input.jsElement.callMethod('_onInput'); |
| 69 expect(input.bindValue, '123'); | 70 expect(input.bindValue, '123'); |
| 70 input.value = '123foo'; | 71 input.value = '123foo'; |
| 71 input.jsElement.callMethod('_onInput'); | 72 input.jsElement.callMethod('_onInput'); |
| 72 expect(input.bindValue, '123'); | 73 expect(input.bindValue, '123'); |
| 73 }); | 74 }); |
| 74 }); | 75 }); |
| 75 } | 76 } |
| OLD | NEW |