Skip to content

Commit 1a1331f

Browse files
committed
test: add back button test
1 parent 94db706 commit 1a1331f

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

test/src/introduction_screen_test.dart

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:dots_indicator/dots_indicator.dart';
2-
import 'package:flutter_test/flutter_test.dart';
32
import 'package:flutter/material.dart';
3+
import 'package:flutter_test/flutter_test.dart';
44
import 'package:introduction_screen/introduction_screen.dart';
55

66
void main() {
@@ -12,6 +12,8 @@ void main() {
1212
bool showSkipButton = false,
1313
bool showDoneButton = false,
1414
bool showNextButton = true,
15+
bool showBackButton = false,
16+
int initialPage = 0,
1517
int? autoScrollDuration,
1618
}) {
1719
return MaterialApp(
@@ -24,8 +26,11 @@ void main() {
2426
next: showNextButton ? Text("Next") : null,
2527
showSkipButton: showSkipButton,
2628
showDoneButton: showDoneButton,
29+
showBackButton: showBackButton,
30+
back: showBackButton ? Text("Back") : null,
2731
showNextButton: showNextButton,
2832
autoScrollDuration: autoScrollDuration,
33+
initialPage: initialPage,
2934
),
3035
);
3136
}
@@ -64,6 +69,29 @@ void main() {
6469
expect(find.text('Page 2'), findsOneWidget);
6570
});
6671

72+
testWidgets('Back button goes back to the previous page', (tester) async {
73+
// Arrange
74+
await tester.pumpWidget(createIntroductionScreen(
75+
pages: [
76+
PageViewModel(title: 'Page 1', body: 'Introduction 1'),
77+
PageViewModel(title: 'Page 2', body: 'Introduction 2'),
78+
],
79+
showBackButton: true,
80+
initialPage: 1,
81+
));
82+
83+
expect(find.text('Page 1'), findsNothing);
84+
expect(find.text('Page 2'), findsOneWidget);
85+
86+
// Act
87+
await tester.tap(find.text('Back'));
88+
await tester.pumpAndSettle();
89+
90+
// Assert
91+
expect(find.text('Page 1'), findsOneWidget);
92+
expect(find.text('Page 2'), findsNothing);
93+
});
94+
6795
testWidgets('Skip button triggers onSkip callback', (tester) async {
6896
// Arrange
6997
var skipTapped = false;

0 commit comments

Comments
 (0)