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