base_utils_test.dart 1.27 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_tools/src/base/utils.dart';
6

7
import '../src/common.dart';
8

9
void main() {
10 11
  group('ItemListNotifier', () {
    test('sends notifications', () async {
12
      final ItemListNotifier<String> list = ItemListNotifier<String>();
13 14
      expect(list.items, isEmpty);

15 16
      final Future<List<String>> addedStreamItems = list.onAdded.toList();
      final Future<List<String>> removedStreamItems = list.onRemoved.toList();
17 18

      list.updateWithNewList(<String>['aaa']);
19 20 21 22 23 24
      list.removeItem('bogus');
      list.updateWithNewList(<String>['aaa', 'bbb', 'ccc']);
      list.updateWithNewList(<String>['bbb', 'ccc']);
      list.removeItem('bbb');

      expect(list.items, <String>['ccc']);
25 26
      list.dispose();

27 28
      final List<String> addedItems = await addedStreamItems;
      final List<String> removedItems = await removedStreamItems;
29

30
      expect(addedItems.length, 3);
31 32
      expect(addedItems.first, 'aaa');
      expect(addedItems[1], 'bbb');
33
      expect(addedItems[2], 'ccc');
34

35
      expect(removedItems.length, 2);
36
      expect(removedItems.first, 'aaa');
37
      expect(removedItems[1], 'bbb');
38 39 40
    });
  });
}