|
| 1 | +import 'package:dcc_toolkit/pagination/pagination_state.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('PaginationState', () { |
| 6 | + group('hasNextPage', () { |
| 7 | + test('returns true when current page is less than last page', () { |
| 8 | + const state = PaginationState<String>(currentPage: 2, lastPage: 5); |
| 9 | + |
| 10 | + expect(state.hasNextPage, true); |
| 11 | + }); |
| 12 | + |
| 13 | + test('returns false when current page equals last page', () { |
| 14 | + const state = PaginationState<String>(currentPage: 5, lastPage: 5); |
| 15 | + |
| 16 | + expect(state.hasNextPage, false); |
| 17 | + }); |
| 18 | + |
| 19 | + test('returns false when current page is greater than last page', () { |
| 20 | + const state = PaginationState<String>(currentPage: 6, lastPage: 5); |
| 21 | + |
| 22 | + expect(state.hasNextPage, false); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + group('equality', () { |
| 27 | + test('returns true for identical instances', () { |
| 28 | + const state = PaginationState<String>(); |
| 29 | + |
| 30 | + expect(state == state, true); |
| 31 | + expect(state.hashCode == state.hashCode, true); |
| 32 | + }); |
| 33 | + |
| 34 | + test('returns true for instances with same values', () { |
| 35 | + const items = ['item1', 'item2']; |
| 36 | + const state1 = PaginationState<String>( |
| 37 | + items: items, |
| 38 | + currentPage: 2, |
| 39 | + lastPage: 5, |
| 40 | + isLoading: true, |
| 41 | + loadingInitialPage: false, |
| 42 | + hasError: true, |
| 43 | + total: 50, |
| 44 | + searchQuery: 'test', |
| 45 | + ); |
| 46 | + const state2 = PaginationState<String>( |
| 47 | + items: items, |
| 48 | + currentPage: 2, |
| 49 | + lastPage: 5, |
| 50 | + isLoading: true, |
| 51 | + loadingInitialPage: false, |
| 52 | + hasError: true, |
| 53 | + total: 50, |
| 54 | + searchQuery: 'test', |
| 55 | + ); |
| 56 | + |
| 57 | + expect(state1 == state2, true); |
| 58 | + expect(state1.hashCode == state2.hashCode, true); |
| 59 | + }); |
| 60 | + |
| 61 | + test('returns false for instances with different items', () { |
| 62 | + const state1 = PaginationState<String>(items: ['item1']); |
| 63 | + const state2 = PaginationState<String>(items: ['item2']); |
| 64 | + |
| 65 | + expect(state1 == state2, false); |
| 66 | + expect(state1.hashCode == state2.hashCode, false); |
| 67 | + }); |
| 68 | + |
| 69 | + test('returns false for instances with different currentPage', () { |
| 70 | + const state1 = PaginationState<String>(); |
| 71 | + const state2 = PaginationState<String>(currentPage: 2); |
| 72 | + |
| 73 | + expect(state1 == state2, false); |
| 74 | + expect(state1.hashCode == state2.hashCode, false); |
| 75 | + }); |
| 76 | + |
| 77 | + test('returns false for instances with different lastPage', () { |
| 78 | + const state1 = PaginationState<String>(lastPage: 3); |
| 79 | + const state2 = PaginationState<String>(lastPage: 5); |
| 80 | + |
| 81 | + expect(state1 == state2, false); |
| 82 | + expect(state1.hashCode == state2.hashCode, false); |
| 83 | + }); |
| 84 | + |
| 85 | + test('returns false for instances with different isLoading', () { |
| 86 | + const state1 = PaginationState<String>(isLoading: true); |
| 87 | + const state2 = PaginationState<String>(); |
| 88 | + |
| 89 | + expect(state1 == state2, false); |
| 90 | + expect(state1.hashCode == state2.hashCode, false); |
| 91 | + }); |
| 92 | + |
| 93 | + test('returns false for instances with different loadingInitialPage', () { |
| 94 | + const state1 = PaginationState<String>(); |
| 95 | + const state2 = PaginationState<String>(loadingInitialPage: false); |
| 96 | + |
| 97 | + expect(state1 == state2, false); |
| 98 | + expect(state1.hashCode == state2.hashCode, false); |
| 99 | + }); |
| 100 | + |
| 101 | + test('returns false for instances with different hasError', () { |
| 102 | + const state1 = PaginationState<String>(hasError: true); |
| 103 | + const state2 = PaginationState<String>(); |
| 104 | + |
| 105 | + expect(state1 == state2, false); |
| 106 | + expect(state1.hashCode == state2.hashCode, false); |
| 107 | + }); |
| 108 | + |
| 109 | + test('returns false for instances with different generic types', () { |
| 110 | + const stringState = PaginationState<String>(); |
| 111 | + const intState = PaginationState<int>(); |
| 112 | + |
| 113 | + expect(stringState.runtimeType == intState.runtimeType, false); |
| 114 | + }); |
| 115 | + }); |
| 116 | + }); |
| 117 | +} |
0 commit comments