Skip to content
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

widgets: Pull out reusable UnreadCountBadge widget; grow support for stream colors #371

Merged
merged 5 commits into from
Nov 15, 2023

Conversation

chrisbobbe
Copy link
Collaborator

@chrisbobbe chrisbobbe commented Nov 8, 2023

With an experiment in golden tests. As Greg pointed out in today's weekly mobile-team call, golden tests might not provide much extra value. But anyway, here's an experiment with them, in case it's helpful now or for our future testing needs. 🙂

cc @sirpengi, who might like to use this for #187

@chrisbobbe
Copy link
Collaborator Author

chrisbobbe commented Nov 9, 2023

Oh, hmm, the goldens are failing in CI. They're not failing when I run them on my machine though.

Maybe another reason that golden tests aren't worth the bother?

@gnprice
Copy link
Member

gnprice commented Nov 9, 2023

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! Just two comments below, apart from the tests — as discussed in that chat thread, we'll skip golden tests here.

I think it'll make sense to go fairly light on tests for this widget. The color calculation will be good for some unit tests; can pull it out as a @visibleForTesting static on the class. Probably none of the rest of the logic really makes sense to test, though. Could have a smoke test that just pumps one of these widgets to confirm nothing crashes.

Comment on lines 47 to 52
// TODO try LCH; see linked discussion
// TODO profiling for expensive computation
final asLab = LabColor.fromColor(baseStreamColor!);
backgroundColor = asLab
.copyWith(lightness: asLab.lightness.clamp(30, 70))
.toColor()
Copy link
Member

Choose a reason for hiding this comment

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

Cool, this sounds good for the present.

In the future if we discover this is a hot spot, we can either (a) find or write a more efficient implementation (as discussed in this chat thread, I think the amount of code needed for these isn't a lot; and I haven't looked closely but it may be that not much computation is needed either), or (b) if that's hard for some reason, memoize the results, perhaps on the Subscription objects.

super.key,
required this.count,
this.bold = false,
this.baseStreamColor,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
this.baseStreamColor,
required this.baseStreamColor,

I think it's not much of a burden for places like the recent-DMs list to explicitly pass null here; and making it explicit will help avoid forgetting to pass a stream color when there is a relevant stream.

@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! Small comments in the tests; otherwise all looks good.

Comment on lines 14 to 15
child: UnreadCountBadge(count: 1, baseStreamColor: null)),
);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
child: UnreadCountBadge(count: 1, baseStreamColor: null)),
);
child: UnreadCountBadge(count: 1, baseStreamColor: null)));
tester.widget(find.text("1"));

That just helps the reader not wonder if it's possible that one frame wasn't enough to fully show the widget. (Which only tends to come up in the presence of our GlobalStoreWidget and PerAccountStoreWidget; but we do use those a lot, so it comes to mind as something that can happen.)

Comment on lines +29 to +32
// TODO Fix bug causing our implementation's results to differ from the
// replit's. Where they differ, see comment with what the replit gives.
Copy link
Member

Choose a reason for hiding this comment

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

Cool. How did you extract the replit's results?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forked the replit (link to the replit) and added some code to run all the colors through getCounterBackgroundColor (since that's what gives the background color for the counters in the replit) and print the results to the console.

Copy link
Member

Choose a reason for hiding this comment

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

Cool. Is it easy to link to that forked replit?

That just seems like it'll be helpful whenever someone (be it you a few months in the future, or someone else) goes to try to resolve this TODO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately I deleted the fork. I couldn't easily figure out version control, and I didn't want to let my future self mix up which code was Vlad's vs. mine.

Copy link
Member

Choose a reason for hiding this comment

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

OK. I added a link to your previous reply, just in the interest of making the information we do have handy now remain handy when someone takes up this TODO.

runCheck(const Color(0xFFFFFF00), const Color(0x4dacb300)); // 0x4dacb200
runCheck(const Color(0xFFFF0000), const Color(0x4dff0000));
runCheck(const Color(0xFF008000), const Color(0x4d008000));
runCheck(const Color(0xFF0000FF), const Color(0x4d0000ff)); // 0x4d0902ff
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this difference of 0x00 vs 0x09 might be the biggest in any channel in any of these test cases, and all the others I spotted were a difference of 1 or 2. Is that right?

If it's almost always 1 or 2, that seems pretty mild, though it'd still ultimately be good to track down and resolve.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I skimmed through them just now, looking for any difference bigger than 0x09. I didn't find one.

Then I realized you also asked if all the rest just had differences of 1 or 2, and I wasn't keeping track of those…I think there were a few that had a difference of 3. Here's one with a difference of 3 and of 5:

runCheck(const Color(0xFF000080), const Color(0x4d492bae)); // 0x4d4b2eb3

@chrisbobbe
Copy link
Collaborator Author

Thanks for the review! Revision pushed.

…t/end

This doesn't seem likely to become asymmetrical, and perhaps we can
save a bit of computation with this.
@gnprice
Copy link
Member

gnprice commented Nov 15, 2023

Thanks! Merging, with just an added couple of comment lines per #371 (comment) above.

@gnprice gnprice merged commit 255fff3 into zulip:main Nov 15, 2023
1 check passed
@chrisbobbe chrisbobbe deleted the pr-unread-count-badge branch November 15, 2023 20:18
@chrisbobbe
Copy link
Collaborator Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants