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