Skip to content

Commit 0a6b2f7

Browse files
chrisbobbegnprice
authored andcommitted
msglist test: Test all MessageTimestampStyles, not just dateOnlyRelative
1 parent 3703baa commit 0a6b2f7

File tree

1 file changed

+42
-22
lines changed

1 file changed

+42
-22
lines changed

test/widgets/message_list_test.dart

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,38 +1639,58 @@ void main() {
16391639
});
16401640

16411641
group('MessageTimestampStyle', () {
1642-
group('dateOnlyRelative', () {
1643-
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
1644-
final now = DateTime.parse("2023-01-10 12:00");
1645-
final testCases = [
1646-
("2023-01-10 12:00", zulipLocalizations.today),
1647-
("2023-01-10 00:00", zulipLocalizations.today),
1648-
("2023-01-10 23:59", zulipLocalizations.today),
1649-
("2023-01-09 23:59", zulipLocalizations.yesterday),
1650-
("2023-01-09 00:00", zulipLocalizations.yesterday),
1651-
("2023-01-08 00:00", "Jan 8"),
1652-
("2022-12-31 00:00", "Dec 31, 2022"),
1653-
// Future times
1654-
("2023-01-10 19:00", zulipLocalizations.today),
1655-
("2023-01-11 00:00", "Jan 11, 2023"),
1656-
];
1657-
for (final (dateTime, expected) in testCases) {
1658-
test('$dateTime returns $expected', () {
1642+
void doTests(
1643+
MessageTimestampStyle style,
1644+
List<(String timestampStr, String? expected)> cases, {
1645+
DateTime? now,
1646+
}) {
1647+
now ??= DateTime.parse("2023-01-10 12:00");
1648+
for (final (timestampStr, expected) in cases) {
1649+
test('${style.name}: $timestampStr returns $expected', () {
16591650
addTearDown(testBinding.reset);
1651+
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
16601652

1661-
withClock(Clock.fixed(now), () {
1662-
final timestamp = DateTime.parse(dateTime).millisecondsSinceEpoch ~/ 1000;
1663-
final result = MessageTimestampStyle.dateOnlyRelative.format(
1653+
withClock(Clock.fixed(now!), () {
1654+
final timestamp = DateTime.parse(timestampStr)
1655+
.millisecondsSinceEpoch ~/ 1000;
1656+
final result = style.format(
16641657
timestamp,
16651658
now: testBinding.utcNow().toLocal(),
16661659
zulipLocalizations: zulipLocalizations);
16671660
check(result).equals(expected);
16681661
});
16691662
});
16701663
}
1671-
});
1664+
}
16721665

1673-
// TODO others
1666+
for (final style in MessageTimestampStyle.values) {
1667+
switch (style) {
1668+
case MessageTimestampStyle.none:
1669+
doTests(style, [('2023-01-10 12:00', null)]);
1670+
case MessageTimestampStyle.dateOnlyRelative:
1671+
final zulipLocalizations = GlobalLocalizations.zulipLocalizations;
1672+
doTests(style,
1673+
now: DateTime.parse("2023-01-10 12:00"),
1674+
[
1675+
("2023-01-10 12:00", zulipLocalizations.today),
1676+
("2023-01-10 00:00", zulipLocalizations.today),
1677+
("2023-01-10 23:59", zulipLocalizations.today),
1678+
("2023-01-09 23:59", zulipLocalizations.yesterday),
1679+
("2023-01-09 00:00", zulipLocalizations.yesterday),
1680+
("2023-01-08 00:00", "Jan 8"),
1681+
("2022-12-31 00:00", "Dec 31, 2022"),
1682+
// Future times
1683+
("2023-01-10 19:00", zulipLocalizations.today),
1684+
("2023-01-11 00:00", "Jan 11, 2023"),
1685+
]);
1686+
case MessageTimestampStyle.timeOnly:
1687+
doTests(style, [('2023-01-10 12:00', '12:00 PM')]);
1688+
case MessageTimestampStyle.lightbox:
1689+
doTests(style, [('2023-01-10 12:00', 'Jan 10, 2023 12:00:00')]);
1690+
case MessageTimestampStyle.full:
1691+
doTests(style, [('2023-01-10 12:00', 'Jan 10, 2023 12:00 PM')]);
1692+
}
1693+
}
16741694
});
16751695

16761696
group('MessageWithPossibleSender', () {

0 commit comments

Comments
 (0)