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