Skip to content

Commit 69d1b15

Browse files
authored
Merge pull request #234 from amitamrutiya2210/model-testing
implement test cases for all models
2 parents 879c736 + 379d65b commit 69d1b15

12 files changed

+752
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import 'package:flood_mobile/Model/client_settings_model.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('Test ClientSettingsModel', () {
6+
final clientSettings = ClientSettingsModel(
7+
dht: true,
8+
dhtPort: 1234,
9+
directoryDefault: '/path/to/directory',
10+
networkHttpMaxOpen: 10,
11+
networkLocalAddress: ['192.168.1.100', '192.168.1.101'],
12+
networkMaxOpenFiles: 100,
13+
networkPortOpen: true,
14+
networkPortRandom: false,
15+
networkPortRange: '6881-6889',
16+
piecesHashOnCompletion: true,
17+
piecesMemoryMax: 512,
18+
protocolPex: true,
19+
throttleGlobalDownSpeed: 1024,
20+
throttleGlobalUpSpeed: 2048,
21+
throttleMaxPeersNormal: 50,
22+
throttleMaxPeersSeed: 100,
23+
throttleMaxDownloads: 5,
24+
throttleMaxDownloadsGlobal: 10,
25+
throttleMaxUploads: 5,
26+
throttleMaxUploadsGlobal: 10,
27+
throttleMinPeersNormal: 5,
28+
throttleMinPeersSeed: 10,
29+
trackersNumWant: 30,
30+
);
31+
32+
final clientSettingsJson = {
33+
'dht': true,
34+
'dhtPort': 1234,
35+
'directoryDefault': '/path/to/directory',
36+
'networkHttpMaxOpen': 10,
37+
'networkLocalAddress': ['192.168.1.100', '192.168.1.101'],
38+
'networkMaxOpenFiles': 100,
39+
'networkPortOpen': true,
40+
'networkPortRandom': false,
41+
'networkPortRange': '6881-6889',
42+
'piecesHashOnCompletion': true,
43+
'piecesMemoryMax': 512,
44+
'protocolPex': true,
45+
'throttleGlobalDownSpeed': 1024,
46+
'throttleGlobalUpSpeed': 2048,
47+
'throttleMaxPeersNormal': 50,
48+
'throttleMaxPeersSeed': 100,
49+
'throttleMaxDownloads': 5,
50+
'throttleMaxDownloadsGlobal': 10,
51+
'throttleMaxUploads': 5,
52+
'throttleMaxUploadsGlobal': 10,
53+
'throttleMinPeersNormal': 5,
54+
'throttleMinPeersSeed': 10,
55+
'trackersNumWant': 30,
56+
};
57+
58+
test('Test JSON to Model', () {
59+
final clientSettingsFromJson =
60+
ClientSettingsModel.fromJson(clientSettingsJson);
61+
expect(clientSettingsFromJson.dht, clientSettings.dht);
62+
expect(clientSettingsFromJson.dhtPort, clientSettings.dhtPort);
63+
expect(clientSettingsFromJson.directoryDefault,
64+
clientSettings.directoryDefault);
65+
expect(clientSettingsFromJson.networkHttpMaxOpen,
66+
clientSettings.networkHttpMaxOpen);
67+
expect(clientSettingsFromJson.networkLocalAddress,
68+
clientSettings.networkLocalAddress);
69+
expect(clientSettingsFromJson.networkMaxOpenFiles,
70+
clientSettings.networkMaxOpenFiles);
71+
expect(clientSettingsFromJson.networkPortOpen,
72+
clientSettings.networkPortOpen);
73+
expect(clientSettingsFromJson.networkPortRandom,
74+
clientSettings.networkPortRandom);
75+
expect(clientSettingsFromJson.networkPortRange,
76+
clientSettings.networkPortRange);
77+
expect(clientSettingsFromJson.piecesHashOnCompletion,
78+
clientSettings.piecesHashOnCompletion);
79+
expect(clientSettingsFromJson.piecesMemoryMax,
80+
clientSettings.piecesMemoryMax);
81+
expect(clientSettingsFromJson.protocolPex, clientSettings.protocolPex);
82+
expect(clientSettingsFromJson.throttleGlobalDownSpeed,
83+
clientSettings.throttleGlobalDownSpeed);
84+
expect(clientSettingsFromJson.throttleGlobalUpSpeed,
85+
clientSettings.throttleGlobalUpSpeed);
86+
expect(clientSettingsFromJson.throttleMaxPeersNormal,
87+
clientSettings.throttleMaxPeersNormal);
88+
expect(clientSettingsFromJson.throttleMaxPeersSeed,
89+
clientSettings.throttleMaxPeersSeed);
90+
expect(clientSettingsFromJson.throttleMaxDownloads,
91+
clientSettings.throttleMaxDownloads);
92+
expect(clientSettingsFromJson.throttleMaxDownloadsGlobal,
93+
clientSettings.throttleMaxDownloadsGlobal);
94+
expect(clientSettingsFromJson.throttleMaxUploads,
95+
clientSettings.throttleMaxUploads);
96+
expect(clientSettingsFromJson.throttleMaxUploadsGlobal,
97+
clientSettings.throttleMaxUploadsGlobal);
98+
expect(clientSettingsFromJson.throttleMinPeersNormal,
99+
clientSettings.throttleMinPeersNormal);
100+
expect(clientSettingsFromJson.throttleMinPeersSeed,
101+
clientSettings.throttleMinPeersSeed);
102+
expect(clientSettingsFromJson.trackersNumWant,
103+
clientSettings.trackersNumWant);
104+
});
105+
106+
test('Test Model to JSON', () {
107+
final json = clientSettings.toJson();
108+
expect(json, clientSettingsJson);
109+
});
110+
});
111+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'package:flood_mobile/Model/current_user_detail_model.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('Test CurrentUserDetailModel', () {
6+
final currentUserDetail = CurrentUserDetailModel(
7+
username: 'JohnDoe',
8+
level: 2,
9+
);
10+
11+
final currentUserDetailJson = {
12+
'username': 'JohnDoe',
13+
'level': 2,
14+
};
15+
16+
test('Test JSON to Model', () {
17+
final currentUserDetailFromJson =
18+
CurrentUserDetailModel.fromJson(currentUserDetailJson);
19+
expect(currentUserDetailFromJson.username, currentUserDetail.username);
20+
expect(currentUserDetailFromJson.level, currentUserDetail.level);
21+
});
22+
});
23+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:flood_mobile/Model/download_rate_model.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('Test RateModel', () {
6+
final rate = RateModel(
7+
downRate: 100,
8+
downTotal: 200,
9+
upRate: 50,
10+
upTotal: 150,
11+
);
12+
13+
final rateJson = {
14+
'downRate': 100,
15+
'downTotal': 200,
16+
'upRate': 50,
17+
'upTotal': 150,
18+
};
19+
20+
test('Test JSON to Model', () {
21+
final rateFromJson = RateModel.fromJson(rateJson);
22+
expect(rateFromJson.downRate, rate.downRate);
23+
expect(rateFromJson.downTotal, rate.downTotal);
24+
expect(rateFromJson.upRate, rate.upRate);
25+
expect(rateFromJson.upTotal, rate.upTotal);
26+
});
27+
});
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flood_mobile/Model/feeds_content_model.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('Test FeedsContentsModel', () {
6+
final feedsContents = FeedsContentsModel(
7+
title: 'Sample Title',
8+
urls: ['http://example.com/image1.jpg', 'http://example.com/image2.jpg'],
9+
);
10+
11+
final feedsContentsJson = {
12+
'title': 'Sample Title',
13+
'urls': [
14+
'http://example.com/image1.jpg',
15+
'http://example.com/image2.jpg'
16+
],
17+
};
18+
19+
test('Test JSON to Model', () {
20+
final feedsContentsFromJson =
21+
FeedsContentsModel.fromJson(feedsContentsJson);
22+
expect(feedsContentsFromJson.title, feedsContents.title);
23+
expect(feedsContentsFromJson.urls, feedsContents.urls);
24+
});
25+
});
26+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:flood_mobile/Model/notification_model.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('Test NotificationContentModel', () {
6+
final notification = NotificationContentModel(
7+
identification: 'sample_id',
8+
id: 'notification.torrent.finished',
9+
name: 'Sample Name',
10+
read: true,
11+
ts: 1621836000,
12+
status: 'Finished Download',
13+
);
14+
15+
final notificationJson = {
16+
'_id': 'sample_id',
17+
'id': 'notification.torrent.finished',
18+
'data': {'name': 'Sample Name'},
19+
'read': true,
20+
'ts': 1621836000,
21+
'status': 'Finished Download',
22+
};
23+
24+
test('Test JSON to Model', () {
25+
final notificationFromJson =
26+
NotificationContentModel.fromJson(notificationJson);
27+
expect(notificationFromJson.identification, notification.identification);
28+
expect(notificationFromJson.id, notification.id);
29+
expect(notificationFromJson.name, notification.name);
30+
expect(notificationFromJson.read, notification.read);
31+
expect(notificationFromJson.ts, notification.ts);
32+
expect(notificationFromJson.status, notification.status);
33+
});
34+
});
35+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import 'package:flood_mobile/Model/notification_model.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('Test NotificationModel', () {
6+
final notification1 = NotificationContentModel(
7+
identification: 'id1',
8+
id: 'notification.torrent.finished',
9+
name: 'Notification 1',
10+
read: true,
11+
ts: 1621836000,
12+
status: 'Finished Download',
13+
);
14+
15+
final notification2 = NotificationContentModel(
16+
identification: 'id2',
17+
id: 'notification.torrent.started',
18+
name: 'Notification 2',
19+
read: false,
20+
ts: 1621837000,
21+
status: 'Notification',
22+
);
23+
24+
final notificationJson = {
25+
'count': {
26+
'read': 2,
27+
'total': 2,
28+
'unread': 0,
29+
},
30+
'notifications': [
31+
{
32+
'_id': 'id1',
33+
'id': 'notification.torrent.finished',
34+
'data': {'name': 'Notification 1'},
35+
'read': true,
36+
'ts': 1621836000,
37+
},
38+
{
39+
'_id': 'id2',
40+
'id': 'notification.torrent.started',
41+
'data': {'name': 'Notification 2'},
42+
'read': false,
43+
'ts': 1621837000,
44+
},
45+
],
46+
};
47+
48+
test('Test JSON to Model', () {
49+
final notificationModel = NotificationModel.fromJson(notificationJson);
50+
51+
expect(notificationModel.read, 2);
52+
expect(notificationModel.total, 2);
53+
expect(notificationModel.unread, 0);
54+
55+
expect(notificationModel.notifications.length, 2);
56+
57+
expect(notificationModel.notifications[0].identification,
58+
notification1.identification);
59+
expect(notificationModel.notifications[0].id, notification1.id);
60+
expect(notificationModel.notifications[0].name, notification1.name);
61+
expect(notificationModel.notifications[0].read, notification1.read);
62+
expect(notificationModel.notifications[0].ts, notification1.ts);
63+
expect(notificationModel.notifications[0].status, notification1.status);
64+
65+
expect(notificationModel.notifications[1].identification,
66+
notification2.identification);
67+
expect(notificationModel.notifications[1].id, notification2.id);
68+
expect(notificationModel.notifications[1].name, notification2.name);
69+
expect(notificationModel.notifications[1].read, notification2.read);
70+
expect(notificationModel.notifications[1].ts, notification2.ts);
71+
expect(notificationModel.notifications[1].status, notification2.status);
72+
});
73+
});
74+
}

0 commit comments

Comments
 (0)