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 | 4 |
5 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'package:observatory/src/elements/class_tree.dart'; | 7 import 'package:observatory/src/elements/class_tree.dart'; |
8 import 'package:observatory/src/elements/nav/notify.dart'; | 8 import 'package:observatory/src/elements/nav/notify.dart'; |
9 import '../mocks.dart'; | 9 import '../mocks.dart'; |
10 | 10 |
11 main() { | 11 main() { |
12 ClassTreeElement.tag.ensureRegistration(); | 12 ClassTreeElement.tag.ensureRegistration(); |
13 | 13 |
14 final nTag = NavNotifyElement.tag.name; | 14 final nTag = NavNotifyElement.tag.name; |
15 const vm = const VMMock(); | 15 const vm = const VMMock(); |
16 const isolate = const IsolateRefMock(); | 16 const isolate = const IsolateRefMock(); |
17 final events = new EventRepositoryMock(); | 17 final events = new EventRepositoryMock(); |
18 final notifications = new NotificationRepositoryMock(); | 18 final notifications = new NotificationRepositoryMock(); |
19 | 19 |
20 group('instantiation', () { | 20 group('instantiation', () { |
21 test('default', () { | 21 test('default', () { |
22 final e = new ClassTreeElement( | 22 final e = new ClassTreeElement(vm, isolate, events, notifications, |
23 vm, isolate, events, notifications, new ClassRepositoryMock()); | 23 new ClassRepositoryMock()); |
24 expect(e, isNotNull, reason: 'element correctly created'); | 24 expect(e, isNotNull, reason: 'element correctly created'); |
25 }); | 25 }); |
26 }); | 26 }); |
27 group('elements', () { | 27 group('elements', () { |
28 test('created after attachment', () async { | 28 test('created after attachment', () async { |
29 const child2_id = 'c2-id'; | 29 const child2_id = 'c2-id'; |
30 const child1_1_id = 'c1_1-id'; | 30 const child1_1_id = 'c1_1-id'; |
31 const child1_id = 'c1-id'; | 31 const child1_id = 'c1-id'; |
32 const child2 = const ClassMock(id: child2_id); | 32 const child2 = const ClassMock(id: child2_id); |
33 const child1_1 = const ClassMock(id: child1_1_id); | 33 const child1_1 = const ClassMock(id: child1_1_id); |
34 const child1 = | 34 const child1 = const ClassMock(id: child1_id, |
35 const ClassMock(id: child1_id, subclasses: const [child1_1]); | 35 subclasses: const [child1_1]); |
36 const object = | 36 const object = const ClassMock(id: 'o-id', |
37 const ClassMock(id: 'o-id', subclasses: const [child1, child2]); | 37 subclasses: const [child1, child2]); |
38 const ids = const [child1_id, child1_1_id, child2_id]; | 38 const ids = const [child1_id, child1_1_id, child2_id]; |
39 bool rendered = false; | 39 bool rendered = false; |
40 final e = new ClassTreeElement( | 40 final e = new ClassTreeElement(vm, isolate, events, notifications, |
41 vm, | |
42 isolate, | |
43 events, | |
44 notifications, | |
45 new ClassRepositoryMock( | 41 new ClassRepositoryMock( |
46 object: expectAsync((i) async { | 42 object: expectAsync((i) async { |
47 expect(i, equals(isolate)); | 43 expect(i, equals(isolate)); |
48 expect(rendered, isFalse); | 44 expect(rendered, isFalse); |
49 return object; | 45 return object; |
50 }, count: 1), | 46 }, count: 1), |
51 getter: expectAsync((i, id) async { | 47 getter: expectAsync((i, id) async { |
52 expect(i, equals(isolate)); | 48 expect(i, equals(isolate)); |
53 expect(ids.contains(id), isTrue); | 49 expect(ids.contains(id), isTrue); |
54 switch (id) { | 50 switch (id) { |
55 case child1_id: | 51 case child1_id: return child1; |
56 return child1; | 52 case child1_1_id: return child1_1; |
57 case child1_1_id: | 53 case child2_id: return child2; |
58 return child1_1; | 54 default: return null; |
59 case child2_id: | |
60 return child2; | |
61 default: | |
62 return null; | |
63 } | 55 } |
64 }, count: 3))); | 56 }, count: 3))); |
65 document.body.append(e); | 57 document.body.append(e); |
66 await e.onRendered.first; | 58 await e.onRendered.first; |
67 rendered = true; | 59 rendered = true; |
68 expect(e.children.length, isNonZero, reason: 'has elements'); | 60 expect(e.children.length, isNonZero, reason: 'has elements'); |
69 expect(e.querySelectorAll(nTag).length, equals(1)); | 61 expect(e.querySelectorAll(nTag).length, equals(1)); |
70 e.remove(); | 62 e.remove(); |
71 await e.onRendered.first; | 63 await e.onRendered.first; |
72 expect(e.children.length, isZero, reason: 'is empty'); | 64 expect(e.children.length, isZero, reason: 'is empty'); |
73 }); | 65 }); |
74 }); | 66 }); |
75 } | 67 } |
OLD | NEW |