@@ -13,6 +13,7 @@ import 'package:zulip/widgets/button.dart';
13
13
import 'package:zulip/widgets/home.dart' ;
14
14
import 'package:zulip/widgets/icons.dart' ;
15
15
import 'package:zulip/widgets/page.dart' ;
16
+ import 'package:zulip/widgets/remote_settings.dart' ;
16
17
import 'package:zulip/widgets/theme.dart' ;
17
18
18
19
import '../api/fake_api.dart' ;
@@ -23,6 +24,7 @@ import '../example_data.dart' as eg;
23
24
import '../model/test_store.dart' ;
24
25
import '../stdlib_checks.dart' ;
25
26
import 'checks.dart' ;
27
+ import 'dialog_checks.dart' ;
26
28
import 'test_app.dart' ;
27
29
28
30
void main () {
@@ -238,4 +240,37 @@ void main() {
238
240
'subscriptions' : jsonEncode ([channel.name]),
239
241
});
240
242
});
243
+
244
+ testWidgets ('Toggle "off" to unsubscribe, but without resubscribe permission' , (tester) async {
245
+ final channel = eg.stream (
246
+ inviteOnly: true , canSubscribeGroup: eg.groupSetting (members: []));
247
+ final subscription = eg.subscription (channel);
248
+
249
+ (Widget , Widget ) checkConfirmDialog () => checkSuggestedActionDialog (tester,
250
+ expectedTitle: 'Unsubscribe from ${channel .name }?' ,
251
+ expectedMessage: 'Once you leave this channel, you will not be able to rejoin.' ,
252
+ expectDestructiveActionButton: true ,
253
+ expectedActionButtonText: 'Unsubscribe' );
254
+
255
+ await setupAllChannelsPage (tester, channels: [subscription]);
256
+
257
+ await tester.tap (find.byType (Toggle ));
258
+ await tester.pump ();
259
+ final (_, cancelButton) = checkConfirmDialog ();
260
+ await tester.tap (find.byWidget (cancelButton));
261
+ await tester.pump ();
262
+ check (connection.lastRequest).isNull ();
263
+ await tester.pump (RemoteSettingBuilder .localEchoIdleTimeout);
264
+
265
+ await tester.tap (find.byType (Toggle ));
266
+ await tester.pump ();
267
+ final (unsubscribeButton, _) = checkConfirmDialog ();
268
+ await tester.tap (find.byWidget (unsubscribeButton));
269
+ check (connection.lastRequest).isA< http.Request > ()
270
+ ..method.equals ('DELETE' )
271
+ ..url.path.equals ('/api/v1/users/me/subscriptions' )
272
+ ..bodyFields.deepEquals ({
273
+ 'subscriptions' : jsonEncode ([channel.name]),
274
+ });
275
+ });
241
276
}
0 commit comments