@@ -22,6 +22,7 @@ class TestPage extends StatelessWidget {
2222 Widget build (BuildContext context) {
2323 return RequestLayoutConfigProvider (
2424 onLoading: (context) => const Text ('Loading...' ),
25+ onEmpty: (context) => const Text ('Empty!' ),
2526 onError: (context, error, onErrorCallback) => const Text ('Error!' ),
2627 child: MaterialApp (
2728 home: Scaffold (body: child),
@@ -45,6 +46,12 @@ void main() {
4546 (_) async => http.Response ('' , StatusCode .badRequest.value),
4647 );
4748
49+ when (
50+ () => client.get (Uri .parse ('2' )),
51+ ).thenAnswer (
52+ (_) async => http.Response ('' , StatusCode .ok.value),
53+ );
54+
4855 testWidgets (
4956 'shows default loading and error widget when no onLoading and onError provided' ,
5057 (tester) async {
@@ -67,6 +74,28 @@ void main() {
6774 expect (find.text ('Error!' ), findsOneWidget);
6875 });
6976
77+ testWidgets (
78+ 'shows default loading and empty widget when no onLoading and onEmpty provided' ,
79+ (tester) async {
80+ final queryCubit = TestArgsRequestCubit ('TestQueryCubit' , client: client);
81+
82+ await tester.pumpWidget (
83+ TestPage (
84+ child: RequestCubitBuilder (
85+ cubit: queryCubit,
86+ builder: (context, data) => Text (data),
87+ ),
88+ ),
89+ );
90+ await tester.pumpAndSettle ();
91+ expect (find.text ('Loading...' ), findsOneWidget);
92+ unawaited (queryCubit.run ('2' ));
93+ await tester.pump ();
94+ expect (find.text ('Loading...' ), findsOneWidget);
95+ await tester.pump ();
96+ expect (find.text ('Empty!' ), findsOneWidget);
97+ });
98+
7099 testWidgets ('shows custom loading and error widget when provided' ,
71100 (tester) async {
72101 final queryCubit = TestArgsRequestCubit ('TestQueryCubit' , client: client);
0 commit comments