Skip to content

Commit 1560337

Browse files
Khader-1gnprice
authored andcommitted
subscription_list test [nfc]: Split subscriptions sort test case
Subscription sort is testing too many things: * Pinned subscriptions are coming before unpinned ones * Pinned subscriptions are alphabetically ordered * Unpinned subscriptions are alphabetically ordered So what this commit does is splitting these test cases up. Additionally some refactors are applied: * Factor out 'checkListedStreamIdsEqual' for more concise cases * Remove unrelated checks from the test case
1 parent 1788ae5 commit 1560337

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

test/widgets/subscription_list_test.dart

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,37 @@ void main() {
8989
check(isUnpinnedHeaderInTree()).isTrue();
9090
});
9191

92-
testWidgets('subscription sort', (tester) async {
93-
await setupStreamListPage(tester, subscriptions: [
94-
eg.subscription(eg.stream(streamId: 1, name: 'd'), pinToTop: true),
95-
eg.subscription(eg.stream(streamId: 2, name: 'c'), pinToTop: false),
96-
eg.subscription(eg.stream(streamId: 3, name: 'b'), pinToTop: true),
97-
eg.subscription(eg.stream(streamId: 4, name: 'a'), pinToTop: false),
98-
]);
99-
check(isPinnedHeaderInTree()).isTrue();
100-
check(isUnpinnedHeaderInTree()).isTrue();
101-
102-
final streamListItems = tester.widgetList<SubscriptionItem>(find.byType(SubscriptionItem)).toList();
103-
check(streamListItems.map((e) => e.subscription.streamId)).deepEquals([3, 1, 4, 2]);
92+
group('subscription sorting', () {
93+
Iterable<int> listedStreamIds(WidgetTester tester) => tester
94+
.widgetList<SubscriptionItem>(find.byType(SubscriptionItem))
95+
.map((e) => e.subscription.streamId);
96+
97+
testWidgets('pinned are shown on the top', (tester) async {
98+
await setupStreamListPage(tester, subscriptions: [
99+
eg.subscription(eg.stream(streamId: 1, name: 'a'), pinToTop: false),
100+
eg.subscription(eg.stream(streamId: 2, name: 'b'), pinToTop: true),
101+
eg.subscription(eg.stream(streamId: 3, name: 'c'), pinToTop: false),
102+
]);
103+
check(listedStreamIds(tester)).deepEquals([2, 1, 3]);
104+
});
105+
106+
testWidgets('pinned subscriptions are sorted', (tester) async {
107+
await setupStreamListPage(tester, subscriptions: [
108+
eg.subscription(eg.stream(streamId: 3, name: 'b'), pinToTop: true),
109+
eg.subscription(eg.stream(streamId: 1, name: 'c'), pinToTop: true),
110+
eg.subscription(eg.stream(streamId: 2, name: 'a'), pinToTop: true),
111+
]);
112+
check(listedStreamIds(tester)).deepEquals([2, 3, 1]);
113+
});
114+
115+
testWidgets('unpinned subscriptions are sorted', (tester) async {
116+
await setupStreamListPage(tester, subscriptions: [
117+
eg.subscription(eg.stream(streamId: 3, name: 'b'), pinToTop: false),
118+
eg.subscription(eg.stream(streamId: 1, name: 'c'), pinToTop: false),
119+
eg.subscription(eg.stream(streamId: 2, name: 'a'), pinToTop: false),
120+
]);
121+
check(listedStreamIds(tester)).deepEquals([2, 3, 1]);
122+
});
104123
});
105124

106125
testWidgets('unread badge shows with unreads', (tester) async {

0 commit comments

Comments
 (0)