Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: pkg/polymer/test/custom_event_test.dart

Issue 23447017: add test for polymer custom events (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: update Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/pkg.status ('k') | pkg/polymer/test/custom_event_test.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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
5 library polymer.test.web.custom_event_test;
6
7 import 'dart:async';
8 import 'dart:html';
9 import 'package:polymer/polymer.dart';
10 import 'package:unittest/unittest.dart';
11 import 'package:unittest/html_config.dart';
12
13
14 @CustomTag('foo-bar')
15 class FooBar extends PolymerElement {
16 // A little too much boilerplate?
17 static const EventStreamProvider<CustomEvent> fooEvent =
18 const EventStreamProvider<CustomEvent>('foo');
19 static const EventStreamProvider<CustomEvent> barBazEvent =
20 const EventStreamProvider<CustomEvent>('barbaz');
21
22 FooBar.created() : super.created();
23
24 Stream<CustomEvent> get onFooEvent =>
25 FooBar.fooEvent.forTarget(this);
26 Stream<CustomEvent> get onBarBazEvent =>
27 FooBar.barBazEvent.forTarget(this);
28
29 fireFoo(x) => dispatchEvent(new CustomEvent('foo', detail: x));
30 fireBarBaz(x) => dispatchEvent(new CustomEvent('barbaz', detail: x));
31 }
32
33 @CustomTag('test-custom-event')
34 class TestCustomEvent extends PolymerElement {
35 TestCustomEvent.created() : super.created();
36
37 get fooBar => getShadowRoot('test-custom-event').query('foo-bar').xtag;
38
39 final events = [];
40 fooHandler(e) => events.add(['foo', e]);
41 barBazHandler(e) => events.add(['barbaz', e]);
42 }
43
44 main() {
45 initPolymer();
46 useHtmlConfiguration();
47
48 setUp(() => Polymer.onReady);
49
50 test('custom event', () {
51 final testComp = query('test-custom-event');
52 final fooBar = testComp.fooBar;
53 fooBar.fireFoo(123);
54 fooBar.fireBarBaz(42);
55 fooBar.fireFoo(777);
56
57 final events = testComp.events;
58 expect(events.length, 3);
59 expect(events.map((e) => e[0]), ['foo', 'barbaz', 'foo']);
60 expect(events.map((e) => e[1].detail), [123, 42, 777]);
61 });
62 }
OLDNEW
« no previous file with comments | « pkg/pkg.status ('k') | pkg/polymer/test/custom_event_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698