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

Unified Diff: pkg/observe/test/list_path_observer_test.dart

Issue 357003002: Fix list_path_observer, temporarily add a test for it, but we'll likely remove (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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/observe/lib/src/list_path_observer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/observe/test/list_path_observer_test.dart
diff --git a/pkg/observe/test/list_path_observer_test.dart b/pkg/observe/test/list_path_observer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3010d128305efbb4d5c8ae4a41cef11cf03a54e5
--- /dev/null
+++ b/pkg/observe/test/list_path_observer_test.dart
@@ -0,0 +1,77 @@
+// 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.
+
+import 'dart:async';
+import 'package:observe/observe.dart';
+import 'package:unittest/unittest.dart';
+import 'observe_test_utils.dart';
+
+main() => dirtyCheckZone().run(_runTests);
+
+_runTests() {
+ var list;
+ var obs;
+ var o1, o2, o3;
+ var sub;
+ int changes;
+
+ setUp(() {
+ list = toObservable([
+ o1 = new TestModel()..a = (new TestModel()..b = 1),
+ o2 = new TestModel()..a = (new TestModel()..b = 2),
+ o3 = new TestModel()..a = (new TestModel()..b = 3)]);
+ obs = new ListPathObserver(list, 'a.b');
+ changes = 0;
+ sub = obs.changes.listen((e) { changes++; });
+ });
+
+ tearDown(() {
+ sub.cancel();
+ list = obs = o1 = o2 = o3 = null;
+ });
+
+ test('list path observer noticed length changes', () {
+ expect(o2.a.b, 2);
+ expect(list[1].a.b, 2);
+ return _nextMicrotask(null).then((_) {
+ expect(changes, 0);
+ list.removeAt(1);
+ }).then(_nextMicrotask).then((_) {
+ expect(changes, 1);
+ expect(list[1].a.b, 3);
+ });
+ });
+
+ test('list path observer delivers deep change', () {
+ expect(o2.a.b, 2);
+ expect(list[1].a.b, 2);
+ int changes = 0;
+ obs.changes.listen((e) { changes++; });
+ return _nextMicrotask(null).then((_) {
+ expect(changes, 0);
+ o2.a.b = 4;
+ }).then(_nextMicrotask).then((_) {
+ expect(changes, 1);
+ expect(list[1].a.b, 4);
+ o1.a = new TestModel()..b = 5;
+ }).then(_nextMicrotask).then((_) {
+ expect(changes, 2);
+ expect(list[0].a.b, 5);
+ });
+ });
+}
+
+_nextMicrotask(_) => new Future(() {});
+
+@reflectable
+class TestModel extends ChangeNotifier {
+ var _a, _b;
+ TestModel();
+
+ get a => _a;
+ void set a(newValue) { _a = notifyPropertyChange(#a, _a, newValue); }
+
+ get b => _b;
+ void set b(newValue) { _b = notifyPropertyChange(#b, _b, newValue); }
+}
« no previous file with comments | « pkg/observe/lib/src/list_path_observer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698