|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:opso/modals/hyperledger_modal.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('HyperledgerProjectModal', () { |
| 6 | + final tModal = HyperledgerProjectModal( |
| 7 | + name: 'TestProject', |
| 8 | + wiki: 'https://wiki.hyperledger.org/test', |
| 9 | + mentors: ['Alice', 'Bob'], |
| 10 | + year: '2023', |
| 11 | + ); |
| 12 | + |
| 13 | + test('constructor sets all fields correctly', () { |
| 14 | + expect(tModal.name, 'TestProject'); |
| 15 | + expect(tModal.wiki, 'https://wiki.hyperledger.org/test'); |
| 16 | + expect(tModal.mentors, ['Alice', 'Bob']); |
| 17 | + expect(tModal.year, '2023'); |
| 18 | + }); |
| 19 | + |
| 20 | + test('fromJson with list mentors', () { |
| 21 | + final json = { |
| 22 | + 'title': 'ListMentorProject', |
| 23 | + 'link': 'https://wiki.hyperledger.org/list', |
| 24 | + 'mentors': ['Mentor1', 'Mentor2'], |
| 25 | + 'year': 2023, |
| 26 | + }; |
| 27 | + final modal = HyperledgerProjectModal.fromJson(json); |
| 28 | + expect(modal.name, 'ListMentorProject'); |
| 29 | + expect(modal.mentors, ['Mentor1', 'Mentor2']); |
| 30 | + expect(modal.year, '2023'); |
| 31 | + }); |
| 32 | + |
| 33 | + test('fromJson with string mentor', () { |
| 34 | + final json = { |
| 35 | + 'title': 'SingleMentorProject', |
| 36 | + 'link': 'https://wiki.hyperledger.org/single', |
| 37 | + 'mentors': 'SingleMentor', |
| 38 | + 'year': 2022, |
| 39 | + }; |
| 40 | + final modal = HyperledgerProjectModal.fromJson(json); |
| 41 | + expect(modal.mentors, ['SingleMentor']); |
| 42 | + }); |
| 43 | + |
| 44 | + test('fromJson converts year int to string', () { |
| 45 | + final json = { |
| 46 | + 'title': 'YearTest', |
| 47 | + 'link': 'url', |
| 48 | + 'mentors': <String>[], |
| 49 | + 'year': 2024, |
| 50 | + }; |
| 51 | + final modal = HyperledgerProjectModal.fromJson(json); |
| 52 | + expect(modal.year, '2024'); |
| 53 | + }); |
| 54 | + |
| 55 | + test('toJson returns correct map', () { |
| 56 | + final map = tModal.toJson(); |
| 57 | + expect(map['title'], 'TestProject'); |
| 58 | + expect(map['link'], 'https://wiki.hyperledger.org/test'); |
| 59 | + expect(map['mentors'], ['Alice', 'Bob']); |
| 60 | + expect(map['year'], '2023'); |
| 61 | + }); |
| 62 | + |
| 63 | + test('toString contains key fields', () { |
| 64 | + final str = tModal.toString(); |
| 65 | + expect(str, contains('TestProject')); |
| 66 | + expect(str, contains('Alice')); |
| 67 | + expect(str, contains('2023')); |
| 68 | + }); |
| 69 | + |
| 70 | + test('supports empty mentors list', () { |
| 71 | + final modal = HyperledgerProjectModal( |
| 72 | + name: 'NoMentor', |
| 73 | + wiki: 'url', |
| 74 | + mentors: [], |
| 75 | + year: '2023', |
| 76 | + ); |
| 77 | + expect(modal.mentors, isEmpty); |
| 78 | + }); |
| 79 | + }); |
| 80 | +} |
0 commit comments