Skip to content

Commit 589a216

Browse files
committed
Add new unit and widget testing features to the updated code.
1 parent b8f2f37 commit 589a216

File tree

4 files changed

+180
-137
lines changed

4 files changed

+180
-137
lines changed

test/unit_test/home_bloc_unit_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void main() {
7777
rssFeedsContentsList: [],
7878
upSpeed: '0 KB/s',
7979
downSpeed: '0 KB/s',
80+
notificationCancel: {},
8081
),
8182
],
8283
);
@@ -103,6 +104,7 @@ void main() {
103104
rssFeedsContentsList: [],
104105
upSpeed: '0 KB/s',
105106
downSpeed: '0 KB/s',
107+
notificationCancel: {},
106108
),
107109
],
108110
);
@@ -136,6 +138,7 @@ void main() {
136138
rssFeedsContentsList: [],
137139
upSpeed: '0 KB/s',
138140
downSpeed: '0 KB/s',
141+
notificationCancel: {},
139142
),
140143
],
141144
);
@@ -163,6 +166,7 @@ void main() {
163166
rssFeedsContentsList: [],
164167
upSpeed: newUpSpeed + '/s',
165168
downSpeed: newDownSpeed + '/s',
169+
notificationCancel: {},
166170
),
167171
],
168172
);
@@ -217,6 +221,7 @@ void main() {
217221
rssFeedsContentsList: [],
218222
upSpeed: '0 KB/s',
219223
downSpeed: '0 KB/s',
224+
notificationCancel: {},
220225
),
221226
],
222227
);
@@ -245,6 +250,7 @@ void main() {
245250
rssFeedsContentsList: newRssFeedsContentsList,
246251
upSpeed: '0 KB/s',
247252
downSpeed: '0 KB/s',
253+
notificationCancel: {},
248254
),
249255
],
250256
);
@@ -271,6 +277,7 @@ void main() {
271277
rssFeedsContentsList: [],
272278
upSpeed: '0 KB/s',
273279
downSpeed: '0 KB/s',
280+
notificationCancel: {},
274281
),
275282
],
276283
);
@@ -297,6 +304,7 @@ void main() {
297304
rssFeedsContentsList: [],
298305
upSpeed: '0 KB/s',
299306
downSpeed: '0 KB/s',
307+
notificationCancel: {},
300308
),
301309
],
302310
);
@@ -323,6 +331,34 @@ void main() {
323331
rssFeedsContentsList: [],
324332
upSpeed: '0 KB/s',
325333
downSpeed: '0 KB/s',
334+
notificationCancel: {},
335+
),
336+
],
337+
);
338+
});
339+
340+
group('notificationCancel', () {
341+
final newNotificationCancel = {'test': true};
342+
343+
blocTest<HomeScreenBloc, HomeScreenState>(
344+
'emits updated state when updateTorrentList is called',
345+
build: () => sut,
346+
act: (bloc) => bloc.add(UpdateNotificationCancelEvent(
347+
newNotificationCancel: newNotificationCancel)),
348+
expect: () => [
349+
HomeScreenState(
350+
torrentList: [],
351+
torrentListJson: {},
352+
unreadNotifications: 0,
353+
notificationModel: NotificationModel(
354+
read: 0, unread: 0, notifications: [], total: 0),
355+
rssFeedsListJson: {},
356+
rssFeedsList: [],
357+
rssRulesList: [],
358+
rssFeedsContentsList: [],
359+
upSpeed: '0 KB/s',
360+
downSpeed: '0 KB/s',
361+
notificationCancel: {'test': true},
326362
),
327363
],
328364
);

test/widget_test/home_screen_widget_test.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ void main() {
3838
setUp(() {
3939
mockHomeScreenBloc = MockHomeScreenBloc();
4040
mockClientSettingsBloc = MockClientSettingsBloc();
41-
when(() => mockHomeScreenBloc.state).thenReturn(HomeScreenState(
41+
when(() => mockHomeScreenBloc.state).thenReturn(
42+
HomeScreenState(
4243
torrentList: [
4344
TorrentModel(
4445
bytesDone: 0.0,
@@ -145,7 +146,10 @@ void main() {
145146
],
146147
rssFeedsContentsList: [],
147148
upSpeed: '10 Kb/s',
148-
downSpeed: '20 Kb/s'));
149+
downSpeed: '20 Kb/s',
150+
notificationCancel: {},
151+
),
152+
);
149153
});
150154
Widget createWidgetUnderTest() {
151155
return MultiBlocProvider(

test/widget_test/rss_feed_homepage_widget_test.dart

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,48 +27,48 @@ void main() {
2727
mockHomeScreenBloc = MockHomeScreenBloc();
2828
when(() => mockHomeScreenBloc.state).thenReturn(
2929
HomeScreenState(
30-
torrentList: [],
31-
torrentListJson: {},
32-
unreadNotifications: 1,
33-
notificationModel:
34-
NotificationModel(read: 1, notifications: [], total: 2, unread: 1),
35-
rssFeedsListJson: {},
36-
rssFeedsList: [
37-
FeedsAndRulesModel(
38-
type: "test feed",
30+
torrentList: [],
31+
torrentListJson: {},
32+
unreadNotifications: 1,
33+
notificationModel: NotificationModel(
34+
read: 1, notifications: [], total: 2, unread: 1),
35+
rssFeedsListJson: {},
36+
rssFeedsList: [
37+
FeedsAndRulesModel(
38+
type: "test feed",
39+
label: "test label",
40+
interval: 0,
41+
id: "test id",
42+
url: "test url",
43+
count: 0),
44+
FeedsAndRulesModel(
45+
type: "test feed",
46+
label: "test label",
47+
interval: 0,
48+
id: "test id",
49+
url: "test url",
50+
count: 0)
51+
],
52+
rssRulesList: [
53+
RulesModel(
54+
type: "test rules",
3955
label: "test label",
40-
interval: 0,
56+
feedIDs: ["test feedIDs"],
57+
field: "test field",
58+
tags: ["test tags"],
59+
match: "test match",
60+
exclude: "test exclude",
61+
destination: "test destination",
4162
id: "test id",
42-
url: "test url",
43-
count: 0),
44-
FeedsAndRulesModel(
45-
type: "test feed",
46-
label: "test label",
47-
interval: 0,
48-
id: "test id",
49-
url: "test url",
50-
count: 0)
51-
],
52-
rssRulesList: [
53-
RulesModel(
54-
type: "test rules",
55-
label: "test label",
56-
feedIDs: ["test feedIDs"],
57-
field: "test field",
58-
tags: ["test tags"],
59-
match: "test match",
60-
exclude: "test exclude",
61-
destination: "test destination",
62-
id: "test id",
63-
isBasePath: true,
64-
startOnLoad: true,
65-
count: 0,
66-
)
67-
],
68-
rssFeedsContentsList: [],
69-
upSpeed: '10 Kb/s',
70-
downSpeed: '20 Kb/s',
71-
),
63+
isBasePath: true,
64+
startOnLoad: true,
65+
count: 0,
66+
)
67+
],
68+
rssFeedsContentsList: [],
69+
upSpeed: '10 Kb/s',
70+
downSpeed: '20 Kb/s',
71+
notificationCancel: {}),
7272
);
7373
});
7474
Widget createWidgetUnderTest() {

0 commit comments

Comments
 (0)