OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 library selectelement_test; | 5 library selectelement_test; |
6 import '../../pkg/unittest/lib/unittest.dart'; | 6 import '../../pkg/unittest/lib/unittest.dart'; |
7 import '../../pkg/unittest/lib/html_config.dart'; | 7 import '../../pkg/unittest/lib/html_config.dart'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 | 9 |
10 main() { | 10 main() { |
11 useHtmlConfiguration(); | 11 useHtmlConfiguration(); |
12 | 12 |
13 test('selectedOptions', () { | 13 test('selectedOptions', () { |
14 var element = new SelectElement(); | 14 var element = new SelectElement(); |
15 element.multiple = false; | 15 element.multiple = false; |
16 var options = [ | 16 var options = [ |
17 new OptionElement(), | 17 new OptionElement(), |
18 new DivElement(), | 18 new DivElement(), |
19 new OptionElement(data: 'data', value: 'two', defaultSelected: false, | 19 new OptionElement(data: 'data', value: 'two', selected: true), |
20 selected: true), | |
21 new DivElement(), | 20 new DivElement(), |
22 new OptionElement(data: 'data', value: 'two', defaultSelected: false, | 21 new OptionElement(data: 'data', value: 'two', selected: true), |
23 selected: true), | |
24 new OptionElement(), | 22 new OptionElement(), |
25 ]; | 23 ]; |
26 element.children.addAll(options); | 24 element.children.addAll(options); |
27 expect(element.selectedOptions.length, 1); | 25 expect(element.selectedOptions.length, 1); |
28 expect(element.selectedOptions[0], equals(options[4])); | 26 expect(element.selectedOptions[0], equals(options[4])); |
29 }); | 27 }); |
30 | 28 |
31 test('multiple selectedOptions', () { | 29 test('multiple selectedOptions', () { |
32 var element = new SelectElement(); | 30 var element = new SelectElement(); |
33 element.multiple = true; | 31 element.multiple = true; |
34 var options = [ | 32 var options = [ |
35 new OptionElement(), | 33 new OptionElement(), |
36 new DivElement(), | 34 new DivElement(), |
37 new OptionElement(data: 'data', value: 'two', defaultSelected: false, | 35 new OptionElement(data: 'data', value: 'two', selected: true), |
38 selected: true), | |
39 new DivElement(), | 36 new DivElement(), |
40 new OptionElement(data: 'data', value: 'two', defaultSelected: false, | 37 new OptionElement(data: 'data', value: 'two', selected: true), |
41 selected: true), | |
42 new OptionElement(), | 38 new OptionElement(), |
| 39 new OptionElement(data: 'data', value: 'two', selected: false), |
43 ]; | 40 ]; |
44 element.children.addAll(options); | 41 element.children.addAll(options); |
45 expect(element.selectedOptions.length, 2); | 42 expect(element.selectedOptions.length, 2); |
46 expect(element.selectedOptions[0], equals(options[2])); | 43 expect(element.selectedOptions[0], equals(options[2])); |
47 expect(element.selectedOptions[1], equals(options[4])); | 44 expect(element.selectedOptions[1], equals(options[4])); |
48 }); | 45 }); |
49 | 46 |
50 test('options', () { | 47 test('options', () { |
51 var element = new SelectElement(); | 48 var element = new SelectElement(); |
52 var options = [ | 49 var options = [ |
53 new OptionElement(), | 50 new OptionElement(), |
54 new OptionElement(data: 'data', value: 'two', defaultSelected: false, | 51 new OptionElement(data: 'data', value: 'two', selected: true), |
55 selected: true), | 52 new OptionElement(data: 'data', value: 'two', selected: true), |
56 new OptionElement(data: 'data', value: 'two', defaultSelected: false, | |
57 selected: true), | |
58 new OptionElement(), | 53 new OptionElement(), |
59 ]; | 54 ]; |
60 element.children.addAll(options); | 55 element.children.addAll(options); |
61 // Use last to make sure that the list was correctly wrapped. | 56 // Use last to make sure that the list was correctly wrapped. |
62 expect(element.options.last, equals(options[3])); | 57 expect(element.options.last, equals(options[3])); |
63 }); | 58 }); |
64 | 59 |
65 test('optgroup', () { | 60 test('optgroup', () { |
66 var element = new Element.html( | 61 var element = new Element.html( |
67 '<select>' | 62 '<select>' |
68 '<option>1</option>' | 63 '<option>1</option>' |
69 '<optgroup>' | 64 '<optgroup>' |
70 '<option>2</option>' | 65 '<option>2</option>' |
71 '</optgroup>' | 66 '</optgroup>' |
72 '</select>'); | 67 '</select>'); |
73 | 68 |
74 expect(element.options.length, 2); | 69 expect(element.options.length, 2); |
75 element.selectedIndex = 1; | 70 element.selectedIndex = 1; |
76 | 71 |
77 var optGroup = element.children[1]; | 72 var optGroup = element.children[1]; |
78 expect(optGroup is OptGroupElement, isTrue); | 73 expect(optGroup is OptGroupElement, isTrue); |
79 expect(optGroup.children.single.selected, isTrue); | 74 expect(optGroup.children.single.selected, isTrue); |
80 expect(element.selectedOptions, optGroup.children); | 75 expect(element.selectedOptions, optGroup.children); |
81 }); | 76 }); |
82 } | 77 } |
OLD | NEW |