2016-02-21 06:00:11 +00:00
|
|
|
// Copyright 2016 The Chromium Authors. 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:flutter_tools/src/base/utils.dart';
|
2018-08-15 03:33:58 +00:00
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../src/common.dart';
|
2016-02-21 06:00:11 +00:00
|
|
|
|
2016-03-10 01:43:14 +00:00
|
|
|
void main() {
|
2016-02-21 06:00:11 +00:00
|
|
|
group('ItemListNotifier', () {
|
|
|
|
test('sends notifications', () async {
|
2018-09-12 06:29:29 +00:00
|
|
|
final ItemListNotifier<String> list = ItemListNotifier<String>();
|
2016-02-21 06:00:11 +00:00
|
|
|
expect(list.items, isEmpty);
|
|
|
|
|
2017-03-04 01:50:46 +00:00
|
|
|
final Future<List<String>> addedStreamItems = list.onAdded.toList();
|
|
|
|
final Future<List<String>> removedStreamItems = list.onRemoved.toList();
|
2016-02-21 06:00:11 +00:00
|
|
|
|
|
|
|
list.updateWithNewList(<String>['aaa']);
|
|
|
|
list.updateWithNewList(<String>['aaa', 'bbb']);
|
|
|
|
list.updateWithNewList(<String>['bbb']);
|
|
|
|
list.dispose();
|
|
|
|
|
2017-03-04 01:50:46 +00:00
|
|
|
final List<String> addedItems = await addedStreamItems;
|
|
|
|
final List<String> removedItems = await removedStreamItems;
|
2016-02-21 06:00:11 +00:00
|
|
|
|
|
|
|
expect(addedItems.length, 2);
|
|
|
|
expect(addedItems.first, 'aaa');
|
|
|
|
expect(addedItems[1], 'bbb');
|
|
|
|
|
|
|
|
expect(removedItems.length, 1);
|
|
|
|
expect(removedItems.first, 'aaa');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|