forked from dart-archive/polymer-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_binding_test.dart
60 lines (49 loc) · 1.67 KB
/
auto_binding_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2014, 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.
import 'dart:async';
import 'dart:html';
import 'package:polymer/auto_binding.dart';
import 'package:polymer/polymer.dart';
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
class TestModel {
var greeting = 'Hi';
eventAction(e) {
e.detail.add('handled');
}
}
main() => initPolymer().then((zone) => zone.run(() {
useHtmlConfiguration();
setUp(() => Polymer.onReady);
test('elements upgraded', () {
AutoBindingElement template = document.getElementById('one');
template.model = new TestModel();
var completer = new Completer();
var events = 0;
window.addEventListener('template-bound', (e) {
events++;
if (e.target.id == 'one') {
expect(e.target, template);
var t = template;
var h = t.$['h'];
expect(h.text, t.model.greeting, reason: 'binding applied');
var ce = t.fire('tap', onNode: h, detail: []);
expect(ce.detail, ['handled'], reason: 'element event handler fired');
}
if (events == 3) completer.complete();
});
/// test dynamic creation
new Future(() {
var d = new DivElement();
d.setInnerHtml('<template is="auto-binding">Dynamical'
' <input value="{{value}}"><div>{{value}}</div></template>',
treeSanitizer: new _NullSanitizer());
document.body.append(d);
});
return completer.future;
});
}));
class _NullSanitizer implements NodeTreeSanitizer {
sanitizeTree(Node node) {}
}