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'; |
| 5 import 'dart:async'; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:observatory/models.dart'; |
| 8 import 'package:observatory/mocks.dart'; |
| 9 import 'package:observatory/src/elements/nav/menu.dart'; |
| 10 import 'package:observatory/src/elements/nav/isolate_menu.dart'; |
| 11 |
| 12 main(){ |
| 13 NavIsolateMenuElement.tag.ensureRegistration(); |
| 14 |
| 15 final String tag = NavMenuElement.tag.name; |
| 16 |
| 17 StreamController<IsolateUpdateEvent> updatesController; |
| 18 final IsolateRefMock ref = const IsolateRefMock(id: 'i-id', name: 'old-name'); |
| 19 final IsolateMock obj = const IsolateMock(id: 'i-id', name: 'new-name'); |
| 20 setUp(() { |
| 21 updatesController = new StreamController<IsolateUpdateEvent>(); |
| 22 }); |
| 23 group('instantiation', () { |
| 24 test('IsolateRef', () { |
| 25 final NavIsolateMenuElement e = new NavIsolateMenuElement(ref, |
| 26 updatesController.stream); |
| 27 expect(e, isNotNull, reason: 'element correctly created'); |
| 28 expect(e.isolate, equals(ref)); |
| 29 }); |
| 30 test('Isolate', () { |
| 31 final NavIsolateMenuElement e = new NavIsolateMenuElement(obj, |
| 32 updatesController.stream); |
| 33 expect(e, isNotNull, reason: 'element correctly created'); |
| 34 expect(e.isolate, equals(obj)); |
| 35 }); |
| 36 }); |
| 37 test('elements created after attachment', () async { |
| 38 final NavIsolateMenuElement e = new NavIsolateMenuElement(ref, |
| 39 updatesController.stream); |
| 40 document.body.append(e); |
| 41 await e.onRendered.first; |
| 42 expect(e.shadowRoot.children.length, isNonZero, reason: 'has elements'); |
| 43 e.remove(); |
| 44 await e.onRendered.first; |
| 45 expect(e.shadowRoot.children.length, isZero, reason: 'is empty'); |
| 46 }); |
| 47 group('updates', () { |
| 48 test('are correctly listen', () async { |
| 49 final NavIsolateMenuElement e = new NavIsolateMenuElement(ref, |
| 50 updatesController.stream); |
| 51 expect(updatesController.hasListener, isFalse); |
| 52 document.body.append(e); |
| 53 await e.onRendered.first; |
| 54 expect(updatesController.hasListener, isTrue); |
| 55 e.remove(); |
| 56 await e.onRendered.first; |
| 57 expect(updatesController.hasListener, isFalse); |
| 58 }); |
| 59 test('have effects', () async { |
| 60 final NavIsolateMenuElement e = new NavIsolateMenuElement(ref, |
| 61 updatesController.stream); |
| 62 document.body.append(e); |
| 63 await e.onRendered.first; |
| 64 expect((e.shadowRoot.querySelector(tag) as NavMenuElement) |
| 65 .label.contains(ref.name), isTrue); |
| 66 updatesController.add(new IsolateUpdateEventMock(isolate: obj)); |
| 67 await e.onRendered.first; |
| 68 expect((e.shadowRoot.querySelector(tag) as NavMenuElement) |
| 69 .label.contains(ref.name), isFalse); |
| 70 expect((e.shadowRoot.querySelector(tag) as NavMenuElement) |
| 71 .label.contains(obj.name), isTrue); |
| 72 e.remove(); |
| 73 }); |
| 74 }); |
| 75 } |
OLD | NEW |