Skip to content

Commit 840e52d

Browse files
chrisbobbegnprice
authored andcommitted
inbox: Fix bug where channel unread badge text color was slightly wrong
UnreadCountBadge has a needlessly loose API for specifying a background color, with three options: 1. Channel-colorized: callers are supposed to pass a ChannelColorSwatch and the implementation picks `unreadCountBadgeBackground` off of that. 2. Any other Color. (ChannelColorSwatch is a Color.) 3. A default color, chosen by the implementation, if `null` is passed. We don't actually have any use for option 2, at least currently, so we'll remove it next. The buggy caller here was using option 2 when it should have used option 1: it wanted a channel-colored background, but it itself picked `unreadCountBadgeBackground` off of the swatch instead of passing the whole swatch to UnreadCountBadge for it to do that. That would have been fine except that the channel-colorized case has its own associated *text* color, and that's conditioned on whether the passed background color is a ChannelColorSwatch.
1 parent 6adc9c3 commit 840e52d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/widgets/inbox.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class _StreamHeaderItem extends _HeaderItem with _LongPressable {
463463
@override Color uncollapsedBackgroundColor(context) =>
464464
colorSwatchFor(context, subscription).barBackground;
465465
@override Color? unreadCountBadgeBackgroundColor(context) =>
466-
colorSwatchFor(context, subscription).unreadCountBadgeBackground;
466+
colorSwatchFor(context, subscription);
467467

468468
@override Future<void> onCollapseButtonTap() async {
469469
await super.onCollapseButtonTap();

test/widgets/inbox_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:zulip/widgets/color.dart';
99
import 'package:zulip/widgets/home.dart';
1010
import 'package:zulip/widgets/icons.dart';
1111
import 'package:zulip/widgets/channel_colors.dart';
12+
import 'package:zulip/widgets/theme.dart';
1213
import 'package:zulip/widgets/unread_count_badge.dart';
1314

1415
import '../example_data.dart' as eg;
@@ -206,6 +207,28 @@ void main() {
206207
await setupVarious(tester);
207208
});
208209

210+
testWidgets('UnreadCountBadge text color for a channel', (tester) async {
211+
// Regression test for a bug where
212+
// DesignVariables.labelCounterUnread was used for the text instead of
213+
// DesignVariables.unreadCountBadgeTextForChannel.
214+
final channel = eg.stream();
215+
final subscription = eg.subscription(channel);
216+
await setupPage(tester,
217+
streams: [channel],
218+
subscriptions: [subscription],
219+
unreadMessages: generateStreamMessages(stream: channel, count: 1, flags: []));
220+
221+
final text = tester.widget<Text>(
222+
find.descendant(
223+
of: find.byWidget(findRowByLabel(tester, channel.name)!),
224+
matching: find.descendant(
225+
of: find.byType(UnreadCountBadge),
226+
matching: find.text('1'))));
227+
228+
final expectedTextColor = DesignVariables.light.unreadCountBadgeTextForChannel;
229+
check(text).style.isNotNull().color.isNotNull().isSameColorAs(expectedTextColor);
230+
});
231+
209232
// TODO test that tapping a conversation row opens the message list
210233
// for the conversation
211234

0 commit comments

Comments
 (0)