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.paper_radio_group_basic_test; | 5 library polymer_elements.test.paper_radio_group_basic_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
9 import 'package:web_components/web_components.dart'; | 9 import 'package:web_components/web_components.dart'; |
10 import 'package:polymer_elements/paper_radio_group.dart'; | 10 import 'package:polymer_elements/paper_radio_group.dart'; |
11 import 'common.dart'; | 11 import 'common.dart'; |
12 | 12 |
13 main() async { | 13 main() async { |
14 await initWebComponents(); | 14 await initWebComponents(); |
15 | 15 |
16 group('defaults', () { | 16 group('defaults', () { |
17 var LEFT_ARROW = 37; | 17 var LEFT_ARROW = 37; |
18 var RIGHT_ARROW = 39; | 18 var RIGHT_ARROW = 39; |
| 19 |
19 test('group can have no selection', () { | 20 test('group can have no selection', () { |
20 PaperRadioGroup g = fixture('NoSelection'); | 21 PaperRadioGroup g = fixture('NoSelection'); |
21 expect(g.selected, isNull); | 22 expect(g.selected, isNull); |
22 var items = g.items; | 23 var items = g.items; |
23 expect(items.length, equals(3)); | 24 expect(items.length, equals(3)); |
24 expect(items[0].checked, isFalse); | 25 expect(items[0].checked, isFalse); |
25 expect(items[1].checked, isFalse); | 26 expect(items[1].checked, isFalse); |
26 expect(items[2].checked, isFalse); | 27 expect(items[2].checked, isFalse); |
27 }); | 28 }); |
| 29 |
28 test('group can have a selection', () { | 30 test('group can have a selection', () { |
29 PaperRadioGroup g = fixture('WithSelection'); | 31 PaperRadioGroup g = fixture('WithSelection'); |
30 expect(g.selected, isNotNull); | 32 expect(g.selected, isNotNull); |
31 var items = g.items; | 33 var items = g.items; |
32 expect(items.length, equals(3)); | 34 expect(items.length, equals(3)); |
33 expect(items[0].checked, isTrue); | 35 expect(items[0].checked, isTrue); |
34 expect(items[1].checked, isFalse); | 36 expect(items[1].checked, isFalse); |
35 expect(items[2].checked, isFalse); | 37 expect(items[2].checked, isFalse); |
36 expect(items[0].attributes['name'], equals(g.selected)); | 38 expect(items[0].attributes['name'], equals(g.selected)); |
37 }); | 39 }); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 await completer.future; | 99 await completer.future; |
98 }); | 100 }); |
99 | 101 |
100 test('clicking the selected item should not deselect', () async { | 102 test('clicking the selected item should not deselect', () async { |
101 PaperRadioGroup g = fixture('WithSelection'); | 103 PaperRadioGroup g = fixture('WithSelection'); |
102 var items = g.items; | 104 var items = g.items; |
103 expect(items[0].checked, isTrue); | 105 expect(items[0].checked, isTrue); |
104 tap(items[0]); | 106 tap(items[0]); |
105 // The selection should not change, but wait for a little bit just | 107 // The selection should not change, but wait for a little bit just |
106 // in case it would and an event would be fired. | 108 // in case it would and an event would be fired. |
107 await wait(200); | 109 await wait(1); |
108 | 110 |
109 expect(items[0].checked, isTrue); | 111 expect(items[0].checked, isTrue); |
110 expect(items[1].checked, isFalse); | 112 expect(items[1].checked, isFalse); |
111 expect(items[2].checked, isFalse); | 113 expect(items[2].checked, isFalse); |
112 }); | 114 }); |
| 115 |
| 116 test('clicking the selected item should deselect if allow-empty-selection is
set', () async { |
| 117 var g = fixture('WithSelection'); |
| 118 g.allowEmptySelection = true; |
| 119 var items = g.items; |
| 120 |
| 121 expect(items[0].checked, true); |
| 122 tap(items[0]); |
| 123 |
| 124 // The selection should not change, but wait for a little bit just |
| 125 // in case it would and an event would be fired. |
| 126 await wait(1); |
| 127 |
| 128 expect(items[0].checked, false); |
| 129 expect(items[1].checked, false); |
| 130 expect(items[2].checked, false); |
| 131 }); |
113 }); | 132 }); |
114 } | 133 } |
OLD | NEW |