|
| 1 | +import 'package:flood_mobile/Model/torrent_content_model.dart'; |
| 2 | +import 'package:flood_mobile/Provider/torrent_content_provider.dart'; |
| 3 | +import 'package:flutter_test/flutter_test.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + late TorrentContentProvider sut; |
| 7 | + |
| 8 | + setUp(() { |
| 9 | + sut = TorrentContentProvider(); |
| 10 | + }); |
| 11 | + |
| 12 | + test( |
| 13 | + "initial values are correct", |
| 14 | + () { |
| 15 | + expect(sut.torrentContentList, []); |
| 16 | + expect(sut.isSelectionMode, false); |
| 17 | + expect(sut.selectedIndexList, []); |
| 18 | + }, |
| 19 | + ); |
| 20 | + |
| 21 | + group('setTorrentContentList', () { |
| 22 | + final newTorrentContentList = [ |
| 23 | + TorrentContentModel( |
| 24 | + filename: 'test filename', |
| 25 | + index: 0, |
| 26 | + path: 'test path', |
| 27 | + percentComplete: null, |
| 28 | + priority: 0, |
| 29 | + sizeBytes: 0, |
| 30 | + depth: 0, |
| 31 | + parentPath: ['test parentPath'], |
| 32 | + isMediaFile: true, |
| 33 | + ) |
| 34 | + ]; |
| 35 | + |
| 36 | + test( |
| 37 | + "tests setTorrentContentList working", |
| 38 | + () async { |
| 39 | + expect(sut.torrentContentList.isEmpty, true); |
| 40 | + sut.setTorrentContentList(newTorrentContentList); |
| 41 | + expect(sut.torrentContentList.isEmpty, false); |
| 42 | + expect(sut.torrentContentList[0].filename, 'test filename'); |
| 43 | + }, |
| 44 | + ); |
| 45 | + |
| 46 | + test( |
| 47 | + "tests setSelectionMode working", |
| 48 | + () async { |
| 49 | + expect(sut.isSelectionMode, false); |
| 50 | + sut.setSelectionMode(newIsSelected: true); |
| 51 | + expect(sut.isSelectionMode, true); |
| 52 | + }, |
| 53 | + ); |
| 54 | + |
| 55 | + test( |
| 56 | + "tests addItemToSelectedIndex working", |
| 57 | + () async { |
| 58 | + expect(sut.selectedIndexList.length, 0); |
| 59 | + sut.addItemToSelectedIndex(1); |
| 60 | + expect(sut.selectedIndexList.length, 1); |
| 61 | + }, |
| 62 | + ); |
| 63 | + |
| 64 | + test( |
| 65 | + "tests removeItemFromSelectedList working", |
| 66 | + () async { |
| 67 | + expect(sut.selectedIndexList.length, 0); |
| 68 | + sut.addItemToSelectedIndex(1); |
| 69 | + sut.addItemToSelectedIndex(2); |
| 70 | + sut.removeItemFromSelectedList(1); |
| 71 | + expect(sut.selectedIndexList, [2]); |
| 72 | + }, |
| 73 | + ); |
| 74 | + |
| 75 | + test( |
| 76 | + "tests removeAllItemsFromList working", |
| 77 | + () async { |
| 78 | + sut.addItemToSelectedIndex(1); |
| 79 | + sut.addItemToSelectedIndex(2); |
| 80 | + expect(sut.selectedIndexList.length, 2); |
| 81 | + sut.removeAllItemsFromList(); |
| 82 | + expect(sut.selectedIndexList.length, 0); |
| 83 | + }, |
| 84 | + ); |
| 85 | + }); |
| 86 | +} |
0 commit comments