@@ -58,6 +58,7 @@ void main() {
58
58
User ? selfUser,
59
59
List <User > otherUsers = const [],
60
60
List <ZulipStream > streams = const [],
61
+ List <Subscription > subscriptions = const [],
61
62
List <Message >? messages,
62
63
bool ? mandatoryTopics,
63
64
int ? zulipFeatureLevel,
@@ -81,6 +82,7 @@ void main() {
81
82
await testBinding.globalStore.add (selfAccount, eg.initialSnapshot (
82
83
realmUsers: [selfUser, ...otherUsers],
83
84
streams: streams,
85
+ subscriptions: subscriptions,
84
86
zulipFeatureLevel: zulipFeatureLevel,
85
87
realmMandatoryTopics: mandatoryTopics,
86
88
realmAllowMessageEditing: true ,
@@ -1281,7 +1283,7 @@ void main() {
1281
1283
});
1282
1284
});
1283
1285
1284
- group ('in channel/topic narrow according to channel post policy' , () {
1286
+ group ('in channel/topic narrow according to channel post policy and privacy/subscribed ' , () {
1285
1287
void checkComposeBox ({required bool isShown}) => checkComposeBoxIsShown (isShown,
1286
1288
bannerLabel: zulipLocalizations.errorBannerCannotPostInChannelLabel);
1287
1289
@@ -1300,14 +1302,25 @@ void main() {
1300
1302
checkComposeBox (isShown: true );
1301
1303
});
1302
1304
1303
- testWidgets ('error banner is shown in $narrowType narrow' , (tester) async {
1305
+ testWidgets ('error banner is shown in $narrowType narrow without posting permission ' , (tester) async {
1304
1306
await prepareComposeBox (tester,
1305
1307
narrow: narrow,
1306
1308
selfUser: eg.user (role: UserRole .moderator),
1307
1309
streams: [eg.stream (streamId: 1 ,
1308
1310
channelPostPolicy: ChannelPostPolicy .administrators)]);
1309
1311
checkComposeBox (isShown: false );
1310
1312
});
1313
+
1314
+ testWidgets ('error banner is shown in $narrowType when private and unsubscribed' , (tester) async {
1315
+ await prepareComposeBox (tester,
1316
+ narrow: narrow,
1317
+ selfUser: eg.user (role: UserRole .moderator),
1318
+ streams: [eg.stream (streamId: 1 ,
1319
+ channelPostPolicy: ChannelPostPolicy .any,
1320
+ inviteOnly: true )]);
1321
+ check (store.subscriptions[1 ]).isNull ();
1322
+ checkComposeBox (isShown: false );
1323
+ });
1311
1324
}
1312
1325
1313
1326
testWidgets ('user loses privilege -> compose box is replaced with the banner' , (tester) async {
@@ -1375,6 +1388,80 @@ void main() {
1375
1388
await tester.pump ();
1376
1389
checkComposeBox (isShown: true );
1377
1390
});
1391
+
1392
+ testWidgets ('unsubscribed private channel becomes public -> banner is replaced with the compose box' , (tester) async {
1393
+ final selfUser = eg.user (role: UserRole .moderator);
1394
+ final channel = eg.stream (streamId: 1 , inviteOnly: true ,
1395
+ channelPostPolicy: ChannelPostPolicy .any);
1396
+
1397
+ await prepareComposeBox (tester,
1398
+ narrow: const ChannelNarrow (1 ),
1399
+ selfUser: selfUser,
1400
+ streams: [channel]);
1401
+ check (store.subscriptions[1 ]).isNull ();
1402
+ checkComposeBox (isShown: false );
1403
+
1404
+ await store.handleEvent (eg.channelUpdateEvent (channel,
1405
+ property: ChannelPropertyName .inviteOnly,
1406
+ value: false ));
1407
+ await tester.pump ();
1408
+ checkComposeBox (isShown: true );
1409
+ });
1410
+
1411
+ testWidgets ('unsubscribed public channel becomes private -> compose box is replaced with the banner' , (tester) async {
1412
+ final selfUser = eg.user (role: UserRole .moderator);
1413
+ final channel = eg.stream (streamId: 1 , inviteOnly: false ,
1414
+ channelPostPolicy: ChannelPostPolicy .any);
1415
+
1416
+ await prepareComposeBox (tester,
1417
+ narrow: const ChannelNarrow (1 ),
1418
+ selfUser: selfUser,
1419
+ streams: [channel]);
1420
+ check (store.subscriptions[1 ]).isNull ();
1421
+ checkComposeBox (isShown: true );
1422
+
1423
+ await store.handleEvent (eg.channelUpdateEvent (channel,
1424
+ property: ChannelPropertyName .inviteOnly,
1425
+ value: true ));
1426
+ await tester.pump ();
1427
+ checkComposeBox (isShown: false );
1428
+ });
1429
+
1430
+ testWidgets ('unsubscribed private channel becomes subscribed -> banner is replaced with the compose box' , (tester) async {
1431
+ final selfUser = eg.user (role: UserRole .moderator);
1432
+ final channel = eg.stream (streamId: 1 , inviteOnly: true ,
1433
+ channelPostPolicy: ChannelPostPolicy .any);
1434
+
1435
+ await prepareComposeBox (tester,
1436
+ narrow: const ChannelNarrow (1 ),
1437
+ selfUser: selfUser,
1438
+ streams: [channel]);
1439
+ check (store.subscriptions[1 ]).isNull ();
1440
+ checkComposeBox (isShown: false );
1441
+
1442
+ await store.handleEvent (SubscriptionAddEvent (id: 1 ,
1443
+ subscriptions: [eg.subscription (channel)]));
1444
+ await tester.pump ();
1445
+ checkComposeBox (isShown: true );
1446
+ });
1447
+
1448
+ testWidgets ('subscribed private channel becomes unsubscribed -> compose box is replaced with the banner' , (tester) async {
1449
+ final selfUser = eg.user (role: UserRole .moderator);
1450
+ final channel = eg.stream (streamId: 1 , inviteOnly: true ,
1451
+ channelPostPolicy: ChannelPostPolicy .any);
1452
+
1453
+ await prepareComposeBox (tester,
1454
+ narrow: const ChannelNarrow (1 ),
1455
+ selfUser: selfUser,
1456
+ streams: [channel],
1457
+ subscriptions: [eg.subscription (channel)]);
1458
+ checkComposeBox (isShown: true );
1459
+
1460
+ await store.handleEvent (SubscriptionRemoveEvent (id: 1 ,
1461
+ streamIds: [channel.streamId]));
1462
+ await tester.pump ();
1463
+ checkComposeBox (isShown: false );
1464
+ });
1378
1465
});
1379
1466
});
1380
1467
0 commit comments