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