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