forked from eatvio/eatvio_app
90 lines
3.3 KiB
Dart
90 lines
3.3 KiB
Dart
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/settings/presentation/bloc/settings_cubit/settings_cubit.dart';
|
|
import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart';
|
|
import 'package:eatvio_app/features/settings/presentation/pages/settings_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:go_router/go_router.dart';
|
|
import 'package:mockito/annotations.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
import 'settings_screen_test.mocks.dart';
|
|
|
|
@GenerateNiceMocks([MockSpec<SettingsCubit>()])
|
|
void main() {
|
|
group('SettingsScreen 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'));
|
|
});
|
|
|
|
tearDown(() async {
|
|
await sl.reset();
|
|
});
|
|
|
|
|
|
Widget wrap(Widget child) {
|
|
return MaterialApp.router(
|
|
theme: ThemeHelper().themeData(),
|
|
localizationsDelegates: const [
|
|
S.delegate,
|
|
GlobalMaterialLocalizations.delegate,
|
|
GlobalWidgetsLocalizations.delegate,
|
|
GlobalCupertinoLocalizations.delegate,
|
|
],
|
|
supportedLocales: const [Locale('ru')],
|
|
routerConfig: GoRouter(
|
|
initialLocation: '/',
|
|
routes: [GoRoute(path: '/', builder: (context, state) => child)],
|
|
),
|
|
);
|
|
}
|
|
|
|
testWidgets('renders settings screen - loading state', (tester) async {
|
|
final cubit = MockSettingsCubit();
|
|
const loadingState = SettingsState.loading();
|
|
|
|
when(cubit.state).thenReturn(loadingState);
|
|
when(cubit.stream).thenAnswer((_) => Stream.value(loadingState));
|
|
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
|
when(cubit.init()).thenAnswer((_) async => Future<void>.value());
|
|
|
|
sl.registerLazySingleton<SettingsCubit>(() => cubit);
|
|
|
|
await tester.pumpWidget(wrap(const SettingsScreen()));
|
|
await tester.pump();
|
|
|
|
expect(find.byType(SettingsScreen), findsOneWidget);
|
|
expect(find.text('Настройки'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('renders settings screen - error state', (tester) async {
|
|
final cubit = MockSettingsCubit();
|
|
const errorState = SettingsState.error(errorMessage: 'Test error');
|
|
|
|
when(cubit.state).thenReturn(errorState);
|
|
when(cubit.stream).thenAnswer((_) => Stream.value(errorState));
|
|
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
|
|
when(cubit.init()).thenAnswer((_) async => Future<void>.value());
|
|
|
|
sl.registerLazySingleton<SettingsCubit>(() => cubit);
|
|
|
|
await tester.pumpWidget(wrap(const SettingsScreen()));
|
|
await tester.pump();
|
|
|
|
expect(find.byType(SettingsScreen), findsOneWidget);
|
|
expect(find.text('Настройки'), findsOneWidget);
|
|
});
|
|
});
|
|
}
|