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

Unified Diff: test/src/common/polymer_descriptor_test.dart

Issue 1290643006: First cut at behaviors. This just implements the lifecycle methodsportion. We may get the rest for … (Closed) Base URL: git@github.com:dart-lang/polymer-dart.git@master
Patch Set: Created 5 years, 4 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
Index: test/src/common/polymer_descriptor_test.dart
diff --git a/test/src/common/polymer_descriptor_test.dart b/test/src/common/polymer_descriptor_test.dart
index 7df44b0c7490f8d1568d4ed48129bcc7f699c499..664386641f8bae3bcc8cb9f0014f2c40425813c2 100644
--- a/test/src/common/polymer_descriptor_test.dart
+++ b/test/src/common/polymer_descriptor_test.dart
@@ -10,16 +10,11 @@ import 'package:polymer/polymer.dart';
import 'package:polymer/src/common/polymer_descriptor.dart';
main() async {
-
await initPolymer();
test('can build polymer descriptor objects', () {
- var annotation = const PolymerRegister(
- 'test-element',
- extendsTag: 'div',
- hostAttributes: const {
- 'foo': 'bar',
- });
+ var annotation = const PolymerRegister('test-element',
+ extendsTag: 'div', hostAttributes: const {'foo': 'bar',});
JsObject descriptor = createPolymerDescriptor(Test, annotation);
expect(descriptor['is'], annotation.tagName);
@@ -30,26 +25,38 @@ main() async {
var properties = descriptor['properties'];
expectProperty(properties['myString'], type: context['String']);
expectProperty(properties['myInt'], type: context['Number'], notify: true);
- expectProperty(properties['myDouble'], type: context['Number'],
- observer: 'myDoubleChanged');
- expectProperty(properties['myNum'], type: context['Number'],
- reflectToAttribute: true);
+ expectProperty(properties['myDouble'],
+ type: context['Number'], observer: 'myDoubleChanged');
+ expectProperty(properties['myNum'],
+ type: context['Number'], reflectToAttribute: true);
expectProperty(properties['myBool'], type: context['Boolean']);
expectProperty(properties['myMap']);
expectProperty(properties['myStringMap']);
expectProperty(properties['myList'], type: context['Array']);
expectProperty(properties['myStringList'], type: context['Array']);
expectProperty(properties['myDateTime'], type: context['Date']);
- expectProperty(properties['computedNum'], type: context['Number'],
+ expectProperty(properties['computedNum'],
+ type: context['Number'],
computed: 'myNumsCombined(myInt, myDouble, myNum)');
+ // From the dart behaviors!
+ expectProperty(properties['behaviorOneProperty'], type: context['String']);
+ expectProperty(properties['behaviorTwoProperty'], type: context['Number']);
var observers = descriptor['observers'];
- expect(observers[0], 'myStringChanged(myString)');
- expect(observers[1], 'myDoubleOrIntChanged(myDouble, myInt)');
+ expect(observers, contains('myStringChanged(myString)'));
+ expect(observers, contains('myDoubleOrIntChanged(myDouble, myInt)'));
+ // From the dart behaviors!
+ expect(
+ observers, contains('behaviorOnePropertyChanged(behaviorOneProperty)'));
+ expect(
+ observers, contains('behaviorTwoPropertyChanged(behaviorTwoProperty)'));
var listeners = descriptor['listeners'];
expect(listeners['tap'], 'onTap');
expect(listeners['someId.tap'], 'onSomeIdTap');
+ // From the dart behaviors!
+ expect(listeners['someEventOne'], 'onSomeEventOne');
+ expect(listeners['someEventTwo'], 'onSomeEventTwo');
expect(descriptor['ready'] is JsFunction, isTrue);
expect(descriptor['attached'] is JsFunction, isTrue);
@@ -57,11 +64,59 @@ main() async {
expect(descriptor['handleSomeEvent'] is JsFunction, isTrue);
expect(descriptor['myDoubleChanged'] is JsFunction, isTrue);
expect(descriptor['myNumsCombined'] is JsFunction, isTrue);
+ // From the dart behaviors!
+ expect(descriptor['behaviorOneExposedMethod'] is JsFunction, isTrue);
+ expect(descriptor['behaviorTwoExposedMethod'] is JsFunction, isTrue);
+
+ expect(descriptor['behaviors'], isNotNull);
+ expect(descriptor['behaviors'].length, 4);
+ expect(descriptor['behaviors'][0], context['Foo']['JsBehaviorOne']);
+ expect(descriptor['behaviors'][1], behavior.getBehavior(DartBehaviorOne));
+ expect(descriptor['behaviors'][2], context['Foo']['JsBehaviorTwo']);
+ expect(descriptor['behaviors'][3], behavior.getBehavior(DartBehaviorTwo));
+ expect(descriptor['behaviors'][1], isNot(descriptor['behaviors'][3]));
});
}
+@BehaviorProxy(const ['Foo', 'JsBehaviorOne'])
+class JsBehaviorOne {}
+
+@BehaviorProxy(const ['Foo', 'JsBehaviorTwo'])
+class JsBehaviorTwo {}
+
+@behavior
+class DartBehaviorOne {
+ @property
+ String behaviorOneProperty;
+
+ @Observe('behaviorOneProperty')
+ void behaviorOnePropertyChanged() {}
+
+ @Listen('someEventOne')
+ void onSomeEventOne() {}
+
+ @eventHandler
+ void behaviorOneExposedMethod() {}
+}
+
+@behavior
+class DartBehaviorTwo {
+ @property
+ int behaviorTwoProperty;
+
+ @Observe('behaviorTwoProperty')
+ void behaviorTwoPropertyChanged() {}
+
+ @Listen('someEventTwo')
+ void onSomeEventTwo() {}
+
+ @eventHandler
+ void behaviorTwoExposedMethod() {}
+}
+
@jsProxyReflectable
-class Test {
+class Test extends Object
+ with JsBehaviorOne, DartBehaviorOne, JsBehaviorTwo, DartBehaviorTwo {
@property
String myString;
@Property(notify: true)
@@ -113,9 +168,14 @@ class Test {
}
}
-void expectProperty(JsObject actual, {
- computed: null, defined: true, notify: false, observer: null,
- reflectToAttribute: false, type: null, value: isNotNull}) {
+void expectProperty(JsObject actual,
+ {computed: null,
+ defined: true,
+ notify: false,
+ observer: null,
+ reflectToAttribute: false,
+ type: null,
+ value: isNotNull}) {
var expected = {
'computed': computed,
'defined': defined,

Powered by Google App Engine
This is Rietveld 408576698