-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen_loading_handler_test.dart
More file actions
123 lines (102 loc) · 4.07 KB
/
screen_loading_handler_test.dart
File metadata and controls
123 lines (102 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:screen_loading_handler/screen_loading_controller.dart'; // Adjust the import according to your project structure
import 'package:screen_loading_handler/screen_loading_handler.dart';
void main() {
group('ScreenLoadingHandler', () {
late ScreenLoadingController controller;
// Set up the controller before each test
setUp(() {
controller = ScreenLoadingController();
});
testWidgets('should show loading indicator when isLoading is true',
(WidgetTester tester) async {
// Build the widget tree with ScreenLoadingHandler
await tester.pumpWidget(
MaterialApp(
home: ScreenLoadingHandler(
controller: controller,
child: const SizedBox.shrink(), // Empty child for testing purposes
),
),
);
// Initially, the loading indicator should not be visible
expect(find.byType(CircularProgressIndicator), findsNothing);
// Start loading by calling startLoading
controller.startLoading();
await tester.pump(); // Rebuild the widget tree
// The loading indicator should now be visible
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
testWidgets('should hide loading indicator when isLoading is false',
(WidgetTester tester) async {
// Build the widget tree with ScreenLoadingHandler
await tester.pumpWidget(
MaterialApp(
home: ScreenLoadingHandler(
controller: controller,
child: const SizedBox.shrink(),
),
),
);
// Start loading to show the indicator
controller.startLoading();
await tester.pump();
// Ensure the loading indicator is visible
expect(find.byType(CircularProgressIndicator), findsOneWidget);
// Stop loading and ensure the indicator is hidden
controller.stopLoading();
await tester.pump();
// The loading indicator should be hidden now
expect(find.byType(CircularProgressIndicator), findsNothing);
});
testWidgets(
'should close loading indicator when tapped if closeOnTap is true',
(WidgetTester tester) async {
// Build the widget tree with ScreenLoadingHandler and closeOnTap set to true
await tester.pumpWidget(
MaterialApp(
home: ScreenLoadingHandler(
controller: controller,
closeOnTap: true,
child: const SizedBox.shrink(),
),
),
);
// Start loading to show the indicator
controller.startLoading();
await tester.pump();
// Ensure the loading indicator is visible
expect(find.byType(CircularProgressIndicator), findsOneWidget);
// Tap on the loading overlay to close the indicator
await tester.tap(find.byType(GestureDetector));
await tester.pump(); // Rebuild the widget tree
// The loading indicator should be hidden after tap
expect(find.byType(CircularProgressIndicator), findsNothing);
});
testWidgets(
'should not close loading indicator when tapped if closeOnTap is false',
(WidgetTester tester) async {
// Build the widget tree with ScreenLoadingHandler and closeOnTap set to false
await tester.pumpWidget(
MaterialApp(
home: ScreenLoadingHandler(
controller: controller,
closeOnTap: false,
child: const SizedBox.shrink(),
),
),
);
// Start loading to show the indicator
controller.startLoading();
await tester.pump();
// Ensure the loading indicator is visible
expect(find.byType(CircularProgressIndicator), findsOneWidget);
// Tap on the loading overlay (but the loading indicator should not close)
await tester.tap(find.byType(GestureDetector));
await tester.pump(); // Rebuild the widget tree
// The loading indicator should still be visible because closeOnTap is false
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
});
}