|
| 1 | +import 'dart:convert'; |
| 2 | +import 'package:flutter/foundation.dart'; |
| 3 | +import 'package:flutter_test/flutter_test.dart'; |
| 4 | +import 'package:{{lang.params.packageName}}/src/realtime_response_connected.dart'; |
| 5 | + |
| 6 | +void main() { |
| 7 | + group('RealtimeResponseConnected', () { |
| 8 | + final channels = ['channel1', 'channel2']; |
| 9 | + final user = {'id': 123, 'name': 'John Doe'}; |
| 10 | + final response1 = RealtimeResponseConnected(channels: channels, user: user); |
| 11 | + |
| 12 | + test('copyWith should create a new instance with updated properties', () { |
| 13 | + final newChannels = ['channel3', 'channel4']; |
| 14 | + final newUser = {'id': 456, 'name': 'Jane Smith'}; |
| 15 | + |
| 16 | + final updatedResponse = response1.copyWith(channels: newChannels, user: newUser); |
| 17 | + |
| 18 | + expect(updatedResponse.channels, equals(newChannels)); |
| 19 | + expect(updatedResponse.user, equals(newUser)); |
| 20 | + }); |
| 21 | + |
| 22 | + test('toMap should return a map representation of the response', () { |
| 23 | + final responseMap = response1.toMap(); |
| 24 | + |
| 25 | + expect(responseMap['channels'], equals(channels)); |
| 26 | + expect(responseMap['user'], equals(user)); |
| 27 | + }); |
| 28 | + |
| 29 | + test('fromMap should create an instance from a map', () { |
| 30 | + final responseMap = {'channels': channels, 'user': user}; |
| 31 | + |
| 32 | + final response2 = RealtimeResponseConnected.fromMap(responseMap); |
| 33 | + |
| 34 | + expect(response2.channels, equals(channels)); |
| 35 | + expect(response2.user, equals(user)); |
| 36 | + }); |
| 37 | + |
| 38 | + test('toJson and fromJson should convert to/from JSON', () { |
| 39 | + final jsonString = response1.toJson(); |
| 40 | + |
| 41 | + final response3 = RealtimeResponseConnected.fromJson(jsonString); |
| 42 | + |
| 43 | + expect(response3.channels, equals(channels)); |
| 44 | + expect(response3.user, equals(user)); |
| 45 | + }); |
| 46 | + |
| 47 | + test('toString should return a string representation of the response', () { |
| 48 | + final responseString = response1.toString(); |
| 49 | + |
| 50 | + expect(responseString, equals('RealtimeResponseConnected(channels: $channels, user: $user)')); |
| 51 | + }); |
| 52 | + |
| 53 | + test('equality operator should compare two instances', () { |
| 54 | + final response2 = RealtimeResponseConnected(channels: channels, user: user); |
| 55 | + |
| 56 | + expect(response1 == response2, isTrue); |
| 57 | + }); |
| 58 | + |
| 59 | + test('hashCode should return a unique hash value', () { |
| 60 | + final hashCode1 = response1.hashCode; |
| 61 | + |
| 62 | + final response2 = RealtimeResponseConnected(channels: channels, user: user); |
| 63 | + final hashCode2 = response2.hashCode; |
| 64 | + |
| 65 | + expect(hashCode1, equals(hashCode2)); |
| 66 | + }); |
| 67 | + }); |
| 68 | +} |
0 commit comments