|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:opso/modals/swoc_project_modal.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('SwocProjectModal', () { |
| 6 | + final tModal = SwocProjectModal( |
| 7 | + name: 'TestProject', |
| 8 | + repo: 'https://github.com/test/repo', |
| 9 | + techstack: ['Flutter', 'Dart'], |
| 10 | + owner: 'TestOwner', |
| 11 | + year: '2023', |
| 12 | + ); |
| 13 | + |
| 14 | + test('constructor sets all fields correctly', () { |
| 15 | + expect(tModal.name, 'TestProject'); |
| 16 | + expect(tModal.repo, 'https://github.com/test/repo'); |
| 17 | + expect(tModal.techstack, ['Flutter', 'Dart']); |
| 18 | + expect(tModal.owner, 'TestOwner'); |
| 19 | + expect(tModal.year, '2023'); |
| 20 | + }); |
| 21 | + |
| 22 | + test('copyWith returns new instance with updated fields', () { |
| 23 | + final updated = tModal.copyWith(name: 'NewName', year: '2024'); |
| 24 | + expect(updated.name, 'NewName'); |
| 25 | + expect(updated.year, '2024'); |
| 26 | + expect(updated.repo, tModal.repo); |
| 27 | + expect(updated.techstack, tModal.techstack); |
| 28 | + expect(updated.owner, tModal.owner); |
| 29 | + }); |
| 30 | + |
| 31 | + test('copyWith with no args returns equivalent object', () { |
| 32 | + final copy = tModal.copyWith(); |
| 33 | + expect(copy.name, tModal.name); |
| 34 | + expect(copy.repo, tModal.repo); |
| 35 | + expect(copy.owner, tModal.owner); |
| 36 | + expect(copy.year, tModal.year); |
| 37 | + }); |
| 38 | + |
| 39 | + test('toMap returns correct map', () { |
| 40 | + final map = tModal.toMap(); |
| 41 | + expect(map['Name'], 'TestProject'); |
| 42 | + expect(map['Repo'], 'https://github.com/test/repo'); |
| 43 | + expect(map['TechStack'], ['Flutter', 'Dart']); |
| 44 | + expect(map['Owner'], 'TestOwner'); |
| 45 | + expect(map['Year'], '2023'); |
| 46 | + }); |
| 47 | + |
| 48 | + test('fromMap constructs correctly', () { |
| 49 | + final map = { |
| 50 | + 'Name': 'FromMapProject', |
| 51 | + 'Repo': 'https://github.com/from/map', |
| 52 | + 'TechStack': ['React', 'Node'], |
| 53 | + 'Owner': 'MapOwner', |
| 54 | + 'Year': '2022', |
| 55 | + }; |
| 56 | + final modal = SwocProjectModal.fromMap(map); |
| 57 | + expect(modal.name, 'FromMapProject'); |
| 58 | + expect(modal.repo, 'https://github.com/from/map'); |
| 59 | + expect(modal.techstack, ['React', 'Node']); |
| 60 | + expect(modal.owner, 'MapOwner'); |
| 61 | + expect(modal.year, '2022'); |
| 62 | + }); |
| 63 | + |
| 64 | + test('getDataFromJson constructs correctly', () { |
| 65 | + final data = { |
| 66 | + 'Name': 'JsonProject', |
| 67 | + 'Repo': 'https://github.com/json/project', |
| 68 | + 'TechStack': ['Python', 'Django'], |
| 69 | + 'Owner': 'JsonOwner', |
| 70 | + 'Year': '2021', |
| 71 | + }; |
| 72 | + final modal = SwocProjectModal.getDataFromJson(data); |
| 73 | + expect(modal.name, 'JsonProject'); |
| 74 | + expect(modal.techstack, ['Python', 'Django']); |
| 75 | + expect(modal.year, '2021'); |
| 76 | + }); |
| 77 | + |
| 78 | + test('toJson returns a valid JSON string', () { |
| 79 | + final jsonStr = tModal.toJson(); |
| 80 | + expect(jsonStr, isA<String>()); |
| 81 | + expect(jsonStr.contains('TestProject'), isTrue); |
| 82 | + }); |
| 83 | + |
| 84 | + test('toString contains all fields', () { |
| 85 | + final str = tModal.toString(); |
| 86 | + expect(str, contains('TestProject')); |
| 87 | + expect(str, contains('TestOwner')); |
| 88 | + expect(str, contains('2023')); |
| 89 | + }); |
| 90 | + |
| 91 | + test('techstack supports empty list', () { |
| 92 | + final modal = SwocProjectModal( |
| 93 | + name: 'NoTech', |
| 94 | + repo: 'url', |
| 95 | + techstack: [], |
| 96 | + owner: 'owner', |
| 97 | + year: '2023', |
| 98 | + ); |
| 99 | + expect(modal.techstack, isEmpty); |
| 100 | + }); |
| 101 | + }); |
| 102 | +} |
0 commit comments