|
| 1 | +import 'package:bloc_test/bloc_test.dart'; |
| 2 | +import 'package:flood_mobile/Blocs/filter_torrent_bloc/filter_torrent_bloc.dart'; |
| 3 | +import 'package:test/test.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + group('FilterTorrentBloc', () { |
| 7 | + late FilterTorrentBloc filterTorrentBloc; |
| 8 | + |
| 9 | + setUp(() { |
| 10 | + filterTorrentBloc = FilterTorrentBloc(); |
| 11 | + }); |
| 12 | + |
| 13 | + tearDown(() { |
| 14 | + filterTorrentBloc.close(); |
| 15 | + }); |
| 16 | + |
| 17 | + test('initial state should be correct', () { |
| 18 | + expect(filterTorrentBloc.state, FilterTorrentState()); |
| 19 | + }); |
| 20 | + |
| 21 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 22 | + 'emits FilterTorrentState with updated filterStatus when SetFilterSelectedEvent is added', |
| 23 | + build: () => FilterTorrentBloc(), |
| 24 | + act: (bloc) => bloc |
| 25 | + .add(SetFilterSelectedEvent(filterStatus: FilterValue.downloading)), |
| 26 | + expect: () => [ |
| 27 | + FilterTorrentState( |
| 28 | + filterStatus: FilterValue.downloading, |
| 29 | + statusList: [], |
| 30 | + mapStatus: {}, |
| 31 | + tagSelected: '', |
| 32 | + mapTags: {'Untagged': 0}, |
| 33 | + trackerURISelected: '', |
| 34 | + trackersSizeList: [], |
| 35 | + tagsSizeList: [], |
| 36 | + maptrackerURIs: {}, |
| 37 | + ), |
| 38 | + ], |
| 39 | + ); |
| 40 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 41 | + 'emits FilterTorrentState with updated statusList when StatusListChanged event is added', |
| 42 | + build: () => filterTorrentBloc, |
| 43 | + act: (bloc) => |
| 44 | + bloc.add(SetStatusListEvent(statusList: ['status1', 'status2'])), |
| 45 | + expect: () => [ |
| 46 | + FilterTorrentState(statusList: ['status1', 'status2']) |
| 47 | + ], |
| 48 | + ); |
| 49 | + |
| 50 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 51 | + 'emits FilterTorrentState with updated tagSelected when TagSelectedChanged event is added', |
| 52 | + build: () => filterTorrentBloc, |
| 53 | + act: (bloc) => bloc.add(SetTagSelectedEvent(tagSelected: 'tag1')), |
| 54 | + expect: () => [FilterTorrentState(tagSelected: 'tag1')], |
| 55 | + ); |
| 56 | + |
| 57 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 58 | + 'emits FilterTorrentState with updated trackerURISelected when TrackerURISelectedChanged event is added', |
| 59 | + build: () => filterTorrentBloc, |
| 60 | + act: (bloc) => |
| 61 | + bloc.add(SetTrackerURISelectedEvent(trackerURISelected: 'tracker1')), |
| 62 | + expect: () => [FilterTorrentState(trackerURISelected: 'tracker1')], |
| 63 | + ); |
| 64 | + |
| 65 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 66 | + 'emits FilterTorrentState with updated mapStatus when MapStatusChanged event is added', |
| 67 | + build: () => filterTorrentBloc, |
| 68 | + act: (bloc) => |
| 69 | + bloc.add(SetMapStatusEvent(mapStatus: {'status': 'value'})), |
| 70 | + expect: () => [ |
| 71 | + FilterTorrentState(mapStatus: {'status': 'value'}) |
| 72 | + ], |
| 73 | + ); |
| 74 | + |
| 75 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 76 | + 'emits FilterTorrentState with updated mapTags when MapTagsChanged event is added', |
| 77 | + build: () => filterTorrentBloc, |
| 78 | + act: (bloc) => bloc.add(SetMapTagsEvent(mapTags: {'tag': 'value'})), |
| 79 | + expect: () => [ |
| 80 | + FilterTorrentState(mapTags: {'tag': 'value'}) |
| 81 | + ], |
| 82 | + ); |
| 83 | + |
| 84 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 85 | + 'emits FilterTorrentState with updated trackersSizeList when TrackersSizeListChanged event is added', |
| 86 | + build: () => filterTorrentBloc, |
| 87 | + act: (bloc) => |
| 88 | + bloc.add(SetTrackersSizeListEvent(trackersSizeList: [1, 2, 3])), |
| 89 | + expect: () => [ |
| 90 | + FilterTorrentState(trackersSizeList: [1, 2, 3]) |
| 91 | + ], |
| 92 | + ); |
| 93 | + |
| 94 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 95 | + 'emits FilterTorrentState with updated tagsSizeList when TagsSizeListChanged event is added', |
| 96 | + build: () => filterTorrentBloc, |
| 97 | + act: (bloc) => bloc.add(SetTagsSizeListEvent(tagsSizeList: [4, 5, 6])), |
| 98 | + expect: () => [ |
| 99 | + FilterTorrentState(tagsSizeList: [4, 5, 6]) |
| 100 | + ], |
| 101 | + ); |
| 102 | + |
| 103 | + blocTest<FilterTorrentBloc, FilterTorrentState>( |
| 104 | + 'emits FilterTorrentState with updated maptrackerURIs when MaptrackerURIsChanged event is added', |
| 105 | + build: () => filterTorrentBloc, |
| 106 | + act: (bloc) => |
| 107 | + bloc.add(SetMapTrackerURIsEvent(maptrackerURIs: {'uri': 'value'})), |
| 108 | + expect: () => [ |
| 109 | + FilterTorrentState(maptrackerURIs: {'uri': 'value'}) |
| 110 | + ], |
| 111 | + ); |
| 112 | + }); |
| 113 | +} |
0 commit comments