From f9f7f9ff70cb469826cff41931101ec9b2862238 Mon Sep 17 00:00:00 2001 From: Aditya Date: Sat, 30 May 2026 16:23:53 +0530 Subject: [PATCH] test: add unit tests for LinuxFoundationModal Comprehensive unit tests for LinuxFoundationModal covering: - Constructor field initialization - copyWith() with partial updates - toMap() serialization - fromMap() deserialization - Equality operator (==) - Inequality when fields differ - hashCode consistency for equal objects - toJson() JSON encoding - toString() output --- test/linux_foundation_modal_test.dart | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 test/linux_foundation_modal_test.dart diff --git a/test/linux_foundation_modal_test.dart b/test/linux_foundation_modal_test.dart new file mode 100644 index 00000000..c4093cd5 --- /dev/null +++ b/test/linux_foundation_modal_test.dart @@ -0,0 +1,86 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:opso/modals/linux_foundation_modal.dart'; + +void main() { + group('LinuxFoundationModal', () { + final tModal = LinuxFoundationModal( + name: 'TestProject', + projectUrl: 'https://linuxfoundation.org/test', + imageUrl: 'https://linuxfoundation.org/test.png', + ); + + test('constructor sets all fields correctly', () { + expect(tModal.name, 'TestProject'); + expect(tModal.projectUrl, 'https://linuxfoundation.org/test'); + expect(tModal.imageUrl, 'https://linuxfoundation.org/test.png'); + }); + + test('copyWith returns updated instance', () { + final updated = tModal.copyWith(name: 'UpdatedName'); + expect(updated.name, 'UpdatedName'); + expect(updated.projectUrl, tModal.projectUrl); + expect(updated.imageUrl, tModal.imageUrl); + }); + + test('copyWith with no args returns equivalent object', () { + final copy = tModal.copyWith(); + expect(copy.name, tModal.name); + expect(copy.projectUrl, tModal.projectUrl); + expect(copy.imageUrl, tModal.imageUrl); + }); + + test('toMap returns correct map', () { + final map = tModal.toMap(); + expect(map['name'], 'TestProject'); + expect(map['project_url'], 'https://linuxfoundation.org/test'); + expect(map['image_url'], 'https://linuxfoundation.org/test.png'); + }); + + test('fromMap constructs correctly', () { + final map = { + 'name': 'FromMapProject', + 'project_url': 'https://linuxfoundation.org/from', + 'image_url': 'https://linuxfoundation.org/from.png', + }; + final modal = LinuxFoundationModal.fromMap(map); + expect(modal.name, 'FromMapProject'); + expect(modal.projectUrl, 'https://linuxfoundation.org/from'); + expect(modal.imageUrl, 'https://linuxfoundation.org/from.png'); + }); + + test('equality operator works correctly', () { + final other = LinuxFoundationModal( + name: 'TestProject', + projectUrl: 'https://linuxfoundation.org/test', + imageUrl: 'https://linuxfoundation.org/test.png', + ); + expect(tModal == other, isTrue); + }); + + test('inequality when fields differ', () { + final other = tModal.copyWith(name: 'DifferentName'); + expect(tModal == other, isFalse); + }); + + test('hashCode is consistent', () { + final other = LinuxFoundationModal( + name: 'TestProject', + projectUrl: 'https://linuxfoundation.org/test', + imageUrl: 'https://linuxfoundation.org/test.png', + ); + expect(tModal.hashCode, equals(other.hashCode)); + }); + + test('toJson returns valid JSON string', () { + final jsonStr = tModal.toJson(); + expect(jsonStr, isA()); + expect(jsonStr.contains('TestProject'), isTrue); + }); + + test('toString contains all fields', () { + final str = tModal.toString(); + expect(str, contains('TestProject')); + expect(str, contains('https://linuxfoundation.org/test')); + }); + }); +}