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