18ea023a9d
Primary breaking changes are: - polymer/platform.dart is removed - Rather than platform.flush, use scheduleMicrotask(Observable.dirtyCheck) - Rather than endOfMicrotask, use either scheduleMicrotask or Future.value - Polymer.job removed, use Timer instead (and upvote bug 14414 for timer.restart if you really want the job semantics) This change is bringing up some really weird timing issues in the tests- I don't think any are inherent to the change itself but is more indicative of larger issues. BUG=13666 R=jmesserly@google.com Review URL: https://codereview.chromium.org//41293002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29311 260f80e4-7a28-3924-810f-c04153c831b5
94 lines
2.4 KiB
Dart
94 lines
2.4 KiB
Dart
// 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.bind_mdv_test;
|
|
|
|
import 'dart:async';
|
|
import 'dart:html';
|
|
import 'package:custom_element/polyfill.dart';
|
|
import 'package:template_binding/template_binding.dart';
|
|
import 'package:observe/observe.dart';
|
|
import 'package:unittest/html_config.dart';
|
|
import 'package:unittest/unittest.dart';
|
|
|
|
main() {
|
|
useHtmlConfiguration();
|
|
|
|
var registered = loadCustomElementPolyfill().then((_) {
|
|
document.register('my-div', MyDivElement);
|
|
});
|
|
|
|
setUp(() => registered);
|
|
|
|
group('bindModel', bindModelTests);
|
|
}
|
|
|
|
bindModelTests() {
|
|
var div;
|
|
|
|
setUp(() {
|
|
div = new MyDivElement();
|
|
document.body.append(div);
|
|
});
|
|
|
|
tearDown(() {
|
|
div.remove();
|
|
});
|
|
|
|
parseAndBindHTML(html, model) =>
|
|
templateBind(new Element.tag('template')
|
|
..setInnerHtml(html, treeSanitizer: const NullTreeSanitizer()))
|
|
.createInstance(model);
|
|
|
|
test('bindModel', () {
|
|
var fragment = parseAndBindHTML('<div id="a" foo="{{bar}}"></div>', div);
|
|
div.append(fragment);
|
|
var a = div.query('#a');
|
|
|
|
div.bar = 5;
|
|
return onAttributeChange(a).then((_) {
|
|
expect(a.attributes['foo'], '5');
|
|
div.bar = 8;
|
|
return onAttributeChange(a).then((_) {
|
|
expect(a.attributes['foo'], '8');
|
|
});
|
|
});
|
|
});
|
|
|
|
test('bind input', () {
|
|
var fragment = parseAndBindHTML('<input value="{{bar}}" />', div);
|
|
div.append(fragment);
|
|
var a = div.query('input');
|
|
|
|
div.bar = 'hello';
|
|
// TODO(sorvell): fix this when observe-js lets us explicitly listen for
|
|
// a change on input.value
|
|
Observable.dirtyCheck();
|
|
return new Future.microtask(() {
|
|
expect(a.value, 'hello');
|
|
});
|
|
});
|
|
}
|
|
|
|
class MyDivElement extends HtmlElement with Observable {
|
|
factory MyDivElement() => new Element.tag('my-div');
|
|
MyDivElement.created() : super.created();
|
|
@observable var bar;
|
|
}
|
|
|
|
class NullTreeSanitizer implements NodeTreeSanitizer {
|
|
const NullTreeSanitizer();
|
|
void sanitizeTree(Node node) {}
|
|
}
|
|
|
|
Future onAttributeChange(Element node) {
|
|
var completer = new Completer();
|
|
new MutationObserver((records, observer) {
|
|
observer.disconnect();
|
|
completer.complete();
|
|
})..observe(node, attributes: true);
|
|
scheduleMicrotask(Observable.dirtyCheck);
|
|
return completer.future;
|
|
}
|