Skip to content

Commit 0a5c691

Browse files
committed
action_sheet test: Check "Subscribe" button absent when no content access
This tests the change in cf83c9e / zulip#1822.
1 parent de03f4b commit 0a5c691

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

test/model/test_store.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ extension PerAccountStoreTestExtension on PerAccountStore {
319319
await handleEvent(ChannelCreateEvent(id: 1, streams: streams));
320320
}
321321

322+
Future<void> updateChannel(
323+
int channelId,
324+
ChannelPropertyName property,
325+
Object? value,
326+
) async {
327+
await handleEvent(ChannelUpdateEvent(
328+
id: 1,
329+
streamId: channelId,
330+
name: 'some channel name', // (not true, of course, but that's fine)
331+
property: property,
332+
value: value));
333+
}
334+
322335
Future<void> addSubscription(Subscription subscription) async {
323336
await addSubscriptions([subscription]);
324337
}

test/widgets/action_sheet_test.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,30 @@ void main() {
341341
await tester.pump(); // [MenuItemButton.onPressed] called in a post-frame callback: flutter/flutter@e4a39fa2e
342342
}
343343

344-
testWidgets('channel not subscribed', (tester) async {
344+
testWidgets('channel not subscribed, with content access', (tester) async {
345345
await prepare();
346346
final narrow = ChannelNarrow(someChannel.streamId);
347347
await store.removeSubscription(narrow.streamId);
348+
check(store.selfHasContentAccess(someChannel)).isTrue();
348349
await showFromMsglistAppBar(tester, narrow: narrow);
349350
checkButton('Subscribe');
350351
});
351352

353+
testWidgets('channel not subscribed, without content access', (tester) async {
354+
final privateChannel = eg.stream(inviteOnly: true);
355+
await prepare();
356+
await store.addStream(privateChannel);
357+
await store.updateChannel(privateChannel.streamId,
358+
ChannelPropertyName.canSubscribeGroup, eg.groupSetting(members: []));
359+
await store.updateChannel(privateChannel.streamId,
360+
ChannelPropertyName.canAddSubscribersGroup, eg.groupSetting(members: []));
361+
final narrow = ChannelNarrow(privateChannel.streamId);
362+
check(store.selfHasContentAccess(privateChannel)).isFalse();
363+
await showFromMsglistAppBar(tester,
364+
channel: privateChannel, narrow: narrow);
365+
checkNoButton('Subscribe');
366+
});
367+
352368
testWidgets('channel subscribed', (tester) async {
353369
await prepare();
354370
final narrow = ChannelNarrow(someChannel.streamId);

0 commit comments

Comments
 (0)