Skip to content

Commit 0af5bb1

Browse files
committed
msglist: Change how tests for ScrollToBottomButton tests for functionality
Switched from checking the ValueNotifier value to looking for the existence of the tooltip in the visible button.
1 parent 9b7418f commit 0af5bb1

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

test/widgets/message_list_test.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,46 +59,50 @@ void main() {
5959
return stickyHeaderListView.controller;
6060
}
6161

62-
ScrollToBottomButton? findScrollToBottomButton(WidgetTester tester) {
63-
return tester.widget<ScrollToBottomButton>(find.byType(ScrollToBottomButton));
62+
bool isButtonVisible(WidgetTester tester) {
63+
return tester.any(find.descendant(
64+
of: find.byType(ScrollToBottomButton),
65+
matching: find.byTooltip("Scroll to bottom")));
6466
}
6567

6668
testWidgets('scrolling changes visibility', (WidgetTester tester) async {
6769
final stream = eg.stream();
6870
await setupMessageListPage(tester, narrow: StreamNarrow(stream.streamId));
6971

7072
final scrollController = findMessageListScrollController(tester)!;
71-
final scrollToBottomButton = findScrollToBottomButton(tester)!;
7273

7374
// Initial state should be not visible, as the message list renders with latest message in view
74-
check(scrollToBottomButton.visibleValue.value).equals(false);
75+
check(isButtonVisible(tester)).equals(false);
7576

7677
scrollController.jumpTo(600);
7778
await tester.pump();
78-
check(scrollToBottomButton.visibleValue.value).equals(true);
79+
check(isButtonVisible(tester)).equals(true);
7980

8081
scrollController.jumpTo(0);
8182
await tester.pump();
82-
check(scrollToBottomButton.visibleValue.value).equals(false);
83+
check(isButtonVisible(tester)).equals(false);
8384
});
8485

8586
testWidgets('dimension updates changes visibility', (WidgetTester tester) async {
8687
final stream = eg.stream();
8788
await setupMessageListPage(tester, narrow: StreamNarrow(stream.streamId));
8889

8990
final scrollController = findMessageListScrollController(tester)!;
90-
final scrollToBottomButton = findScrollToBottomButton(tester)!;
9191

9292
// Initial state should be not visible, as the message list renders with latest message in view
93-
check(scrollToBottomButton.visibleValue.value).equals(false);
93+
check(isButtonVisible(tester)).equals(false);
9494

9595
scrollController.jumpTo(600);
9696
await tester.pump();
97-
check(scrollToBottomButton.visibleValue.value).equals(true);
97+
check(isButtonVisible(tester)).equals(true);
9898

9999
tester.view.physicalSize = const Size(2000, 40000);
100100
await tester.pump();
101-
check(scrollToBottomButton.visibleValue.value).equals(false);
101+
// Dimension changes use NotificationListener<ScrollMetricsNotification
102+
// which has a one frame lag. If that ever gets resolved this extra pump
103+
// would ideally be removed
104+
await tester.pump();
105+
check(isButtonVisible(tester)).equals(false);
102106
});
103107
});
104-
}
108+
}

0 commit comments

Comments
 (0)