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