Skip to content

Commit 1991556

Browse files
committed
action_sheet test [nfc]: Pull out a prepare function and reuse
Any of this function's new params (isChannelSubscribed, isChannelMuted, visibilityPolicy, and zulipFeatureLevel) might come in useful as we continue to add to the topic action sheet.
1 parent c27b9f4 commit 1991556

File tree

1 file changed

+39
-43
lines changed

1 file changed

+39
-43
lines changed

test/widgets/action_sheet_test.dart

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -113,37 +113,37 @@ void main() {
113113
final someMessage = eg.streamMessage(
114114
stream: someChannel, topic: someTopic, sender: eg.otherUser);
115115

116-
group('showTopicActionSheet', () {
117-
Future<void> prepare({
118-
ZulipStream? channel,
119-
String topic = someTopic,
120-
bool isChannelSubscribed = true,
121-
bool? isChannelMuted,
122-
UserTopicVisibilityPolicy? visibilityPolicy,
123-
UnreadMessagesSnapshot? unreadMsgs,
124-
int? zulipFeatureLevel,
125-
}) async {
126-
final effectiveChannel = channel ?? someChannel;
127-
assert(isChannelSubscribed || isChannelMuted == null);
128-
129-
addTearDown(testBinding.reset);
130-
131-
final account = eg.selfAccount.copyWith(zulipFeatureLevel: zulipFeatureLevel);
132-
await testBinding.globalStore.add(account, eg.initialSnapshot(
133-
realmUsers: [eg.selfUser, eg.otherUser],
134-
streams: [effectiveChannel],
135-
subscriptions: isChannelSubscribed
136-
? [eg.subscription(effectiveChannel, isMuted: isChannelMuted ?? false)]
137-
: null,
138-
userTopics: visibilityPolicy != null
139-
? [eg.userTopicItem(effectiveChannel, topic, visibilityPolicy)]
140-
: null,
141-
unreadMsgs: unreadMsgs,
142-
zulipFeatureLevel: zulipFeatureLevel));
143-
store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
144-
connection = store.connection as FakeApiConnection;
145-
}
116+
Future<void> prepare({
117+
ZulipStream? channel,
118+
String topic = someTopic,
119+
bool isChannelSubscribed = true,
120+
bool? isChannelMuted,
121+
UserTopicVisibilityPolicy? visibilityPolicy,
122+
UnreadMessagesSnapshot? unreadMsgs,
123+
int? zulipFeatureLevel,
124+
}) async {
125+
final effectiveChannel = channel ?? someChannel;
126+
assert(isChannelSubscribed || isChannelMuted == null);
127+
128+
addTearDown(testBinding.reset);
129+
130+
final account = eg.selfAccount.copyWith(zulipFeatureLevel: zulipFeatureLevel);
131+
await testBinding.globalStore.add(account, eg.initialSnapshot(
132+
realmUsers: [eg.selfUser, eg.otherUser],
133+
streams: [effectiveChannel],
134+
subscriptions: isChannelSubscribed
135+
? [eg.subscription(effectiveChannel, isMuted: isChannelMuted ?? false)]
136+
: null,
137+
userTopics: visibilityPolicy != null
138+
? [eg.userTopicItem(effectiveChannel, topic, visibilityPolicy)]
139+
: null,
140+
unreadMsgs: unreadMsgs,
141+
zulipFeatureLevel: zulipFeatureLevel));
142+
store = await testBinding.globalStore.perAccount(eg.selfAccount.id);
143+
connection = store.connection as FakeApiConnection;
144+
}
146145

146+
group('showTopicActionSheet', () {
147147
void checkButtons() {
148148
final actionSheetFinder = find.byType(BottomSheet);
149149
check(actionSheetFinder).findsOne();
@@ -233,24 +233,20 @@ void main() {
233233

234234
channel = eg.stream();
235235
topic = 'isChannelMuted: $isChannelMuted, policy: $visibilityPolicy';
236-
237-
final account = eg.selfAccount.copyWith(zulipFeatureLevel: zulipFeatureLevel);
238-
final subscriptions = isChannelMuted == null ? <Subscription>[]
239-
: [eg.subscription(channel, isMuted: isChannelMuted)];
240-
await testBinding.globalStore.add(account, eg.initialSnapshot(
241-
realmUsers: [eg.selfUser, eg.otherUser],
242-
streams: [channel],
243-
subscriptions: subscriptions,
244-
userTopics: [eg.userTopicItem(channel, topic, visibilityPolicy)],
245-
zulipFeatureLevel: zulipFeatureLevel));
246-
store = await testBinding.globalStore.perAccount(account.id);
247-
connection = store.connection as FakeApiConnection;
236+
await prepare(
237+
channel: channel,
238+
topic: topic,
239+
isChannelSubscribed: isChannelMuted != null, // shorthand; see dartdoc
240+
isChannelMuted: isChannelMuted,
241+
visibilityPolicy: visibilityPolicy,
242+
zulipFeatureLevel: zulipFeatureLevel,
243+
);
248244

249245
final message = eg.streamMessage(
250246
stream: channel, topic: topic, sender: eg.otherUser);
251247
connection.prepare(json: eg.newestGetMessagesResult(
252248
foundOldest: true, messages: [message]).toJson());
253-
await tester.pumpWidget(TestZulipApp(accountId: account.id,
249+
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
254250
child: MessageListPage(
255251
initNarrow: eg.topicNarrow(channel.streamId, topic))));
256252
await tester.pumpAndSettle();

0 commit comments

Comments
 (0)