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