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' hide Notification, NotificationEvent; |
| 5 import 'package:unittest/unittest.dart'; |
| 6 import 'package:observatory/mocks.dart'; |
| 7 import 'package:observatory/models.dart' as M; |
| 8 import 'package:observatory/src/elements/nav/notify.dart'; |
| 9 import 'package:observatory/src/elements/nav/notify_event.dart'; |
| 10 import 'package:observatory/src/elements/nav/notify_exception.dart'; |
| 11 |
| 12 main() { |
| 13 NavNotifyElement.tag.ensureRegistration(); |
| 14 |
| 15 final evTag = NavNotifyEventElement.tag.name; |
| 16 final exTag = NavNotifyExceptionElement.tag.name; |
| 17 |
| 18 const vm = const VMRefMock(); |
| 19 const isolate = const IsolateRefMock(id: 'i-id', name: 'i-name'); |
| 20 |
| 21 group('instantiation', () { |
| 22 test('default', () { |
| 23 final NavNotifyElement e = new NavNotifyElement( |
| 24 new NotificationRepositoryMock()); |
| 25 expect(e, isNotNull, reason: 'element correctly created'); |
| 26 expect(e.notifyOnPause, isTrue, reason: 'notifyOnPause is default'); |
| 27 }); |
| 28 test('notify on pause', () { |
| 29 final NavNotifyElement e = new NavNotifyElement( |
| 30 new NotificationRepositoryMock(), notifyOnPause: true); |
| 31 expect(e, isNotNull, reason: 'element correctly created'); |
| 32 expect(e.notifyOnPause, isTrue, reason: 'notifyOnPause is the same'); |
| 33 }); |
| 34 test('do not notify on pause', () { |
| 35 final NavNotifyElement e = new NavNotifyElement( |
| 36 new NotificationRepositoryMock(), notifyOnPause: false); |
| 37 expect(e, isNotNull, reason: 'element correctly created'); |
| 38 expect(e.notifyOnPause, isFalse, reason: 'notifyOnPause is the same'); |
| 39 }); |
| 40 }); |
| 41 test('is correctly listening', () async { |
| 42 final NotificationRepositoryMock repository = |
| 43 new NotificationRepositoryMock(); |
| 44 final NavNotifyElement e = new NavNotifyElement(repository); |
| 45 document.body.append(e); |
| 46 await e.onRendered.first; |
| 47 expect(repository.hasListeners, isTrue, reason: 'is listening'); |
| 48 e.remove(); |
| 49 await e.onRendered.first; |
| 50 expect(repository.hasListeners, isFalse, reason: 'is no more listening'); |
| 51 }); |
| 52 group('elements', () { |
| 53 test('created after attachment', () async { |
| 54 final NotificationRepositoryMock repository = |
| 55 new NotificationRepositoryMock(list: [ |
| 56 new ExceptionNotificationMock(exception: new Exception("ex")), |
| 57 const EventNotificationMock(event: const VMUpdateEventMock(vm: vm)), |
| 58 const EventNotificationMock(event: const VMUpdateEventMock(vm: vm)) |
| 59 ]); |
| 60 final NavNotifyElement e = new NavNotifyElement(repository); |
| 61 document.body.append(e); |
| 62 await e.onRendered.first; |
| 63 expect(repository.listInvoked, isTrue, reason: 'should invoke list()'); |
| 64 expect(e.children.length, isNonZero, reason: 'has elements'); |
| 65 expect(e.querySelectorAll(evTag).length, equals(2)); |
| 66 expect(e.querySelectorAll(exTag).length, equals(1)); |
| 67 e.remove(); |
| 68 await e.onRendered.first; |
| 69 expect(e.children.length, isZero, reason: 'is empty'); |
| 70 }); |
| 71 test('react to notifyOnPause change', () async { |
| 72 final NotificationRepositoryMock repository = |
| 73 new NotificationRepositoryMock(list: [ |
| 74 new ExceptionNotificationMock(exception: new Exception("ex")), |
| 75 const EventNotificationMock(event: const VMUpdateEventMock()), |
| 76 const EventNotificationMock( |
| 77 event: const PauseStartEventMock(isolate: isolate)) |
| 78 ]); |
| 79 final NavNotifyElement e = new NavNotifyElement(repository, |
| 80 notifyOnPause: true); |
| 81 document.body.append(e); |
| 82 await e.onRendered.first; |
| 83 expect(e.querySelectorAll(evTag).length, equals(2)); |
| 84 expect(e.querySelectorAll(exTag).length, equals(1)); |
| 85 e.notifyOnPause = false; |
| 86 await e.onRendered.first; |
| 87 expect(e.querySelectorAll(evTag).length, equals(1)); |
| 88 expect(e.querySelectorAll(exTag).length, equals(1)); |
| 89 e.notifyOnPause = true; |
| 90 await e.onRendered.first; |
| 91 expect(e.querySelectorAll(evTag).length, equals(2)); |
| 92 expect(e.querySelectorAll(exTag).length, equals(1)); |
| 93 e.remove(); |
| 94 await e.onRendered.first; |
| 95 expect(e.children.length, isZero, reason: 'is empty'); |
| 96 }); |
| 97 test('react to update event', () async { |
| 98 final List<M.Notification> list = [ |
| 99 new ExceptionNotificationMock(exception: new Exception("ex")), |
| 100 const EventNotificationMock(event: const VMUpdateEventMock()), |
| 101 ]; |
| 102 final NotificationRepositoryMock repository = |
| 103 new NotificationRepositoryMock(list: list); |
| 104 final NavNotifyElement e = new NavNotifyElement(repository, |
| 105 notifyOnPause: true); |
| 106 document.body.append(e); |
| 107 await e.onRendered.first; |
| 108 expect(e.querySelectorAll(evTag).length, equals(1)); |
| 109 expect(e.querySelectorAll(exTag).length, equals(1)); |
| 110 list.add(const EventNotificationMock( |
| 111 event: const PauseStartEventMock(isolate: isolate))); |
| 112 repository.triggerChangeEvent(); |
| 113 await e.onRendered.first; |
| 114 expect(e.querySelectorAll(evTag).length, equals(2)); |
| 115 expect(e.querySelectorAll(exTag).length, equals(1)); |
| 116 e.remove(); |
| 117 await e.onRendered.first; |
| 118 expect(e.children.length, isZero, reason: 'is empty'); |
| 119 }); |
| 120 }); |
| 121 } |
OLD | NEW |