@@ -91,10 +91,20 @@ void main() {
91
91
return stream;
92
92
}
93
93
94
+ Future <Subscription > prepareSingleSubscription (WidgetTester tester) async {
95
+ final stream = eg.subscription (eg.stream ());
96
+ await setupChannelListPage (tester, streams: [stream], subscriptions: [stream]);
97
+ return stream;
98
+ }
99
+
94
100
Future <void > tapSubscribeButton (WidgetTester tester) async {
95
101
await tester.tap (find.byIcon (Icons .add));
96
102
}
97
103
104
+ Future <void > tapUnsubscribeButton (WidgetTester tester) async {
105
+ await tester.tap (find.byIcon (Icons .check));
106
+ }
107
+
98
108
Future <void > waitAndCheckSnackbarIsShown (WidgetTester tester, String message) async {
99
109
await tester.pump (Duration .zero);
100
110
await tester.pumpAndSettle ();
@@ -108,17 +118,20 @@ void main() {
108
118
alreadySubscribed: {}).toJson ());
109
119
110
120
check (find.byIcon (Icons .add).evaluate ()).isNotEmpty ();
121
+ check (find.byIcon (Icons .check).evaluate ()).isEmpty ();
111
122
112
123
await store.handleEvent (SubscriptionAddEvent (id: 1 ,
113
124
subscriptions: [eg.subscription (stream)]));
114
125
await tester.pumpAndSettle ();
115
126
116
127
check (find.byIcon (Icons .add).evaluate ()).isEmpty ();
128
+ check (find.byIcon (Icons .check).evaluate ()).isNotEmpty ();
117
129
118
130
await store.handleEvent (SubscriptionRemoveEvent (id: 2 , streamIds: [stream.streamId]));
119
131
await tester.pumpAndSettle ();
120
132
121
133
check (find.byIcon (Icons .add).evaluate ()).isNotEmpty ();
134
+ check (find.byIcon (Icons .check).evaluate ()).isEmpty ();
122
135
}, skip: true );
123
136
124
137
group ('subscribe' , () {
@@ -193,5 +206,66 @@ void main() {
193
206
expectedMessage: 'NetworkException: Oops (ClientException: Oops)' );
194
207
}, skip: true );
195
208
});
209
+
210
+ group ('unsubscribe' , () {
211
+ testWidgets ('is shown only for streams that user is subscribed to' , (tester) async {
212
+ final streams = [eg.stream (), eg.stream (), eg.subscription (eg.stream ())];
213
+ final subscriptions = [streams[2 ]];
214
+ await setupChannelListPage (tester, streams: streams, subscriptions: subscriptions.cast ());
215
+
216
+ check (find.byIcon (Icons .check).evaluate ().length).equals (1 );
217
+ });
218
+
219
+ testWidgets ('smoke api' , (tester) async {
220
+ final stream = await prepareSingleSubscription (tester);
221
+ connection.prepare (json: UnsubscribeFromChannelsResult (
222
+ removed: [stream.name],
223
+ notRemoved: []).toJson ());
224
+ await tapUnsubscribeButton (tester);
225
+
226
+ await tester.pump (Duration .zero);
227
+ await tester.pumpAndSettle ();
228
+ check (connection.lastRequest).isA< http.Request > ()
229
+ ..method.equals ('DELETE' )
230
+ ..url.path.equals ('/api/v1/users/me/subscriptions' )
231
+ ..bodyFields.deepEquals ({
232
+ 'subscriptions' : jsonEncode ([stream.name])
233
+ });
234
+ });
235
+
236
+ testWidgets ('shows a snackbar when subscription passes' , (WidgetTester tester) async {
237
+ final stream = await prepareSingleSubscription (tester);
238
+ connection.prepare (json: UnsubscribeFromChannelsResult (
239
+ removed: [stream.name],
240
+ notRemoved: []).toJson ());
241
+ await tapUnsubscribeButton (tester);
242
+
243
+ await waitAndCheckSnackbarIsShown (tester,
244
+ zulipLocalizations.messageUnsubscribedFromChannel (stream.name));
245
+ }, skip: true );
246
+
247
+ testWidgets ('shows a snackbar when subscription fails' , (WidgetTester tester) async {
248
+ final stream = await prepareSingleSubscription (tester);
249
+ connection.prepare (json: UnsubscribeFromChannelsResult (
250
+ removed: [],
251
+ notRemoved: [stream.name]).toJson ());
252
+ await tapUnsubscribeButton (tester);
253
+
254
+ await waitAndCheckSnackbarIsShown (tester,
255
+ zulipLocalizations.errorFailedToUnsubscribedFromChannel (stream.name));
256
+ }, skip: true );
257
+
258
+ testWidgets ('catch-all api errors' , (WidgetTester tester) async {
259
+ final stream = await prepareSingleSubscription (tester);
260
+ connection.prepare (exception: http.ClientException ('Oops' ));
261
+ await tapUnsubscribeButton (tester);
262
+ await tester.pump (Duration .zero);
263
+ await tester.pumpAndSettle ();
264
+
265
+ checkErrorDialog (tester,
266
+ expectedTitle: zulipLocalizations.errorFailedToUnsubscribedFromChannel (stream.name),
267
+ expectedMessage: 'NetworkException: Oops (ClientException: Oops)' );
268
+ }, skip: true );
269
+ });
196
270
});
197
271
}
0 commit comments