|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_bloc/flutter_bloc.dart'; |
| 3 | +import 'package:flutter_bloc_advance/configuration/environment.dart'; |
| 4 | +import 'package:flutter_bloc_advance/data/repository/account_repository.dart'; |
| 5 | +import 'package:flutter_bloc_advance/data/repository/authorities_repository.dart'; |
| 6 | +import 'package:flutter_bloc_advance/data/repository/city_repository.dart'; |
| 7 | +import 'package:flutter_bloc_advance/data/repository/district_repository.dart'; |
| 8 | +import 'package:flutter_bloc_advance/data/repository/login_repository.dart'; |
| 9 | +import 'package:flutter_bloc_advance/data/repository/menu_repository.dart'; |
| 10 | +import 'package:flutter_bloc_advance/data/repository/user_repository.dart'; |
| 11 | +import 'package:flutter_bloc_advance/generated/l10n.dart'; |
| 12 | +import 'package:flutter_bloc_advance/presentation/common_blocs/account/account.dart'; |
| 13 | +import 'package:flutter_bloc_advance/presentation/common_blocs/authorities/authorities_bloc.dart'; |
| 14 | +import 'package:flutter_bloc_advance/presentation/common_blocs/city/city.dart'; |
| 15 | +import 'package:flutter_bloc_advance/presentation/common_blocs/district/district.dart'; |
| 16 | +import 'package:flutter_bloc_advance/presentation/common_widgets/drawer/drawer_bloc/drawer.dart'; |
| 17 | +import 'package:flutter_bloc_advance/presentation/screen/user/bloc/user.dart'; |
| 18 | +import 'package:flutter_bloc_advance/presentation/screen/user/list/list_user_screen.dart'; |
| 19 | +import 'package:flutter_form_builder/flutter_form_builder.dart'; |
| 20 | +import 'package:flutter_localizations/flutter_localizations.dart'; |
| 21 | +import 'package:flutter_test/flutter_test.dart'; |
| 22 | +import 'package:get/get.dart'; |
| 23 | + |
| 24 | +import '../../../init.dart'; |
| 25 | + |
| 26 | +/// List User Screen Test |
| 27 | +/// class ListUserScreen extends StatelessWidget |
| 28 | +void main() { |
| 29 | + setUpAll(() { |
| 30 | + // Set the environment to test for working with mock-json data on the API |
| 31 | + initBlocDependencies(); |
| 32 | + }); |
| 33 | + |
| 34 | + final blocs = [ |
| 35 | + BlocProvider<AuthoritiesBloc>(create: (_) => AuthoritiesBloc(authoritiesRepository: AuthoritiesRepository())), |
| 36 | + BlocProvider<AccountBloc>(create: (_) => AccountBloc(accountRepository: AccountRepository())), |
| 37 | + BlocProvider<UserBloc>(create: (_) => UserBloc(userRepository: UserRepository())), |
| 38 | + BlocProvider<CityBloc>(create: (_) => CityBloc(cityRepository: CityRepository())), |
| 39 | + BlocProvider<DistrictBloc>(create: (_) => DistrictBloc(districtRepository: DistrictRepository())), |
| 40 | + BlocProvider<DrawerBloc>(create: (_) => DrawerBloc(loginRepository: LoginRepository(), menuRepository: MenuRepository())), |
| 41 | + ]; |
| 42 | + |
| 43 | + GetMaterialApp getWidget() { |
| 44 | + return GetMaterialApp( |
| 45 | + home: MultiBlocProvider( |
| 46 | + providers: blocs, |
| 47 | + child: ListUserScreen(), |
| 48 | + ), |
| 49 | + localizationsDelegates: const [ |
| 50 | + S.delegate, |
| 51 | + GlobalMaterialLocalizations.delegate, |
| 52 | + GlobalWidgetsLocalizations.delegate, |
| 53 | + GlobalCupertinoLocalizations.delegate, |
| 54 | + ], |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + testWidgets('renders ListUserScreen correctly', (tester) async { |
| 59 | + // Given: A ListUserScreen with mocked state is rendered |
| 60 | + await tester.pumpWidget(getWidget()); |
| 61 | + |
| 62 | + // When: The screen is loaded |
| 63 | + await tester.pumpAndSettle(); |
| 64 | + |
| 65 | + //Then: Check if the AppBar contains the correct title |
| 66 | + |
| 67 | + // Then: Check if the search form elements are present |
| 68 | + expect(find.byType(FormBuilderTextField), findsNWidgets(3)); |
| 69 | + expect(find.byType(ElevatedButton), findsOneWidget); |
| 70 | + expect(find.text('List'), findsOneWidget); |
| 71 | + |
| 72 | + // Then: Check if the table header is rendered |
| 73 | + expect(find.text('Role'), findsOneWidget); |
| 74 | + expect(find.text('Login'), findsOneWidget); |
| 75 | + expect(find.text('First Name'), findsOneWidget); |
| 76 | + expect(find.text('Last Name'), findsOneWidget); |
| 77 | + expect(find.text('Email'), findsOneWidget); |
| 78 | + expect(find.text('Phone Number'), findsOneWidget); |
| 79 | + expect(find.text('Active'), findsOneWidget); |
| 80 | + }); |
| 81 | + |
| 82 | + // testWidgets('FormBuilderDropdown is displayed when state is AuthoritiesLoadSuccessState', (WidgetTester tester) async { |
| 83 | + // final mockAuthoritiesBloc = MockAuthoritiesBloc(); |
| 84 | + // |
| 85 | + // whenListen( |
| 86 | + // mockAuthoritiesBloc, |
| 87 | + // Stream.fromIterable([AuthoritiesLoadSuccessState(roleList: ['ROLE_USER', 'ROLE_ADMIN'])]), |
| 88 | + // initialState: AuthoritiesInitial(), |
| 89 | + // ); |
| 90 | + // |
| 91 | + // await tester.pumpWidget( |
| 92 | + // MaterialApp( |
| 93 | + // home: BlocProvider<AuthoritiesBloc>( |
| 94 | + // create: (context) => mockAuthoritiesBloc, |
| 95 | + // child: ListUserScreen(), |
| 96 | + // ), |
| 97 | + // ), |
| 98 | + // ); |
| 99 | + // |
| 100 | + // await tester.pumpAndSettle(); |
| 101 | + // |
| 102 | + // expect(find.byType(FormBuilderDropdown), findsOneWidget); |
| 103 | + // }); |
| 104 | + |
| 105 | + |
| 106 | +} |
0 commit comments