|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:opso/modals/linux_foundation_modal.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('LinuxFoundationModal', () { |
| 6 | + final tModal = LinuxFoundationModal( |
| 7 | + name: 'TestProject', |
| 8 | + projectUrl: 'https://linuxfoundation.org/test', |
| 9 | + imageUrl: 'https://linuxfoundation.org/test.png', |
| 10 | + ); |
| 11 | + |
| 12 | + test('constructor sets all fields correctly', () { |
| 13 | + expect(tModal.name, 'TestProject'); |
| 14 | + expect(tModal.projectUrl, 'https://linuxfoundation.org/test'); |
| 15 | + expect(tModal.imageUrl, 'https://linuxfoundation.org/test.png'); |
| 16 | + }); |
| 17 | + |
| 18 | + test('copyWith returns updated instance', () { |
| 19 | + final updated = tModal.copyWith(name: 'UpdatedName'); |
| 20 | + expect(updated.name, 'UpdatedName'); |
| 21 | + expect(updated.projectUrl, tModal.projectUrl); |
| 22 | + expect(updated.imageUrl, tModal.imageUrl); |
| 23 | + }); |
| 24 | + |
| 25 | + test('copyWith with no args returns equivalent object', () { |
| 26 | + final copy = tModal.copyWith(); |
| 27 | + expect(copy.name, tModal.name); |
| 28 | + expect(copy.projectUrl, tModal.projectUrl); |
| 29 | + expect(copy.imageUrl, tModal.imageUrl); |
| 30 | + }); |
| 31 | + |
| 32 | + test('toMap returns correct map', () { |
| 33 | + final map = tModal.toMap(); |
| 34 | + expect(map['name'], 'TestProject'); |
| 35 | + expect(map['project_url'], 'https://linuxfoundation.org/test'); |
| 36 | + expect(map['image_url'], 'https://linuxfoundation.org/test.png'); |
| 37 | + }); |
| 38 | + |
| 39 | + test('fromMap constructs correctly', () { |
| 40 | + final map = { |
| 41 | + 'name': 'FromMapProject', |
| 42 | + 'project_url': 'https://linuxfoundation.org/from', |
| 43 | + 'image_url': 'https://linuxfoundation.org/from.png', |
| 44 | + }; |
| 45 | + final modal = LinuxFoundationModal.fromMap(map); |
| 46 | + expect(modal.name, 'FromMapProject'); |
| 47 | + expect(modal.projectUrl, 'https://linuxfoundation.org/from'); |
| 48 | + expect(modal.imageUrl, 'https://linuxfoundation.org/from.png'); |
| 49 | + }); |
| 50 | + |
| 51 | + test('equality operator works correctly', () { |
| 52 | + final other = LinuxFoundationModal( |
| 53 | + name: 'TestProject', |
| 54 | + projectUrl: 'https://linuxfoundation.org/test', |
| 55 | + imageUrl: 'https://linuxfoundation.org/test.png', |
| 56 | + ); |
| 57 | + expect(tModal == other, isTrue); |
| 58 | + }); |
| 59 | + |
| 60 | + test('inequality when fields differ', () { |
| 61 | + final other = tModal.copyWith(name: 'DifferentName'); |
| 62 | + expect(tModal == other, isFalse); |
| 63 | + }); |
| 64 | + |
| 65 | + test('hashCode is consistent', () { |
| 66 | + final other = LinuxFoundationModal( |
| 67 | + name: 'TestProject', |
| 68 | + projectUrl: 'https://linuxfoundation.org/test', |
| 69 | + imageUrl: 'https://linuxfoundation.org/test.png', |
| 70 | + ); |
| 71 | + expect(tModal.hashCode, equals(other.hashCode)); |
| 72 | + }); |
| 73 | + |
| 74 | + test('toJson returns valid JSON string', () { |
| 75 | + final jsonStr = tModal.toJson(); |
| 76 | + expect(jsonStr, isA<String>()); |
| 77 | + expect(jsonStr.contains('TestProject'), isTrue); |
| 78 | + }); |
| 79 | + |
| 80 | + test('toString contains all fields', () { |
| 81 | + final str = tModal.toString(); |
| 82 | + expect(str, contains('TestProject')); |
| 83 | + expect(str, contains('https://linuxfoundation.org/test')); |
| 84 | + }); |
| 85 | + }); |
| 86 | +} |
0 commit comments