OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 import 'dart:html'; | 4 import 'dart:html'; |
5 import 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
6 import 'package:observatory/src/elements/curly_block.dart'; | 6 import 'package:observatory/src/elements/curly_block.dart'; |
7 import 'package:observatory/src/elements/helpers/rendering_queue.dart'; | |
8 | 7 |
9 main() { | 8 main() { |
10 CurlyBlockElement.tag.ensureRegistration(); | 9 CurlyBlockElement.tag.ensureRegistration(); |
11 | 10 |
12 final TimedRenderingBarrier barrier = new TimedRenderingBarrier(); | |
13 final RenderingQueue queue = new RenderingQueue.fromBarrier(barrier); | |
14 group('instantiation', () { | 11 group('instantiation', () { |
15 test('default', () { | 12 test('default', () { |
16 final CurlyBlockElement e = new CurlyBlockElement(); | 13 final CurlyBlockElement e = new CurlyBlockElement(); |
17 expect(e, isNotNull, reason: 'element correctly created'); | 14 expect(e, isNotNull, reason: 'element correctly created'); |
18 expect(e.expanded, isFalse); | 15 expect(e.expanded, isFalse); |
19 expect(e.disabled, isFalse); | 16 expect(e.disabled, isFalse); |
20 }); | 17 }); |
21 test('not expanded', () { | 18 test('not expanded', () { |
22 final CurlyBlockElement e = new CurlyBlockElement(expanded: false); | 19 final CurlyBlockElement e = new CurlyBlockElement(expanded: false); |
23 expect(e, isNotNull, reason: 'element correctly created'); | 20 expect(e, isNotNull, reason: 'element correctly created'); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 expect(e.disabled, isFalse); | 62 expect(e.disabled, isFalse); |
66 }); | 63 }); |
67 test('disabled', () { | 64 test('disabled', () { |
68 final CurlyBlockElement e = new CurlyBlockElement(disabled: true); | 65 final CurlyBlockElement e = new CurlyBlockElement(disabled: true); |
69 expect(e, isNotNull, reason: 'element correctly created'); | 66 expect(e, isNotNull, reason: 'element correctly created'); |
70 expect(e.expanded, isFalse); | 67 expect(e.expanded, isFalse); |
71 expect(e.disabled, isTrue); | 68 expect(e.disabled, isTrue); |
72 }); | 69 }); |
73 }); | 70 }); |
74 test('elements created', () async { | 71 test('elements created', () async { |
75 final CurlyBlockElement e = new CurlyBlockElement(queue: queue); | 72 final CurlyBlockElement e = new CurlyBlockElement(); |
76 expect(e.shadowRoot, isNotNull, reason: 'shadowRoot is created'); | 73 expect(e.shadowRoot, isNotNull, reason: 'shadowRoot is created'); |
77 document.body.append(e); | 74 document.body.append(e); |
78 await e.onRendered.first; | 75 await e.onRendered.first; |
79 expect(e.shadowRoot.children.length, isNonZero, | 76 expect(e.shadowRoot.children.length, isNonZero, |
80 reason: 'shadowRoot has elements'); | 77 reason: 'shadowRoot has elements'); |
81 e.remove(); | 78 e.remove(); |
82 await e.onRendered.first; | 79 await e.onRendered.first; |
83 expect(e.shadowRoot.children.length, isZero, reason: 'shadowRoot is empty'); | 80 expect(e.shadowRoot.children.length, isZero, reason: 'shadowRoot is empty'); |
84 }); | 81 }); |
85 group('content', () { | 82 group('content', () { |
86 CurlyBlockElement e; | 83 CurlyBlockElement e; |
87 setUp(() async { | 84 setUp(() async { |
88 e = new CurlyBlockElement(queue: queue); | 85 e = new CurlyBlockElement(); |
89 document.body.append(e); | 86 document.body.append(e); |
90 await e.onRendered.first; | 87 await e.onRendered.first; |
91 }); | 88 }); |
92 tearDown(() async { | 89 tearDown(() { |
93 e.remove(); | 90 e.remove(); |
94 await e.onRendered.first; | |
95 }); | 91 }); |
96 test('toggles visibility', () async { | 92 test('toggles visibility', () async { |
97 expect(e.shadowRoot.querySelector('content'), isNull); | 93 expect(e.shadowRoot.querySelector('content'), isNull); |
98 e.toggle(); | 94 e.toggle(); |
99 await e.onRendered.first; | 95 await e.onRendered.first; |
100 expect(e.shadowRoot.querySelector('content'), isNotNull); | 96 expect(e.shadowRoot.querySelector('content'), isNotNull); |
101 e.toggle(); | 97 e.toggle(); |
102 await e.onRendered.first; | 98 await e.onRendered.first; |
103 expect(e.shadowRoot.querySelector('content'), isNull); | 99 expect(e.shadowRoot.querySelector('content'), isNull); |
| 100 e.remove(); |
104 }); | 101 }); |
105 test('toggles visibility (manually)', () async { | 102 test('toggles visibility (manually)', () async { |
106 expect(e.shadowRoot.querySelector('content'), isNull); | 103 expect(e.shadowRoot.querySelector('content'), isNull); |
107 e.expanded = true; | 104 e.expanded = true; |
108 await e.onRendered.first; | 105 await e.onRendered.first; |
109 expect(e.shadowRoot.querySelector('content'), isNotNull); | 106 expect(e.shadowRoot.querySelector('content'), isNotNull); |
110 e.expanded = false; | 107 e.expanded = false; |
111 await e.onRendered.first; | 108 await e.onRendered.first; |
112 expect(e.shadowRoot.querySelector('content'), isNull); | 109 expect(e.shadowRoot.querySelector('content'), isNull); |
| 110 e.remove(); |
113 }); | 111 }); |
114 test('does not toggle if disabled', () async { | 112 test('does not toggle if disabled', () async { |
115 e.disabled = true; | 113 e.disabled = true; |
116 await e.onRendered.first; | 114 await e.onRendered.first; |
117 expect(e.expanded, isFalse); | 115 expect(e.expanded, isFalse); |
118 expect(e.shadowRoot.querySelector('content'), isNull); | 116 expect(e.shadowRoot.querySelector('content'), isNull); |
119 e.toggle(); | 117 e.toggle(); |
120 await e.onRendered.first; | 118 await e.onRendered.first; |
121 expect(e.expanded, isFalse); | 119 expect(e.expanded, isFalse); |
122 expect(e.shadowRoot.querySelector('content'), isNull); | 120 expect(e.shadowRoot.querySelector('content'), isNull); |
123 e.disabled = false; | 121 e.disabled = false; |
124 e.toggle(); | 122 e.toggle(); |
125 await e.onRendered.first; | 123 await e.onRendered.first; |
126 expect(e.expanded, isTrue); | 124 expect(e.expanded, isTrue); |
127 expect(e.shadowRoot.querySelector('content'), isNotNull); | 125 expect(e.shadowRoot.querySelector('content'), isNotNull); |
128 e.disabled = true; | 126 e.disabled = true; |
129 e.toggle(); | 127 e.toggle(); |
130 await e.onRendered.first; | 128 await e.onRendered.first; |
131 expect(e.expanded, isTrue); | 129 expect(e.expanded, isTrue); |
132 expect(e.shadowRoot.querySelector('content'), isNotNull); | 130 expect(e.shadowRoot.querySelector('content'), isNotNull); |
| 131 e.remove(); |
133 }); | 132 }); |
134 test('toggles visibility (manually) if disabled', () async { | 133 test('toggles visibility (manually) if disabled', () async { |
135 e.disabled = true; | 134 e.disabled = true; |
136 await e.onRendered.first; | 135 await e.onRendered.first; |
137 expect(e.shadowRoot.querySelector('content'), isNull); | 136 expect(e.shadowRoot.querySelector('content'), isNull); |
138 e.expanded = true; | 137 e.expanded = true; |
139 await e.onRendered.first; | 138 await e.onRendered.first; |
140 expect(e.shadowRoot.querySelector('content'), isNotNull); | 139 expect(e.shadowRoot.querySelector('content'), isNotNull); |
141 e.expanded = false; | 140 e.expanded = false; |
142 await e.onRendered.first; | 141 await e.onRendered.first; |
143 expect(e.shadowRoot.querySelector('content'), isNull); | 142 expect(e.shadowRoot.querySelector('content'), isNull); |
| 143 e.remove(); |
144 }); | 144 }); |
145 }); | 145 }); |
146 group('event', () { | 146 group('event', () { |
147 CurlyBlockElement e; | 147 CurlyBlockElement e; |
148 setUp(() async { | 148 setUp(() async { |
149 e = new CurlyBlockElement(queue: queue); | 149 e = new CurlyBlockElement(); |
150 document.body.append(e); | 150 document.body.append(e); |
151 await e.onRendered.first; | 151 await e.onRendered.first; |
152 }); | 152 }); |
153 tearDown(() async { | 153 tearDown(() async { |
154 e.remove(); | 154 e.remove(); |
155 await e.onRendered.first; | 155 await e.onRendered.first; |
156 }); | 156 }); |
157 test('fires on toggle', () async { | 157 test('fires on toggle', () async { |
158 e.onToggle.listen(expectAsync((CurlyBlockToggleEvent event){ | 158 e.onToggle.listen(expectAsync((CurlyBlockToggleEvent event){ |
159 expect(event, isNotNull); | 159 expect(event, isNotNull); |
(...skipping 10 matching lines...) Expand all Loading... |
170 e.expanded = !e.expanded; | 170 e.expanded = !e.expanded; |
171 await e.onRendered.first; | 171 await e.onRendered.first; |
172 }); | 172 }); |
173 test('does not fire if setting same expanded value', () async { | 173 test('does not fire if setting same expanded value', () async { |
174 e.onToggle.listen(expectAsync((_){}, count: 0)); | 174 e.onToggle.listen(expectAsync((_){}, count: 0)); |
175 e.expanded = e.expanded; | 175 e.expanded = e.expanded; |
176 await e.onRendered.first; | 176 await e.onRendered.first; |
177 }); | 177 }); |
178 }); | 178 }); |
179 } | 179 } |
OLD | NEW |