Skip to content

Commit

Permalink
emoji_reaction test [nfc]: Move some setup code out next to similar code
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbobbe committed Jul 16, 2024
1 parent c026fce commit 5967ff0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions test/widgets/emoji_reaction_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,9 @@ void main() {
Future<void> setupChipsInBox(WidgetTester tester, {
required List<Reaction> reactions,
double width = 245.0, // (seen in context on an iPhone 13 Pro)
TextDirection textDirection = TextDirection.ltr,
}) async {
final message = eg.streamMessage(reactions: reactions);

final locale = switch (textDirection) {
TextDirection.ltr => const Locale('en'),
TextDirection.rtl => const Locale('ar'),
};
tester.platformDispatcher.localeTestValue = locale;
tester.platformDispatcher.localesTestValue = [locale];
addTearDown(tester.platformDispatcher.clearLocaleTestValue);
addTearDown(tester.platformDispatcher.clearLocalesTestValue);

await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id,
child: Center(
child: ColoredBox(
Expand All @@ -68,7 +58,6 @@ void main() {
await tester.pumpAndSettle(); // global store, per-account store

final reactionChipsList = tester.element(find.byType(ReactionChipsList));
check(Directionality.of(reactionChipsList)).equals(textDirection);
check(reactionChipsList).size.isNotNull().width.equals(width);
}

Expand Down Expand Up @@ -106,6 +95,15 @@ void main() {
tester.platformDispatcher.textScaleFactorTestValue = textScaleFactor;
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);

final locale = switch (textDirection) {
TextDirection.ltr => const Locale('en'),
TextDirection.rtl => const Locale('ar'),
};
tester.platformDispatcher.localeTestValue = locale;
tester.platformDispatcher.localesTestValue = [locale];
addTearDown(tester.platformDispatcher.clearLocaleTestValue);
addTearDown(tester.platformDispatcher.clearLocalesTestValue);

await prepare();

await store.addUsers(users);
Expand All @@ -126,7 +124,10 @@ void main() {
..statusCode = HttpStatus.ok
..content = kSolidBlueAvatar;

await setupChipsInBox(tester, textDirection: textDirection, reactions: reactions);
await setupChipsInBox(tester, reactions: reactions);

final reactionChipsList = tester.element(find.byType(ReactionChipsList));
check(Directionality.of(reactionChipsList)).equals(textDirection);

// TODO(upstream) Do these in an addTearDown, once we can:
// https://github.com/flutter/flutter/issues/123189
Expand Down

0 comments on commit 5967ff0

Please sign in to comment.