|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:opso/modals/sob_project_modal.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('SobProjectModal', () { |
| 6 | + final tModal = SobProjectModal( |
| 7 | + name: 'Alice Smith', |
| 8 | + organization: 'Bitcoin Org', |
| 9 | + description: 'Working on Bitcoin core', |
| 10 | + mentor: 'Bob Jones', |
| 11 | + university: 'MIT', |
| 12 | + country: 'USA', |
| 13 | + projects: [ |
| 14 | + 'https://github.com/test/proj1', |
| 15 | + 'https://github.com/test/proj2', |
| 16 | + ], |
| 17 | + year: 2023, |
| 18 | + ); |
| 19 | + |
| 20 | + test('constructor sets all fields correctly', () { |
| 21 | + expect(tModal.name, 'Alice Smith'); |
| 22 | + expect(tModal.organization, 'Bitcoin Org'); |
| 23 | + expect(tModal.description, 'Working on Bitcoin core'); |
| 24 | + expect(tModal.mentor, 'Bob Jones'); |
| 25 | + expect(tModal.university, 'MIT'); |
| 26 | + expect(tModal.country, 'USA'); |
| 27 | + expect(tModal.projects, hasLength(2)); |
| 28 | + expect(tModal.year, 2023); |
| 29 | + }); |
| 30 | + |
| 31 | + test('copyWith updates selected fields', () { |
| 32 | + final updated = tModal.copyWith(name: 'Jane Doe', country: 'UK'); |
| 33 | + expect(updated.name, 'Jane Doe'); |
| 34 | + expect(updated.country, 'UK'); |
| 35 | + expect(updated.organization, tModal.organization); |
| 36 | + expect(updated.mentor, tModal.mentor); |
| 37 | + }); |
| 38 | + |
| 39 | + test('copyWith with no args returns equivalent object', () { |
| 40 | + final copy = tModal.copyWith(); |
| 41 | + expect(copy.name, tModal.name); |
| 42 | + expect(copy.year, tModal.year); |
| 43 | + }); |
| 44 | + |
| 45 | + test('toMap returns correct map', () { |
| 46 | + final map = tModal.toMap(); |
| 47 | + expect(map['name'], 'Alice Smith'); |
| 48 | + expect(map['organization'], 'Bitcoin Org'); |
| 49 | + expect(map['mentor'], 'Bob Jones'); |
| 50 | + expect(map['university'], 'MIT'); |
| 51 | + expect(map['country'], 'USA'); |
| 52 | + expect(map['year'], 2023); |
| 53 | + expect(map['project_links'], hasLength(2)); |
| 54 | + }); |
| 55 | + |
| 56 | + test('fromMap constructs correctly with project_links', () { |
| 57 | + final map = { |
| 58 | + 'name': 'Bob', |
| 59 | + 'organization': 'Ethereum', |
| 60 | + 'description': 'DeFi work', |
| 61 | + 'mentor': 'Charlie', |
| 62 | + 'university': 'Stanford', |
| 63 | + 'country': 'Canada', |
| 64 | + 'project_links': ['https://github.com/a', 'https://github.com/b'], |
| 65 | + 'year': 2022, |
| 66 | + }; |
| 67 | + final modal = SobProjectModal.fromMap(map); |
| 68 | + expect(modal.name, 'Bob'); |
| 69 | + expect(modal.projects, hasLength(2)); |
| 70 | + expect(modal.year, 2022); |
| 71 | + }); |
| 72 | + |
| 73 | + test('fromMap handles missing project_links gracefully', () { |
| 74 | + final map = { |
| 75 | + 'name': 'NoLinks', |
| 76 | + 'organization': 'Org', |
| 77 | + 'description': 'Desc', |
| 78 | + 'mentor': 'Mentor', |
| 79 | + 'university': 'Univ', |
| 80 | + 'country': 'Country', |
| 81 | + 'year': 2021, |
| 82 | + }; |
| 83 | + final modal = SobProjectModal.fromMap(map); |
| 84 | + expect(modal.projects, isEmpty); |
| 85 | + }); |
| 86 | + |
| 87 | + test('fromMap handles null values with defaults', () { |
| 88 | + final modal = SobProjectModal.fromMap({}); |
| 89 | + expect(modal.name, ''); |
| 90 | + expect(modal.year, 0); |
| 91 | + expect(modal.projects, isEmpty); |
| 92 | + }); |
| 93 | + |
| 94 | + test('equality operator works correctly', () { |
| 95 | + final other = SobProjectModal( |
| 96 | + name: 'Alice Smith', |
| 97 | + organization: 'Bitcoin Org', |
| 98 | + description: 'Working on Bitcoin core', |
| 99 | + mentor: 'Bob Jones', |
| 100 | + university: 'MIT', |
| 101 | + country: 'USA', |
| 102 | + projects: [ |
| 103 | + 'https://github.com/test/proj1', |
| 104 | + 'https://github.com/test/proj2', |
| 105 | + ], |
| 106 | + year: 2023, |
| 107 | + ); |
| 108 | + expect(tModal == other, isTrue); |
| 109 | + }); |
| 110 | + |
| 111 | + test('inequality when fields differ', () { |
| 112 | + final other = tModal.copyWith(name: 'Different'); |
| 113 | + expect(tModal == other, isFalse); |
| 114 | + }); |
| 115 | + |
| 116 | + test('toString contains all key fields', () { |
| 117 | + final str = tModal.toString(); |
| 118 | + expect(str, contains('Alice Smith')); |
| 119 | + expect(str, contains('Bitcoin Org')); |
| 120 | + expect(str, contains('MIT')); |
| 121 | + }); |
| 122 | + }); |
| 123 | +} |
0 commit comments