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/nav/notify.dart'; | 7 import 'package:observatory/src/elements/nav/notify.dart'; |
8 import 'package:observatory/src/elements/vm_connect_target.dart'; | 8 import 'package:observatory/src/elements/vm_connect_target.dart'; |
9 import 'package:observatory/src/elements/vm_connect.dart'; | 9 import 'package:observatory/src/elements/vm_connect.dart'; |
10 import '../mocks.dart'; | 10 import '../mocks.dart'; |
11 | 11 |
12 void load(_) {} | 12 void load(_) {} |
13 | 13 |
14 main() { | 14 main() { |
15 VMConnectElement.tag.ensureRegistration(); | 15 VMConnectElement.tag.ensureRegistration(); |
16 | 16 |
17 final nTag = NavNotifyElement.tag.name; | 17 final nTag = NavNotifyElement.tag.name; |
18 final tTag = VMConnectTargetElement.tag.name; | 18 final tTag = VMConnectTargetElement.tag.name; |
19 | 19 |
20 group('instantiation', () { | 20 group('instantiation', () { |
21 test('default', () { | 21 test('default', () { |
22 final e = new VMConnectElement(new TargetRepositoryMock(), | 22 final e = new VMConnectElement( |
23 load, new NotificationRepositoryMock()); | 23 new TargetRepositoryMock(), load, new NotificationRepositoryMock()); |
24 expect(e, isNotNull, reason: 'element correctly created'); | 24 expect(e, isNotNull, reason: 'element correctly created'); |
25 }); | 25 }); |
26 }); | 26 }); |
27 test('is correctly listening', () async { | 27 test('is correctly listening', () async { |
28 final targets = new TargetRepositoryMock(); | 28 final targets = new TargetRepositoryMock(); |
29 final e = new VMConnectElement(targets, load, | 29 final e = |
30 new NotificationRepositoryMock()); | 30 new VMConnectElement(targets, load, new NotificationRepositoryMock()); |
31 document.body.append(e); | 31 document.body.append(e); |
32 await e.onRendered.first; | 32 await e.onRendered.first; |
33 expect(targets.hasListeners, isTrue, reason: 'is listening'); | 33 expect(targets.hasListeners, isTrue, reason: 'is listening'); |
34 e.remove(); | 34 e.remove(); |
35 await e.onRendered.first; | 35 await e.onRendered.first; |
36 expect(targets.hasListeners, isFalse, reason: 'is no more listening'); | 36 expect(targets.hasListeners, isFalse, reason: 'is no more listening'); |
37 }); | 37 }); |
38 group('elements', () { | 38 group('elements', () { |
39 test('created after attachment', () async { | 39 test('created after attachment', () async { |
40 final targets = new TargetRepositoryMock(list: const [ | 40 final targets = new TargetRepositoryMock(list: const [ |
41 const TargetMock(name: 't-1'), const TargetMock(name: 't-2'), | 41 const TargetMock(name: 't-1'), |
42 ]); | 42 const TargetMock(name: 't-2'), |
43 final e = new VMConnectElement(targets, load, | 43 ]); |
44 new NotificationRepositoryMock()); | 44 final e = |
| 45 new VMConnectElement(targets, load, new NotificationRepositoryMock()); |
45 document.body.append(e); | 46 document.body.append(e); |
46 await e.onRendered.first; | 47 await e.onRendered.first; |
47 expect(targets.listInvoked, isTrue, reason: 'should invoke list()'); | 48 expect(targets.listInvoked, isTrue, reason: 'should invoke list()'); |
48 expect(e.children.length, isNonZero, reason: 'has elements'); | 49 expect(e.children.length, isNonZero, reason: 'has elements'); |
49 expect(e.querySelectorAll(nTag).length, equals(1)); | 50 expect(e.querySelectorAll(nTag).length, equals(1)); |
50 expect(e.querySelectorAll(tTag).length, equals(2)); | 51 expect(e.querySelectorAll(tTag).length, equals(2)); |
51 e.remove(); | 52 e.remove(); |
52 await e.onRendered.first; | 53 await e.onRendered.first; |
53 expect(e.children.length, isZero, reason: 'is empty'); | 54 expect(e.children.length, isZero, reason: 'is empty'); |
54 }); | 55 }); |
55 test('react to update event', () async { | 56 test('react to update event', () async { |
56 final list = <TargetMock>[const TargetMock(name: 't-1')]; | 57 final list = <TargetMock>[const TargetMock(name: 't-1')]; |
57 final targets = new TargetRepositoryMock(list: list); | 58 final targets = new TargetRepositoryMock(list: list); |
58 final e = new VMConnectElement(targets, load, | 59 final e = |
59 new NotificationRepositoryMock()); | 60 new VMConnectElement(targets, load, new NotificationRepositoryMock()); |
60 document.body.append(e); | 61 document.body.append(e); |
61 await e.onRendered.first; | 62 await e.onRendered.first; |
62 expect(e.querySelectorAll(tTag).length, equals(1)); | 63 expect(e.querySelectorAll(tTag).length, equals(1)); |
63 list.add(const TargetMock(name: 't-2')); | 64 list.add(const TargetMock(name: 't-2')); |
64 targets.triggerChangeEvent(); | 65 targets.triggerChangeEvent(); |
65 await e.onRendered.first; | 66 await e.onRendered.first; |
66 expect(e.querySelectorAll(tTag).length, equals(2)); | 67 expect(e.querySelectorAll(tTag).length, equals(2)); |
67 e.remove(); | 68 e.remove(); |
68 await e.onRendered.first; | 69 await e.onRendered.first; |
69 expect(e.children.length, isZero, reason: 'is empty'); | 70 expect(e.children.length, isZero, reason: 'is empty'); |
70 }); | 71 }); |
71 }); | 72 }); |
72 group('invokes', () { | 73 group('invokes', () { |
73 test('add on click', () async { | 74 test('add on click', () async { |
74 final address = 'ws://host:1234/ws'; | 75 final address = 'ws://host:1234/ws'; |
75 final list = <TargetMock>[const TargetMock(name: 't-1')]; | 76 final list = <TargetMock>[const TargetMock(name: 't-1')]; |
76 final targets = new TargetRepositoryMock(list: list, | 77 final targets = new TargetRepositoryMock( |
| 78 list: list, |
77 add: expectAsync((String val) { | 79 add: expectAsync((String val) { |
78 expect(val, equals(address)); | 80 expect(val, equals(address)); |
79 }, count: 1, reason: 'should be invoked')); | 81 }, count: 1, reason: 'should be invoked')); |
80 final e = new VMConnectElement(targets, load, | 82 final e = new VMConnectElement( |
81 new NotificationRepositoryMock(), address: address); | 83 targets, load, new NotificationRepositoryMock(), |
| 84 address: address); |
82 document.body.append(e); | 85 document.body.append(e); |
83 await e.onRendered.first; | 86 await e.onRendered.first; |
84 (e.querySelector('button.vm_connect') as ButtonElement).click(); | 87 (e.querySelector('button.vm_connect') as ButtonElement).click(); |
85 e.remove(); | 88 e.remove(); |
86 await e.onRendered.first; | 89 await e.onRendered.first; |
87 }); | 90 }); |
88 test('connect', () async { | 91 test('connect', () async { |
89 final list = <TargetMock>[const TargetMock(name: 't-1')]; | 92 final list = <TargetMock>[const TargetMock(name: 't-1')]; |
90 final targets = new TargetRepositoryMock(list: list, | 93 final targets = new TargetRepositoryMock( |
| 94 list: list, |
91 setCurrent: expectAsync((TargetMock t) { | 95 setCurrent: expectAsync((TargetMock t) { |
92 expect(t, equals(list[0])); | 96 expect(t, equals(list[0])); |
93 }, count: 1, reason: 'should be invoked')); | 97 }, count: 1, reason: 'should be invoked')); |
94 final e = new VMConnectElement(targets, load, | 98 final e = |
95 new NotificationRepositoryMock()); | 99 new VMConnectElement(targets, load, new NotificationRepositoryMock()); |
96 document.body.append(e); | 100 document.body.append(e); |
97 await e.onRendered.first; | 101 await e.onRendered.first; |
98 (e.querySelector(tTag) as VMConnectTargetElement).connect(); | 102 (e.querySelector(tTag) as VMConnectTargetElement).connect(); |
99 e.remove(); | 103 e.remove(); |
100 await e.onRendered.first; | 104 await e.onRendered.first; |
101 }); | 105 }); |
102 test('delete', () async { | 106 test('delete', () async { |
103 final list = <TargetMock>[const TargetMock(name: 't-1')]; | 107 final list = <TargetMock>[const TargetMock(name: 't-1')]; |
104 final targets = new TargetRepositoryMock(list: list, | 108 final targets = new TargetRepositoryMock( |
| 109 list: list, |
105 delete: expectAsync((TargetMock t) { | 110 delete: expectAsync((TargetMock t) { |
106 expect(t, equals(list[0])); | 111 expect(t, equals(list[0])); |
107 }, count: 1, reason: 'should be invoked')); | 112 }, count: 1, reason: 'should be invoked')); |
108 final e = new VMConnectElement(targets, load, | 113 final e = |
109 new NotificationRepositoryMock()); | 114 new VMConnectElement(targets, load, new NotificationRepositoryMock()); |
110 document.body.append(e); | 115 document.body.append(e); |
111 await e.onRendered.first; | 116 await e.onRendered.first; |
112 (e.querySelector(tTag) as VMConnectTargetElement).delete(); | 117 (e.querySelector(tTag) as VMConnectTargetElement).delete(); |
113 e.remove(); | 118 e.remove(); |
114 await e.onRendered.first; | 119 await e.onRendered.first; |
115 }); | 120 }); |
116 }); | 121 }); |
117 } | 122 } |
OLD | NEW |