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/src/elements/helpers/rendering_queue.dart'; | |
7 import 'package:observatory/src/elements/nav/menu_item.dart'; | 6 import 'package:observatory/src/elements/nav/menu_item.dart'; |
8 | 7 |
9 main() { | 8 main() { |
10 NavMenuItemElement.tag.ensureRegistration(); | 9 NavMenuItemElement.tag.ensureRegistration(); |
11 | 10 |
12 final TimedRenderingBarrier barrier = new TimedRenderingBarrier(); | |
13 final RenderingQueue queue = new RenderingQueue.fromBarrier(barrier); | |
14 | |
15 group('instantiation', () { | 11 group('instantiation', () { |
16 final label = 'custom-label'; | 12 final label = 'custom-label'; |
17 final link = 'link-to-target'; | 13 final link = 'link-to-target'; |
18 test('label', () { | 14 test('label', () { |
19 final NavMenuItemElement e = new NavMenuItemElement(label); | 15 final NavMenuItemElement e = new NavMenuItemElement(label); |
20 expect(e, isNotNull, reason: 'element correctly created'); | 16 expect(e, isNotNull, reason: 'element correctly created'); |
21 expect(e.label, equals(label), reason: 'element correctly created'); | 17 expect(e.label, equals(label), reason: 'element correctly created'); |
22 }); | 18 }); |
23 test('label', () { | 19 test('label', () { |
24 final NavMenuItemElement e = new NavMenuItemElement(label, link: link); | 20 final NavMenuItemElement e = new NavMenuItemElement(label, link: link); |
25 expect(e, isNotNull, reason: 'element correctly created'); | 21 expect(e, isNotNull, reason: 'element correctly created'); |
26 expect(e.link, equals(link), reason: 'element correctly created'); | 22 expect(e.link, equals(link), reason: 'element correctly created'); |
27 }); | 23 }); |
28 }); | 24 }); |
29 group('elements', () { | 25 group('elements', () { |
30 test('created', () async { | 26 test('created', () async { |
31 final label = 'custom-label'; | 27 final label = 'custom-label'; |
32 final NavMenuItemElement e = new NavMenuItemElement(label, queue: queue); | 28 final NavMenuItemElement e = new NavMenuItemElement(label); |
33 document.body.append(e); | 29 document.body.append(e); |
34 await e.onRendered.first; | 30 await e.onRendered.first; |
35 expect(e.shadowRoot.children.length, isNonZero, reason: 'has elements'); | 31 expect(e.shadowRoot.children.length, isNonZero, reason: 'has elements'); |
36 expect(e.shadowRoot.querySelector('content'), isNotNull, | 32 expect(e.shadowRoot.querySelector('content'), isNotNull, |
37 reason: 'has content elements')
; | 33 reason: 'has content elements')
; |
38 e.remove(); | 34 e.remove(); |
39 await e.onRendered.first; | 35 await e.onRendered.first; |
40 expect(e.shadowRoot.children.length, isZero, reason: 'is empty'); | 36 expect(e.shadowRoot.children.length, isZero, reason: 'is empty'); |
41 }); | 37 }); |
42 test('react to label change', () async { | 38 test('react to label change', () async { |
43 final label1 = 'custom-label-1'; | 39 final label1 = 'custom-label-1'; |
44 final label2 = 'custom-label-2'; | 40 final label2 = 'custom-label-2'; |
45 final NavMenuItemElement e = new NavMenuItemElement(label1, queue: queue); | 41 final NavMenuItemElement e = new NavMenuItemElement(label1); |
46 document.body.append(e); | 42 document.body.append(e); |
47 await e.onRendered.first; | 43 await e.onRendered.first; |
48 expect(e.shadowRoot.innerHtml.contains(label1), isTrue); | 44 expect(e.shadowRoot.innerHtml.contains(label1), isTrue); |
49 expect(e.shadowRoot.innerHtml.contains(label2), isFalse); | 45 expect(e.shadowRoot.innerHtml.contains(label2), isFalse); |
50 e.label = label2; | 46 e.label = label2; |
51 await e.onRendered.first; | 47 await e.onRendered.first; |
52 expect(e.shadowRoot.innerHtml.contains(label1), isFalse); | 48 expect(e.shadowRoot.innerHtml.contains(label1), isFalse); |
53 expect(e.shadowRoot.innerHtml.contains(label2), isTrue); | 49 expect(e.shadowRoot.innerHtml.contains(label2), isTrue); |
54 e.remove(); | 50 e.remove(); |
55 await e.onRendered.first; | 51 await e.onRendered.first; |
56 }); | 52 }); |
57 test('react to link change', () async { | 53 test('react to link change', () async { |
58 final label = 'custom-label'; | 54 final label = 'custom-label'; |
59 final link1 = 'custom-label-1'; | 55 final link1 = 'custom-label-1'; |
60 final link2 = 'custom-label-2'; | 56 final link2 = 'custom-label-2'; |
61 final NavMenuItemElement e = new NavMenuItemElement(label, link: link1, | 57 final NavMenuItemElement e = new NavMenuItemElement(label, link: link1); |
62 queue: queue); | |
63 document.body.append(e); | 58 document.body.append(e); |
64 await e.onRendered.first; | 59 await e.onRendered.first; |
65 expect(e.shadowRoot.innerHtml.contains(link1), isTrue); | 60 expect(e.shadowRoot.innerHtml.contains(link1), isTrue); |
66 expect(e.shadowRoot.innerHtml.contains(link2), isFalse); | 61 expect(e.shadowRoot.innerHtml.contains(link2), isFalse); |
67 e.link = link2; | 62 e.link = link2; |
68 await e.onRendered.first; | 63 await e.onRendered.first; |
69 expect(e.shadowRoot.innerHtml.contains(link1), isFalse); | 64 expect(e.shadowRoot.innerHtml.contains(link1), isFalse); |
70 expect(e.shadowRoot.innerHtml.contains(link2), isTrue); | 65 expect(e.shadowRoot.innerHtml.contains(link2), isTrue); |
71 e.remove(); | 66 e.remove(); |
72 await e.onRendered.first; | 67 await e.onRendered.first; |
73 }); | 68 }); |
74 }); | 69 }); |
75 } | 70 } |
OLD | NEW |