| 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/curly_block.dart'; | 7 import 'package:observatory/src/elements/curly_block.dart'; |
| 8 import 'package:observatory/src/elements/inbound_references.dart'; | 8 import 'package:observatory/src/elements/inbound_references.dart'; |
| 9 import 'package:observatory/src/elements/instance_ref.dart'; | 9 import 'package:observatory/src/elements/instance_ref.dart'; |
| 10 import '../mocks.dart'; | 10 import '../mocks.dart'; |
| 11 | 11 |
| 12 main() { | 12 main() { |
| 13 InboundReferencesElement.tag.ensureRegistration(); | 13 InboundReferencesElement.tag.ensureRegistration(); |
| 14 | 14 |
| 15 final cTag = CurlyBlockElement.tag.name; | 15 final cTag = CurlyBlockElement.tag.name; |
| 16 final iTag = InstanceRefElement.tag.name; | 16 final iTag = InstanceRefElement.tag.name; |
| 17 final rTag = InboundReferencesElement.tag.name; | 17 final rTag = InboundReferencesElement.tag.name; |
| 18 | 18 |
| 19 const isolate = const IsolateRefMock(); | 19 const isolate = const IsolateRefMock(); |
| 20 const object = const InstanceRefMock(); | 20 const object = const InstanceRefMock(); |
| 21 final inbounds = new InboundReferencesRepositoryMock(); | 21 final inbounds = new InboundReferencesRepositoryMock(); |
| 22 final instances = new InstanceRepositoryMock(); | 22 final instances = new InstanceRepositoryMock(); |
| 23 test('instantiation', () { | 23 test('instantiation', () { |
| 24 final e = new InboundReferencesElement(isolate, object, inbounds, | 24 final e = |
| 25 instances); | 25 new InboundReferencesElement(isolate, object, inbounds, instances); |
| 26 expect(e, isNotNull, reason: 'element correctly created'); | 26 expect(e, isNotNull, reason: 'element correctly created'); |
| 27 expect(e.isolate, equals(isolate)); | 27 expect(e.isolate, equals(isolate)); |
| 28 expect(e.object, equals(object)); | 28 expect(e.object, equals(object)); |
| 29 }); | 29 }); |
| 30 test('elements created after attachment', () async { | 30 test('elements created after attachment', () async { |
| 31 const source = const InstanceRefMock(id: 'source-id', name: 'source_name'); | 31 const source = const InstanceRefMock(id: 'source-id', name: 'source_name'); |
| 32 const references = const InboundReferencesMock(elements: const [ | 32 const references = const InboundReferencesMock( |
| 33 const InboundReferenceMock(source: source) | 33 elements: const [const InboundReferenceMock(source: source)]); |
| 34 ]); | |
| 35 bool invoked = false; | 34 bool invoked = false; |
| 36 final inbounds = new InboundReferencesRepositoryMock( | 35 final inbounds = new InboundReferencesRepositoryMock( |
| 37 getter: expectAsync((i, id) async { | 36 getter: expectAsync((i, id) async { |
| 38 expect(i, equals(isolate)); | 37 expect(i, equals(isolate)); |
| 39 expect(id, equals(object.id)); | 38 expect(id, equals(object.id)); |
| 40 invoked = true; | 39 invoked = true; |
| 41 return references; | 40 return references; |
| 42 }, count: 1) | 41 }, count: 1)); |
| 43 ); | |
| 44 final instances = new InstanceRepositoryMock(); | 42 final instances = new InstanceRepositoryMock(); |
| 45 final e = new InboundReferencesElement(isolate, object, inbounds, | 43 final e = |
| 46 instances); | 44 new InboundReferencesElement(isolate, object, inbounds, instances); |
| 47 document.body.append(e); | 45 document.body.append(e); |
| 48 await e.onRendered.first; | 46 await e.onRendered.first; |
| 49 expect(invoked, isFalse); | 47 expect(invoked, isFalse); |
| 50 expect(e.children.length, isNonZero, reason: 'has elements'); | 48 expect(e.children.length, isNonZero, reason: 'has elements'); |
| 51 expect(e.querySelectorAll(iTag).length, isZero); | 49 expect(e.querySelectorAll(iTag).length, isZero); |
| 52 (e.querySelector(cTag) as CurlyBlockElement).toggle(); | 50 (e.querySelector(cTag) as CurlyBlockElement).toggle(); |
| 53 await e.onRendered.first; | 51 await e.onRendered.first; |
| 54 expect(invoked, isTrue); | 52 expect(invoked, isTrue); |
| 55 expect(e.querySelectorAll(iTag).length, equals(1)); | 53 expect(e.querySelectorAll(iTag).length, equals(1)); |
| 56 expect(e.querySelectorAll(rTag).length, equals(1)); | 54 expect(e.querySelectorAll(rTag).length, equals(1)); |
| 57 e.remove(); | 55 e.remove(); |
| 58 await e.onRendered.first; | 56 await e.onRendered.first; |
| 59 expect(e.children.length, isZero, reason: 'is empty'); | 57 expect(e.children.length, isZero, reason: 'is empty'); |
| 60 }); | 58 }); |
| 61 } | 59 } |
| OLD | NEW |