OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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 import 'dart:html'; |
| 5 import 'package:unittest/unittest.dart'; |
| 6 import 'package:observatory/src/elements/curly_block.dart'; |
| 7 |
| 8 main() { |
| 9 CurlyBlockElement.tag.ensureRegistration(); |
| 10 |
| 11 group('instantiation', () { |
| 12 test('default', () { |
| 13 final CurlyBlockElement e = new CurlyBlockElement(); |
| 14 expect(e, isNotNull, reason: 'element correctly created'); |
| 15 expect(e.expanded, isFalse); |
| 16 expect(e.disabled, isFalse); |
| 17 }); |
| 18 test('not expanded', () { |
| 19 final CurlyBlockElement e = new CurlyBlockElement(expanded: false); |
| 20 expect(e, isNotNull, reason: 'element correctly created'); |
| 21 expect(e.expanded, isFalse); |
| 22 expect(e.disabled, isFalse); |
| 23 }); |
| 24 test('not expanded / not disabled', () { |
| 25 final CurlyBlockElement e = new CurlyBlockElement(expanded: false, |
| 26 disabled: false); |
| 27 expect(e, isNotNull, reason: 'element correctly created'); |
| 28 expect(e.expanded, isFalse); |
| 29 expect(e.disabled, isFalse); |
| 30 }); |
| 31 test('not expanded / disabled', () { |
| 32 final CurlyBlockElement e = new CurlyBlockElement(expanded: false, |
| 33 disabled: true); |
| 34 expect(e, isNotNull, reason: 'element correctly created'); |
| 35 expect(e.expanded, isFalse); |
| 36 expect(e.disabled, isTrue); |
| 37 }); |
| 38 test('expanded', () { |
| 39 final CurlyBlockElement e = new CurlyBlockElement(expanded: true); |
| 40 expect(e, isNotNull, reason: 'element correctly created'); |
| 41 expect(e.expanded, isTrue); |
| 42 expect(e.disabled, isFalse); |
| 43 }); |
| 44 test('expanded / not disabled', () { |
| 45 final CurlyBlockElement e = new CurlyBlockElement(expanded: true, |
| 46 disabled: false); |
| 47 expect(e, isNotNull, reason: 'element correctly created'); |
| 48 expect(e.expanded, isTrue); |
| 49 expect(e.disabled, isFalse); |
| 50 }); |
| 51 test('expanded / disabled', () { |
| 52 final CurlyBlockElement e = new CurlyBlockElement(expanded: true, |
| 53 disabled: true); |
| 54 expect(e, isNotNull, reason: 'element correctly created'); |
| 55 expect(e.expanded, isTrue); |
| 56 expect(e.disabled, isTrue); |
| 57 }); |
| 58 test('not disabled', () { |
| 59 final CurlyBlockElement e = new CurlyBlockElement(disabled: false); |
| 60 expect(e, isNotNull, reason: 'element correctly created'); |
| 61 expect(e.expanded, isFalse); |
| 62 expect(e.disabled, isFalse); |
| 63 }); |
| 64 test('disabled', () { |
| 65 final CurlyBlockElement e = new CurlyBlockElement(disabled: true); |
| 66 expect(e, isNotNull, reason: 'element correctly created'); |
| 67 expect(e.expanded, isFalse); |
| 68 expect(e.disabled, isTrue); |
| 69 }); |
| 70 }); |
| 71 test('elements created', () async { |
| 72 final CurlyBlockElement e = new CurlyBlockElement(); |
| 73 expect(e.shadowRoot, isNotNull, reason: 'shadowRoot is created'); |
| 74 document.body.append(e); |
| 75 await e.onRendered.first; |
| 76 expect(e.shadowRoot.children.length, isNonZero, |
| 77 reason: 'shadowRoot has elements'); |
| 78 e.remove(); |
| 79 await e.onRendered.first; |
| 80 expect(e.shadowRoot.children.length, isZero, reason: 'shadowRoot is empty'); |
| 81 }); |
| 82 group('content', () { |
| 83 CurlyBlockElement e; |
| 84 setUp(() async { |
| 85 e = new CurlyBlockElement(); |
| 86 document.body.append(e); |
| 87 await e.onRendered.first; |
| 88 }); |
| 89 tearDown(() { |
| 90 e.remove(); |
| 91 }); |
| 92 test('toggles visibility', () async { |
| 93 expect(e.shadowRoot.querySelector('content'), isNull); |
| 94 e.toggle(); |
| 95 await e.onRendered.first; |
| 96 expect(e.shadowRoot.querySelector('content'), isNotNull); |
| 97 e.toggle(); |
| 98 await e.onRendered.first; |
| 99 expect(e.shadowRoot.querySelector('content'), isNull); |
| 100 e.remove(); |
| 101 }); |
| 102 test('toggles visibility (manually)', () async { |
| 103 expect(e.shadowRoot.querySelector('content'), isNull); |
| 104 e.expanded = true; |
| 105 await e.onRendered.first; |
| 106 expect(e.shadowRoot.querySelector('content'), isNotNull); |
| 107 e.expanded = false; |
| 108 await e.onRendered.first; |
| 109 expect(e.shadowRoot.querySelector('content'), isNull); |
| 110 e.remove(); |
| 111 }); |
| 112 test('does not toggle if disabled', () async { |
| 113 e.disabled = true; |
| 114 await e.onRendered.first; |
| 115 expect(e.expanded, isFalse); |
| 116 expect(e.shadowRoot.querySelector('content'), isNull); |
| 117 e.toggle(); |
| 118 await e.onRendered.first; |
| 119 expect(e.expanded, isFalse); |
| 120 expect(e.shadowRoot.querySelector('content'), isNull); |
| 121 e.disabled = false; |
| 122 e.toggle(); |
| 123 await e.onRendered.first; |
| 124 expect(e.expanded, isTrue); |
| 125 expect(e.shadowRoot.querySelector('content'), isNotNull); |
| 126 e.disabled = true; |
| 127 e.toggle(); |
| 128 await e.onRendered.first; |
| 129 expect(e.expanded, isTrue); |
| 130 expect(e.shadowRoot.querySelector('content'), isNotNull); |
| 131 e.remove(); |
| 132 }); |
| 133 test('toggles visibility (manually) if disabled', () async { |
| 134 e.disabled = true; |
| 135 await e.onRendered.first; |
| 136 expect(e.shadowRoot.querySelector('content'), isNull); |
| 137 e.expanded = true; |
| 138 await e.onRendered.first; |
| 139 expect(e.shadowRoot.querySelector('content'), isNotNull); |
| 140 e.expanded = false; |
| 141 await e.onRendered.first; |
| 142 expect(e.shadowRoot.querySelector('content'), isNull); |
| 143 e.remove(); |
| 144 }); |
| 145 }); |
| 146 group('event', () { |
| 147 CurlyBlockElement e; |
| 148 setUp(() async { |
| 149 e = new CurlyBlockElement(); |
| 150 document.body.append(e); |
| 151 await e.onRendered.first; |
| 152 }); |
| 153 tearDown(() async { |
| 154 e.remove(); |
| 155 await e.onRendered.first; |
| 156 }); |
| 157 test('fires on toggle', () async { |
| 158 e.onToggle.listen(expectAsync((CurlyBlockToggleEvent event){ |
| 159 expect(event, isNotNull); |
| 160 expect(event.control, equals(e)); |
| 161 }, count: 1)); |
| 162 e.toggle(); |
| 163 await e.onRendered.first; |
| 164 }); |
| 165 test('fires on manual toggle', () async { |
| 166 e.onToggle.listen(expectAsync((CurlyBlockToggleEvent event){ |
| 167 expect(event, isNotNull); |
| 168 expect(event.control, equals(e)); |
| 169 }, count: 1)); |
| 170 e.expanded = !e.expanded; |
| 171 await e.onRendered.first; |
| 172 }); |
| 173 test('does not fire if setting same expanded value', () async { |
| 174 e.onToggle.listen(expectAsync((_){}, count: 0)); |
| 175 e.expanded = e.expanded; |
| 176 await e.onRendered.first; |
| 177 }); |
| 178 }); |
| 179 } |
OLD | NEW |