OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 import 'dart:html'; |
| 5 import 'package:unittest/unittest.dart'; |
| 6 import 'package:observatory/src/elements/nav/menu.dart'; |
| 7 |
| 8 main() { |
| 9 NavMenuElement.tag.ensureRegistration(); |
| 10 |
| 11 group('instantiation', () { |
| 12 final label = 'custom-label'; |
| 13 test('label', () { |
| 14 final NavMenuElement e = new NavMenuElement(label); |
| 15 expect(e, isNotNull, reason: 'element correctly created'); |
| 16 expect(e.label, equals(label), reason: 'element correctly created'); |
| 17 }); |
| 18 test('not last', () { |
| 19 final NavMenuElement e = new NavMenuElement(label, last: false); |
| 20 expect(e, isNotNull, reason: 'element correctly created'); |
| 21 expect(e.last, isFalse, reason: 'element correctly created'); |
| 22 }); |
| 23 test('last', () { |
| 24 final NavMenuElement e = new NavMenuElement(label, last: true); |
| 25 expect(e, isNotNull, reason: 'element correctly created'); |
| 26 expect(e.last, isTrue, reason: 'element correctly created'); |
| 27 }); |
| 28 }); |
| 29 group('elements', () { |
| 30 test('created', () async { |
| 31 final label = 'custom-label'; |
| 32 final NavMenuElement e = new NavMenuElement(label); |
| 33 document.body.append(e); |
| 34 await e.onRendered.first; |
| 35 expect(e.shadowRoot.children.length, isNonZero, reason: 'has elements'); |
| 36 expect(e.shadowRoot.querySelector('content'), isNotNull, |
| 37 reason: 'has content elements')
; |
| 38 e.remove(); |
| 39 await e.onRendered.first; |
| 40 expect(e.shadowRoot.children.length, isZero, reason: 'is empty'); |
| 41 }); |
| 42 test('react to label change', () async { |
| 43 final label1 = 'custom-label-1'; |
| 44 final label2 = 'custom-label-2'; |
| 45 final NavMenuElement e = new NavMenuElement(label1); |
| 46 document.body.append(e); |
| 47 await e.onRendered.first; |
| 48 expect(e.shadowRoot.innerHtml.contains(label1), isTrue); |
| 49 expect(e.shadowRoot.innerHtml.contains(label2), isFalse); |
| 50 e.label = label2; |
| 51 await e.onRendered.first; |
| 52 expect(e.shadowRoot.innerHtml.contains(label1), isFalse); |
| 53 expect(e.shadowRoot.innerHtml.contains(label2), isTrue); |
| 54 e.remove(); |
| 55 await e.onRendered.first; |
| 56 }); |
| 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 }); |
| 73 } |
OLD | NEW |