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/isolate_reconnect.dart'; | 7 import 'package:observatory/src/elements/isolate_reconnect.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 IsolateReconnectElement.tag.ensureRegistration(); | 12 IsolateReconnectElement.tag.ensureRegistration(); |
13 | 13 |
14 final nTag = NavNotifyElement.tag.name; | 14 final nTag = NavNotifyElement.tag.name; |
15 | 15 |
16 EventRepositoryMock events; | 16 EventRepositoryMock events; |
17 NotificationRepositoryMock notifications; | 17 NotificationRepositoryMock notifications; |
18 Uri uri; | 18 Uri uri; |
19 const vm = const VMMock(isolates: const [ | 19 const vm = const VMMock(isolates: const [ |
20 const IsolateMock(id: 'i-1-id'), const IsolateMock(id: 'i-2-id') | 20 const IsolateMock(id: 'i-1-id'), |
| 21 const IsolateMock(id: 'i-2-id') |
21 ]); | 22 ]); |
22 const missing = 'missing-id'; | 23 const missing = 'missing-id'; |
23 setUp(() { | 24 setUp(() { |
24 events = new EventRepositoryMock(); | 25 events = new EventRepositoryMock(); |
25 notifications = new NotificationRepositoryMock(); | 26 notifications = new NotificationRepositoryMock(); |
26 uri = new Uri(path: 'path'); | 27 uri = new Uri(path: 'path'); |
27 }); | 28 }); |
28 test('instantiation', () { | 29 test('instantiation', () { |
29 final e = new IsolateReconnectElement(vm, events, notifications, missing, | 30 final e = |
30 uri); | 31 new IsolateReconnectElement(vm, events, notifications, missing, uri); |
31 expect(e, isNotNull, reason: 'element correctly created'); | 32 expect(e, isNotNull, reason: 'element correctly created'); |
32 expect(e.vm, equals(vm)); | 33 expect(e.vm, equals(vm)); |
33 expect(e.missing, equals(missing)); | 34 expect(e.missing, equals(missing)); |
34 expect(e.uri, equals(uri)); | 35 expect(e.uri, equals(uri)); |
35 }); | 36 }); |
36 test('elements created after attachment', () async { | 37 test('elements created after attachment', () async { |
37 final e = new IsolateReconnectElement(vm, events, notifications, missing, | 38 final e = |
38 uri); | 39 new IsolateReconnectElement(vm, events, notifications, missing, uri); |
39 document.body.append(e); | 40 document.body.append(e); |
40 await e.onRendered.first; | 41 await e.onRendered.first; |
41 expect(e.children.length, isNonZero, reason: 'has elements'); | 42 expect(e.children.length, isNonZero, reason: 'has elements'); |
42 expect(e.querySelector(nTag), isNotNull, reason: 'has notifications'); | 43 expect(e.querySelector(nTag), isNotNull, reason: 'has notifications'); |
43 expect(e.querySelectorAll('.isolate-link').length, | 44 expect( |
44 equals(vm.isolates.length), reason: 'has links'); | 45 e.querySelectorAll('.isolate-link').length, equals(vm.isolates.length), |
| 46 reason: 'has links'); |
45 e.remove(); | 47 e.remove(); |
46 await e.onRendered.first; | 48 await e.onRendered.first; |
47 expect(e.children.length, isZero, reason: 'is empty'); | 49 expect(e.children.length, isZero, reason: 'is empty'); |
48 }); | 50 }); |
49 group('updates', () { | 51 group('updates', () { |
50 test('are correctly listen', () async { | 52 test('are correctly listen', () async { |
51 final e = new IsolateReconnectElement(vm, events, notifications, missing, | 53 final e = |
52 uri); | 54 new IsolateReconnectElement(vm, events, notifications, missing, uri); |
53 expect(events.onVMUpdateHasListener, isFalse); | 55 expect(events.onVMUpdateHasListener, isFalse); |
54 document.body.append(e); | 56 document.body.append(e); |
55 await e.onRendered.first; | 57 await e.onRendered.first; |
56 expect(events.onVMUpdateHasListener, isTrue); | 58 expect(events.onVMUpdateHasListener, isTrue); |
57 e.remove(); | 59 e.remove(); |
58 await e.onRendered.first; | 60 await e.onRendered.first; |
59 expect(events.onVMUpdateHasListener, isFalse); | 61 expect(events.onVMUpdateHasListener, isFalse); |
60 }); | 62 }); |
61 test('have effects', () async { | 63 test('have effects', () async { |
62 final e = new IsolateReconnectElement(vm, events, notifications, missing, | 64 final e = |
63 uri); | 65 new IsolateReconnectElement(vm, events, notifications, missing, uri); |
64 const vm2 = const VMMock(isolates: const [ | 66 const vm2 = const VMMock(isolates: const [ |
65 const IsolateMock(id: 'i-1-id'), const IsolateMock(id: 'i-2-id'), | 67 const IsolateMock(id: 'i-1-id'), |
66 const IsolateMock(id: 'i-3-id') | 68 const IsolateMock(id: 'i-2-id'), |
| 69 const IsolateMock(id: 'i-3-id') |
67 ]); | 70 ]); |
68 document.body.append(e); | 71 document.body.append(e); |
69 await e.onRendered.first; | 72 await e.onRendered.first; |
70 expect(e.querySelectorAll('.isolate-link').length, | 73 expect(e.querySelectorAll('.isolate-link').length, |
71 equals(vm.isolates.length)); | 74 equals(vm.isolates.length)); |
72 events.add(new VMUpdateEventMock(vm: vm2)); | 75 events.add(new VMUpdateEventMock(vm: vm2)); |
73 await e.onRendered.first; | 76 await e.onRendered.first; |
74 expect(e.querySelectorAll('.isolate-link').length, | 77 expect(e.querySelectorAll('.isolate-link').length, |
75 equals(vm2.isolates.length)); | 78 equals(vm2.isolates.length)); |
76 e.remove(); | 79 e.remove(); |
77 await e.onRendered.first; | 80 await e.onRendered.first; |
78 }); | 81 }); |
79 }); | 82 }); |
80 } | 83 } |
OLD | NEW |