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