From d72a0a676a8e8149e1db05210760f8a5e13446bb Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Tue, 6 Feb 2024 19:33:55 +0000 Subject: [PATCH] inbox test [nfc]: Pull out findRowByLabel This will be used later to match other types of rows. --- test/widgets/inbox_test.dart | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/test/widgets/inbox_test.dart b/test/widgets/inbox_test.dart index 46e15f9e3e7..e2579a43eec 100644 --- a/test/widgets/inbox_test.dart +++ b/test/widgets/inbox_test.dart @@ -70,14 +70,10 @@ void main() { ]); } - /// Find an all-DMs header element. - // Why "an" all-DMs header element? Because there might be two: one that - // floats at the top of the screen to give the "sticky header" effect, and one - // that scrolls normally, the way it would in a regular [ListView]. - // TODO we'll need to find both and run checks on them, knowing which is which. - Widget? findAllDmsHeaderRow(WidgetTester tester) { + /// Find a row with the given label. + Widget? findRowByLabel(WidgetTester tester, String label) { final rowLabel = tester.widgetList( - find.text('Direct messages'), + find.text(label), ).firstOrNull; if (rowLabel == null) { return null; @@ -89,6 +85,15 @@ void main() { matching: find.byType(Row))); } + /// Find an all-DMs header element. + // Why "an" all-DMs header element? Because there might be two: one that + // floats at the top of the screen to give the "sticky header" effect, and one + // that scrolls normally, the way it would in a regular [ListView]. + // TODO we'll need to find both and run checks on them, knowing which is which. + Widget? findAllDmsHeaderRow(WidgetTester tester) { + return findRowByLabel(tester, 'Direct messages'); + } + /// For the given stream ID, find a stream header element. // Why "an" all-DMs header element? Because there might be two: one that // floats at the top of the screen to give the "sticky header" effect, and one @@ -96,15 +101,7 @@ void main() { // TODO we'll need to find both and run checks on them, knowing which is which. Widget? findStreamHeaderRow(WidgetTester tester, int streamId) { final stream = store.streams[streamId]!; - final rowLabel = tester.widgetList(find.text(stream.name)).firstOrNull; - if (rowLabel == null) { - return null; - } - - return tester.widget( - find.ancestor( - of: find.byWidget(rowLabel), - matching: find.byType(Row))); + return findRowByLabel(tester, stream.name); } IconData expectedStreamHeaderIcon(int streamId) {