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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/pkg.status ('k') | pkg/polymer/test/custom_event_test.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/test/custom_event_test.dart
diff --git a/pkg/polymer/test/custom_event_test.dart b/pkg/polymer/test/custom_event_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b0010e77445fae0e07689faea7a8d5060c8c6402
--- /dev/null
+++ b/pkg/polymer/test/custom_event_test.dart
@@ -0,0 +1,62 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library polymer.test.web.custom_event_test;
+
+import 'dart:async';
+import 'dart:html';
+import 'package:polymer/polymer.dart';
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
+
+
+@CustomTag('foo-bar')
+class FooBar extends PolymerElement {
+ // A little too much boilerplate?
+ static const EventStreamProvider<CustomEvent> fooEvent =
+ const EventStreamProvider<CustomEvent>('foo');
+ static const EventStreamProvider<CustomEvent> barBazEvent =
+ const EventStreamProvider<CustomEvent>('barbaz');
+
+ FooBar.created() : super.created();
+
+ Stream<CustomEvent> get onFooEvent =>
+ FooBar.fooEvent.forTarget(this);
+ Stream<CustomEvent> get onBarBazEvent =>
+ FooBar.barBazEvent.forTarget(this);
+
+ fireFoo(x) => dispatchEvent(new CustomEvent('foo', detail: x));
+ fireBarBaz(x) => dispatchEvent(new CustomEvent('barbaz', detail: x));
+}
+
+@CustomTag('test-custom-event')
+class TestCustomEvent extends PolymerElement {
+ TestCustomEvent.created() : super.created();
+
+ get fooBar => getShadowRoot('test-custom-event').query('foo-bar').xtag;
+
+ final events = [];
+ fooHandler(e) => events.add(['foo', e]);
+ barBazHandler(e) => events.add(['barbaz', e]);
+}
+
+main() {
+ initPolymer();
+ useHtmlConfiguration();
+
+ setUp(() => Polymer.onReady);
+
+ test('custom event', () {
+ final testComp = query('test-custom-event');
+ final fooBar = testComp.fooBar;
+ fooBar.fireFoo(123);
+ fooBar.fireBarBaz(42);
+ fooBar.fireFoo(777);
+
+ final events = testComp.events;
+ expect(events.length, 3);
+ expect(events.map((e) => e[0]), ['foo', 'barbaz', 'foo']);
+ expect(events.map((e) => e[1].detail), [123, 42, 777]);
+ });
+}
« 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