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