Skip to content

emoji_reaction: Add EmojiReactionTheme, including dark variant #805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 26, 2024

Conversation

chrisbobbe
Copy link
Collaborator

@chrisbobbe chrisbobbe commented Jul 12, 2024

Screenshot (also showing some unrelated tweaks toward dark-theme that will land separately):

image

I thought it might be helpful to have a new ThemeExtension for this part of the UI instead of adding all these values to DesignVariables. This way at least we don't have to alphabetize these items along with a lot of attributes from unrelated parts of the UI. I see that we're taking the DesignVariables approach in #762, though, and it's possible that that'll end up being preferred for some reason.

Related: #95

@chrisbobbe chrisbobbe added the integration review Added by maintainers when PR may be ready for integration label Jul 12, 2024
@gnprice
Copy link
Member

gnprice commented Jul 12, 2024

Huh, when I run tests locally at the tip of this, they fail — I think on exactly the RTL half of the cases:

$ flutter test test/widgets/emoji_reaction_test.dart 
00:02 +0: ReactionChipsList smoke (same reaction, different users, with one unknown user): show names when few / text / rtl / text scale: 0.8235
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure was thrown running a test:
Expected: a TextDirection that:
  equals <TextDirection.rtl>
Actual: <TextDirection.ltr>
Which: are not equal

When the exception was thrown, this was the stack:
#0      check.<anonymous closure> (package:checks/src/checks.dart:85:9)
#1      _TestContext.expect (package:checks/src/checks.dart:708:12)
#2      CoreChecks.equals (package:checks/src/extensions/core.dart:90:13)
#3      main.<anonymous closure>.setupChipsInBox (file:///home/greg/z/flutterz/test/widgets/emoji_reaction_test.dart:74:51)
<asynchronous suspension>
#4      main.<anonymous closure>.runSmokeTest.<anonymous closure> (file:///home/greg/z/flutterz/test/widgets/emoji_reaction_test.dart:132:17)
[…]

That begins at the "Set up whole ZulipApp" commit. It persists even after I run flutter pub get (which I believe should be redundant, I believe flutter test does that).

Clearly it works for you and in CI. So presumably there's something that's getting cached for me locally — like the list of locales, perhaps, so that it doesn't know about ar.

Persists also if I run flutter build apk --config-only, which I would have expected to take care of generating any files it was going to generate.

@chrisbobbe
Copy link
Collaborator Author

What does ZulipLocalizations.supportedLocales look like for you?

@gnprice
Copy link
Member

gnprice commented Jul 12, 2024

[en, ja]

@chrisbobbe
Copy link
Collaborator Author

chrisbobbe commented Jul 12, 2024

Hmm, mine was auto-updating to include ar with flutter run. Or anyway the "play" button in Android Studio, which does flutter run.

@gnprice
Copy link
Member

gnprice commented Jul 12, 2024

Cool, yeah, flutter run does it.

I think that probably means flutter gen-l10n will do it. Ah indeed, and our docs say this:

Then run the app (with flutter run or in your IDE),
or perform a hot reload,
to cause the Dart bindings to be updated based on your
changes to the ARB file.
(You can also trigger an update directly, with flutter gen-l10n.)

I guess we'll have to warn everyone to do that after this gets merged.

@gnprice
Copy link
Member

gnprice commented Jul 12, 2024

(Probably this should be thought of as a bug in the flutter tool.)

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Haven't yet read the main commit at the end.)

addTearDown(tester.platformDispatcher.clearLocaleTestValue);
addTearDown(tester.platformDispatcher.clearLocalesTestValue);

await tester.pumpWidget(const ZulipApp());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit turns out to make these tests quite a bit slower:

  # before:
$ time flutter test test/widgets/emoji_reaction_test.dart
00:05 +160: All tests passed!                                                            

time: 6.078s wall (7.313s u, 0.940s s)


  # after:
$ time flutter test test/widgets/emoji_reaction_test.dart
00:09 +160: All tests passed!                                                            

time: 10.528s wall (12.424s u, 1.321s s)

The slowdown happens with this commit:
fa3f012 emoji_reaction test: Set up whole ZulipApp, not just MaterialApp

It'd be good to try to pin down where that time is going. The strategy of reusing ZulipApp in tests makes a lot of sense in principle, so we're likely to try using it in more and more tests… and I'd like to figure out how to do so without slowing all our tests down by 75%.

The strategy I'd try is to just start commenting out parts of ZulipApp's functionality, and rerunning this one test file, and see which pieces are contributing the time.

Then once we know which pieces are at issue, we can see about finding hacks for tests to cut those out, or strip them down to a minimum.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @chrisbobbe! Generally this looks good.

And then repeating here just so the action items are in one place:

  • On merging this, we'll need to make a PSA in #mobile-team that people need to run flutter gen-l10n (or just flutter run) after rebasing in order to get tests working again.
    • And as a bonus followup it'd be nice to find or file an upstream flutter-tool issue about the need for that.

@gnprice
Copy link
Member

gnprice commented Jul 12, 2024

I thought it might be helpful to have a new ThemeExtension for this part of the UI instead of adding all these values to DesignVariables. This way at least we don't have to alphabetize these items along with a lot of attributes from unrelated parts of the UI. I see that we're taking the DesignVariables approach in #762, though, and it's possible that that'll end up being preferred for some reason.

Yeah, I'm not sure. Happy to have both approaches going, and we can see which we like better and optionally refactor later to a single approach.

chrisbobbe added a commit to chrisbobbe/zulip-flutter that referenced this pull request Jul 16, 2024
Greg noticed an instance where using ZulipApp directly was causing
tests to slow down by some 75%:
  zulip#805 (comment)
Specifically, that was when we converted the emoji-reaction widget
tests over to use ZulipApp instead of mimicking it with a
MaterialApp, etc.

It's helpful to use something approaching the real ZulipApp. But
we'd like to avoid that slowdown, especially if it's happening in
code that most tests don't need to exercise. So, here's a
stripped-down version that does that. It takes roughly the same time
as the MaterialApp approach in those emoji-reaction tests. (11s on
my machine, vs. 16s with ZulipApp.)

This commit just converts the tests that were using ZulipApp. Next,
we'll sweep through and treat the ones using the ad hoc MaterialApp
approach.
@chrisbobbe chrisbobbe force-pushed the pr-emoji-reaction-dark-theme branch from cf3ef49 to 7dd90d1 Compare July 16, 2024 23:58
@chrisbobbe
Copy link
Collaborator Author

Thanks for the review! Revision pushed.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Here's a partial review before I switch to another task.

Small comments below, and I tried out the performance effects of these two commits:
0a2b459 test: Add TestZulipApp; replace uses of ZulipApp
c026fce test: Use TestZulipApp everywhere else it makes sense

on flutter test test/widgets on my machine, measuring the fastest of three runs.

Before:
time: 15.837s wall (68.737s u, 9.182s s)

After replacing ZulipApp uses:
time: 15.389s wall (64.851s u, 8.641s s)

After using TestZulipApp more widely:
time: 15.684s wall (64.010s u, 9.070s s)

So replacing ZulipApp made a small speedup, about 7% less total CPU time. Then using TestZulipApp more widely had roughly zero impact, as hoped.

I haven't yet read the last four commits (or revisions to them, at least) in detail:
c026fce test: Use TestZulipApp everywhere else it makes sense
5967ff0 emoji_reaction test [nfc]: Move some setup code out next to similar code
309cff5 emoji_reaction test: Add another convenient test-setup check
7dd90d1 emoji_reaction: Add EmojiReactionTheme, including dark variant

Comment on lines 13 to 14
factory EmojiReactionTheme.light() {
return EmojiReactionTheme._(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump on redirecting constructor (one of those two #804 comments I mentioned)

Comment on lines +12 to +13
this.navigatorObservers,
this.child = const Placeholder(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this final ordering is good but the reordering should get squashed into the commit that introduces the widget

Comment on lines 406 to 407
await tester.pumpAndSettle();
await tester.pump();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice that a lot of pumpAndSettle calls seem to become unnecessary in favor of just pump.

@gnprice
Copy link
Member

gnprice commented Jul 19, 2024

Noting here to help us remember it: #827 introduces another spot that could benefit from TestZulipApp:
#827 (comment)

so whichever of these PRs lands first, we can update that spot in the other PR.

edit: Also #835.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, and here's the rest of a review on this revision. Generally looks great — several nits, and two other comments on tests which should be quick to fix.

supportedLocales: ZulipLocalizations.supportedLocales,
home: GlobalStoreWidget(
child: ChooseAccountPage())));
await tester.pumpWidget(const TestZulipApp(child: ChooseAccountPage()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the specific page is the main interesting bit here, and I think a bit easier to spot if it starts a line:

Suggested change
await tester.pumpWidget(const TestZulipApp(child: ChooseAccountPage()));
await tester.pumpWidget(const TestZulipApp(
child: ChooseAccountPage()));

Comment on lines -49 to -50
home: Directionality(
textDirection: textDirection ?? TextDirection.ltr,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: currently these get turned into the tester.platformDispatcher logic in the big conversion commit:
c026fce test: Use TestZulipApp everywhere else it makes sense

Probably that'd be better as a separate commit coming after that one, since it's different from the otherwise-repetitive other changes in the commit.

Comment on lines +99 to +101
tester.platformDispatcher.accessibilityFeaturesTestValue =
FakeAccessibilityFeatures(boldText: platformRequestsBold);
addTearDown(tester.platformDispatcher.clearAccessibilityFeaturesTestValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to include in the same commit, though. It's fairly straightforwardly just another way of expressing the effect of that MediaQuery.

await tester.pump();
final buttonTextFinder = find.text(buttonText);
final context = tester.element(buttonTextFinder);
final text = tester.renderObject<RenderParagraph>(buttonTextFinder).text;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small simplification:

Suggested change
final text = tester.renderObject<RenderParagraph>(buttonTextFinder).text;
final text = (context.renderObject as RenderParagraph).text;

Then also buttonTextFinder is used just once and can be inlined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also nit: reorder this line to just before the check, after computing the expected values; or perhaps even just inline it into the check call

@@ -204,6 +215,45 @@ void main() {
}
}
}

testWidgets('Smoke test for light/dark/lerped', (tester) async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: nested in unintended group

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'ReactionChipsList' group? It uses some helpers that are in that group. Those could be moved out of the group, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this test didn't seem to be about the ReactionChipsList widget.

I guess that is the widget that test helper is setting up, though, so maybe the grouping is appropriate.

await prepare();
await store.addUsers([eg.selfUser, eg.otherUser]);

debugFollowPlatformBrightness = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs teardown

chrisbobbe added a commit to chrisbobbe/zulip-flutter that referenced this pull request Jul 26, 2024
Greg noticed an instance where using ZulipApp directly was causing
tests to slow down by some 75%:
  zulip#805 (comment)
Specifically, that was when we converted the emoji-reaction widget
tests over to use ZulipApp instead of mimicking it with a
MaterialApp, etc.

It's helpful to use something approaching the real ZulipApp. But
we'd like to avoid that slowdown, especially if it's happening in
code that most tests don't need to exercise. So, here's a
stripped-down version that does that. It takes roughly the same time
as the MaterialApp approach in those emoji-reaction tests. (11s on
my machine, vs. 16s with ZulipApp.)

This commit just converts the tests that were using ZulipApp. Next,
we'll sweep through and treat the ones using the ad hoc MaterialApp
approach.
@chrisbobbe chrisbobbe force-pushed the pr-emoji-reaction-dark-theme branch 2 times, most recently from 3a4af4d to 2f804d5 Compare July 26, 2024 01:47
@chrisbobbe
Copy link
Collaborator Author

Thanks for the review! Revision pushed.

This will let us simplify how we simulate RTL in the emoji-reaction
widget tests, coming up.

Fixes: zulip#803
We're about to refactor the way RTL gets applied.

While we're at it, also check the width of the ReactionChipsList
element.
Greg noticed an instance where using ZulipApp directly was causing
tests to slow down by some 75%:
  zulip#805 (comment)
Specifically, that was when we converted the emoji-reaction widget
tests over to use ZulipApp instead of mimicking it with a
MaterialApp, etc.

It's helpful to use something approaching the real ZulipApp. But
we'd like to avoid that slowdown, especially if it's happening in
code that most tests don't need to exercise. So, here's a
stripped-down version that does that. It takes roughly the same time
as the MaterialApp approach in those emoji-reaction tests. (11s on
my machine, vs. 16s with ZulipApp.)

This commit just converts the tests that were using ZulipApp. Next,
we'll sweep through and treat the ones using the ad hoc MaterialApp
approach.
@gnprice gnprice force-pushed the pr-emoji-reaction-dark-theme branch from 2f804d5 to 6324bf3 Compare July 26, 2024 21:10
@gnprice gnprice merged commit 6324bf3 into zulip:main Jul 26, 2024
@gnprice
Copy link
Member

gnprice commented Jul 26, 2024

Thanks! Looks good — merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants