Skip to content

Commit a2e5066

Browse files
committed
test: improve auto-scroll test to verify that only one page is advanced at a time
1 parent 1a1331f commit a2e5066

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

test/src/introduction_screen_test.dart

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,24 +195,40 @@ void main() {
195195
});
196196
});
197197

198-
testWidgets('Auto-scroll works as expected', (WidgetTester tester) async {
198+
testWidgets('Auto-scroll advances one page at a time',
199+
(WidgetTester tester) async {
199200
// Arrange
200-
final pages = [
201-
PageViewModel(title: 'Page 1', body: 'Introduction 1'),
202-
PageViewModel(title: 'Page 2', body: 'Introduction 2'),
203-
];
204-
205-
await tester.pumpWidget(
206-
createIntroductionScreen(pages: pages, autoScrollDuration: 5));
201+
const autoScrollDuration = 2000;
202+
await tester.pumpWidget(createIntroductionScreen(
203+
pages: [
204+
PageViewModel(title: 'Page 1', body: 'Introduction 1'),
205+
PageViewModel(title: 'Page 2', body: 'Introduction 2'),
206+
PageViewModel(title: 'Page 3', body: 'Introduction 3'),
207+
],
208+
autoScrollDuration: autoScrollDuration,
209+
));
207210

208-
// Initial page should be Page 1
211+
// Should still be at page 1 after 100 ms
212+
await tester.pump(Duration(milliseconds: 100));
213+
await tester.pumpAndSettle();
209214
expect(find.text('Page 1'), findsOneWidget);
215+
expect(find.text('Page 2'), findsNothing);
216+
expect(find.text('Page 3'), findsNothing);
210217

211-
// Simulate time passing to trigger auto-scroll
212-
await tester.pump(const Duration(milliseconds: 10));
218+
// Wait for first auto-scroll, should be on page 2 now
219+
await tester.pump(Duration(milliseconds: autoScrollDuration + 100));
213220
await tester.pumpAndSettle();
214221

215-
// The auto-scroll should have moved to the next page
222+
expect(find.text('Page 1'), findsNothing);
216223
expect(find.text('Page 2'), findsOneWidget);
224+
expect(find.text('Page 3'), findsNothing);
225+
226+
// Wait for second auto-scroll, should be on page 3 now
227+
await tester.pump(Duration(milliseconds: autoScrollDuration));
228+
await tester.pumpAndSettle();
229+
230+
expect(find.text('Page 1'), findsNothing);
231+
expect(find.text('Page 2'), findsNothing);
232+
expect(find.text('Page 3'), findsOneWidget);
217233
});
218234
}

0 commit comments

Comments
 (0)