forked from eatvio/eatvio_app
feat(tests): test coverage 60%
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/auth_cubit/auth_cubit.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/auth_cubit/auth_state.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/pages/auth_screen.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'auth_screen_smoke_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<AuthCubit>()])
|
||||
void main() {
|
||||
group('AuthScreen smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: child,
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders base auth UI', (tester) async {
|
||||
final cubit = MockAuthCubit();
|
||||
when(cubit.state).thenReturn(const AuthState());
|
||||
when(cubit.stream).thenAnswer((_) => const Stream<AuthState>.empty());
|
||||
when(cubit.close()).thenAnswer((_) async {});
|
||||
sl.registerFactory<AuthCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const AuthScreen()));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(AuthScreen), findsOneWidget);
|
||||
// Minimal/stable assertions.
|
||||
expect(find.text(S.current.authentificate), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/reset_password_cubit/reset_password_cubit.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/reset_password_cubit/reset_password_state.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/pages/forget_password_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'forget_password_screen_smoke_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ResetPasswordCubit>()])
|
||||
void main() {
|
||||
group('ForgetPasswordScreen smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(theme: ThemeHelper().themeData(), home: child);
|
||||
}
|
||||
|
||||
testWidgets('renders initial email step (isAuth=false)', (tester) async {
|
||||
final cubit = MockResetPasswordCubit();
|
||||
when(cubit.state).thenReturn(const ResetPasswordState.empty());
|
||||
when(cubit.stream).thenAnswer((_) => const Stream<ResetPasswordState>.empty());
|
||||
when(cubit.close()).thenAnswer((_) async {});
|
||||
sl.registerFactory<ResetPasswordCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const ForgetPasswordScreen(isAuth: false)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(ForgetPasswordScreen), findsOneWidget);
|
||||
expect(find.text('Восстановление пароля'), findsOneWidget);
|
||||
expect(find.text('E-mail'), findsOneWidget);
|
||||
expect(find.text('Сбросить пароль'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('renders code + new password step', (tester) async {
|
||||
final cubit = MockResetPasswordCubit();
|
||||
when(cubit.state).thenReturn(const ResetPasswordState.codeSendSuccess());
|
||||
when(cubit.stream).thenAnswer((_) => const Stream<ResetPasswordState>.empty());
|
||||
when(cubit.close()).thenAnswer((_) async {});
|
||||
sl.registerFactory<ResetPasswordCubit>(() => cubit);
|
||||
|
||||
await tester.pumpWidget(wrap(const ForgetPasswordScreen(isAuth: true)));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Смена пароля'), findsOneWidget);
|
||||
expect(find.text('Код'), findsOneWidget);
|
||||
expect(find.text('Пароль'), findsOneWidget);
|
||||
expect(find.text('Подтвердите пароль'), findsOneWidget);
|
||||
expect(find.text('Сменить пароль'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'package:eatvio_app/core/app_config.dart';
|
||||
import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/di/cubit_registrations.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/auth/entities/auth_result_entity.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/oauth_cubit/oauth_cubit.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/bloc/oauth_cubit/oauth_state.dart';
|
||||
import 'package:eatvio_app/features/auth/presentation/pages/register_via_social_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'register_via_social_screen_smoke_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<OAuthCubit>()])
|
||||
void main() {
|
||||
group('RegisterViaSocialScreen smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
});
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
|
||||
await CubitRegistrations.sl.reset();
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
Widget wrap(Widget child) {
|
||||
return MaterialApp(theme: ThemeHelper().themeData(), home: child);
|
||||
}
|
||||
|
||||
testWidgets('renders and pre-fills fields from AuthResultEntity', (tester) async {
|
||||
final cubit = MockOAuthCubit();
|
||||
when(cubit.state).thenReturn(const OAuthState());
|
||||
when(cubit.stream).thenAnswer((_) => const Stream<OAuthState>.empty());
|
||||
when(cubit.close()).thenAnswer((_) async {});
|
||||
CubitRegistrations.sl.registerFactory<OAuthCubit>(() => cubit);
|
||||
|
||||
const authResult = AuthResultEntity(
|
||||
accessToken: 'token',
|
||||
userId: '1',
|
||||
clientId: 'client',
|
||||
refreshToken: 'refresh',
|
||||
firstName: 'Ivan',
|
||||
lastName: 'Petrov',
|
||||
email: 'ivan@example.com',
|
||||
phone: '+7 (999) 111 22 33',
|
||||
birthDate: '1990-01-01',
|
||||
gender: GenderEnum.male,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(wrap(const RegisterViaSocialScreen(authResult: authResult, provider: 'vk')));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(RegisterViaSocialScreen), findsOneWidget);
|
||||
expect(find.text('Регистрация'), findsOneWidget);
|
||||
expect(find.text('Ivan'), findsOneWidget);
|
||||
expect(find.text('Petrov'), findsOneWidget);
|
||||
expect(find.text('ivan@example.com'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user