|
| 1 | +import 'package:flutter_test/flutter_test.dart'; |
| 2 | +import 'package:opso/modals/rsoc_project_modal.dart'; |
| 3 | + |
| 4 | +void main() { |
| 5 | + group('RsocProjectModal', () { |
| 6 | + final tModal = RsocProjectModal( |
| 7 | + name: 'TestProject', |
| 8 | + contributor: 'Alice', |
| 9 | + description: 'A test RSOC project', |
| 10 | + githubUrl: 'https://github.com/test/rsoc', |
| 11 | + ); |
| 12 | + |
| 13 | + test('constructor sets all fields correctly', () { |
| 14 | + expect(tModal.name, 'TestProject'); |
| 15 | + expect(tModal.contributor, 'Alice'); |
| 16 | + expect(tModal.description, 'A test RSOC project'); |
| 17 | + expect(tModal.githubUrl, 'https://github.com/test/rsoc'); |
| 18 | + }); |
| 19 | + |
| 20 | + test('fromJson constructs correctly', () { |
| 21 | + final json = { |
| 22 | + 'name': 'JsonProject', |
| 23 | + 'contributor': 'Bob', |
| 24 | + 'description': 'Json description', |
| 25 | + 'githubUrl': 'https://github.com/json/rsoc', |
| 26 | + }; |
| 27 | + final modal = RsocProjectModal.fromJson(json); |
| 28 | + expect(modal.name, 'JsonProject'); |
| 29 | + expect(modal.contributor, 'Bob'); |
| 30 | + expect(modal.description, 'Json description'); |
| 31 | + expect(modal.githubUrl, 'https://github.com/json/rsoc'); |
| 32 | + }); |
| 33 | + |
| 34 | + test('toJson returns correct map', () { |
| 35 | + final map = tModal.toJson(); |
| 36 | + expect(map['name'], 'TestProject'); |
| 37 | + expect(map['contributor'], 'Alice'); |
| 38 | + expect(map['description'], 'A test RSOC project'); |
| 39 | + expect(map['githubUrl'], 'https://github.com/test/rsoc'); |
| 40 | + }); |
| 41 | + |
| 42 | + test('toJson and fromJson are symmetric', () { |
| 43 | + final map = tModal.toJson(); |
| 44 | + final restored = RsocProjectModal.fromJson(map); |
| 45 | + expect(restored.name, tModal.name); |
| 46 | + expect(restored.contributor, tModal.contributor); |
| 47 | + expect(restored.description, tModal.description); |
| 48 | + expect(restored.githubUrl, tModal.githubUrl); |
| 49 | + }); |
| 50 | + |
| 51 | + test('toString contains all fields', () { |
| 52 | + final str = tModal.toString(); |
| 53 | + expect(str, contains('TestProject')); |
| 54 | + expect(str, contains('Alice')); |
| 55 | + expect(str, contains('A test RSOC project')); |
| 56 | + expect(str, contains('https://github.com/test/rsoc')); |
| 57 | + }); |
| 58 | + |
| 59 | + test('supports empty string fields', () { |
| 60 | + final modal = RsocProjectModal( |
| 61 | + name: '', |
| 62 | + contributor: '', |
| 63 | + description: '', |
| 64 | + githubUrl: '', |
| 65 | + ); |
| 66 | + expect(modal.name, ''); |
| 67 | + expect(modal.contributor, ''); |
| 68 | + }); |
| 69 | + }); |
| 70 | +} |
0 commit comments