OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 testEventBatch() { | 5 testEventBatch() { |
6 test('EventBatch', () { | 6 test('EventBatch', () { |
7 // check that all events are fired at the end. Use all record methods | 7 // check that all events are fired at the end. Use all record methods |
8 // in abstract observable | 8 // in abstract observable |
9 final target = new AbstractObservable(); | 9 final target = new AbstractObservable(); |
10 EventSummary res = null; | 10 EventSummary res = null; |
11 target.addChangeListener((summary) { | 11 target.addChangeListener((summary) { |
12 expect(res).isNull(); | 12 expect(res, isNull()); |
13 res = summary; | 13 res = summary; |
14 expect(res).isNotNull(); | 14 expect(res, isNotNull()); |
15 }); | 15 }); |
16 | 16 |
17 final f = EventBatch.wrap((e) { | 17 final f = EventBatch.wrap((e) { |
18 target.recordPropertyUpdate('pM', 10, 11); | 18 target.recordPropertyUpdate('pM', 10, 11); |
19 target.recordPropertyUpdate('pL', '11', '13'); | 19 target.recordPropertyUpdate('pL', '11', '13'); |
20 target.recordListUpdate(2, 'a', 'b'); | 20 target.recordListUpdate(2, 'a', 'b'); |
21 target.recordListInsert(5, 'a'); | 21 target.recordListInsert(5, 'a'); |
22 target.recordListRemove(4, 'c'); | 22 target.recordListRemove(4, 'c'); |
23 target.recordGlobalChange(); | 23 target.recordGlobalChange(); |
24 }); | 24 }); |
25 | 25 |
26 expect(res).isNull(); | 26 expect(res, isNull()); |
27 f(null); | 27 f(null); |
28 expect(res).isNotNull(); | 28 expect(res, isNotNull()); |
29 | 29 |
30 expect(res.events.length).equals(6); | 30 expect(res.events, hasLength(6)); |
31 validateUpdate(res.events[0], target, 'pM', null, 10, 11); | 31 validateUpdate(res.events[0], target, 'pM', null, 10, 11); |
32 validateUpdate(res.events[1], target, 'pL', null, '11', '13'); | 32 validateUpdate(res.events[1], target, 'pL', null, '11', '13'); |
33 validateUpdate(res.events[2], target, null, 2, 'a', 'b'); | 33 validateUpdate(res.events[2], target, null, 2, 'a', 'b'); |
34 validateInsert(res.events[3], target, null, 5, 'a'); | 34 validateInsert(res.events[3], target, null, 5, 'a'); |
35 validateRemove(res.events[4], target, null, 4, 'c'); | 35 validateRemove(res.events[4], target, null, 4, 'c'); |
36 validateGlobal(res.events[5], target); | 36 validateGlobal(res.events[5], target); |
37 }); | 37 }); |
38 } | 38 } |
OLD | NEW |