Skip to content

Commit

Permalink
channel_list: Sort channels alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
Khader-1 committed Jul 27, 2024
1 parent 6f4e7b3 commit e4fecd9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/widgets/channel_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class _ChannelListPageState extends State<ChannelListPage> with PerAccountStoreA
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final zulipLocalizations = ZulipLocalizations.of(context);
final streams = store.streams.values.toList();
final streams = store.streams.values.toList()..sort((a, b) {
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
});
return Scaffold(
appBar: AppBar(title: Text(zulipLocalizations.channelListPageTitle)),
body: SafeArea(
Expand Down
25 changes: 25 additions & 0 deletions test/widgets/channel_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,29 @@ void main() {
await setupChannelListPage(tester, streams: streams, subscriptions: []);
check(getItemCount()).equals(3);
});

group('list ordering', () {
Iterable<String> listedStreamNames(WidgetTester tester) => tester
.widgetList<ChannelItem>(find.byType(ChannelItem))
.map((e) => e.stream.name);

List<ZulipStream> streamsFromNames(List<String> names) {
return names.map((name) => eg.stream(name: name)).toList();
}

testWidgets('is alphabetically case-insensitive', (tester) async {
final streams = streamsFromNames(['b', 'C', 'A']);
await setupChannelListPage(tester, streams: streams, subscriptions: []);

check(listedStreamNames(tester)).deepEquals(['A', 'b', 'C']);
});

testWidgets('is insensitive of user subscription', (tester) async {
final streams = streamsFromNames(['b', 'c', 'a']);
await setupChannelListPage(tester, streams: streams,
subscriptions: [eg.subscription(streams[0])]);

check(listedStreamNames(tester)).deepEquals(['a', 'b', 'c']);
});
});
}

0 comments on commit e4fecd9

Please sign in to comment.