Files
eatvio_app/test/features/glossary/presentation/pages/glossary_screen_test.dart

141 lines
4.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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/widgets/loader.dart';
import 'package:eatvio_app/features/glossary/presentation/pages/glossary_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import '../../../../helpers/webview_test_helper.dart';
void main() {
group('GlossaryScreen', () {
setUp(() async {
WebViewTestHelper.setUpWebViewPlatform();
await sl.reset();
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
});
tearDown(() {
WebViewTestHelper.tearDownWebViewPlatform();
});
testWidgets('отображает GlossaryScreen с WebView и AppBar', (WidgetTester tester) async {
const passKey = 'test-pass-key';
final router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) => const GlossaryScreen(passKey: passKey),
),
],
);
await tester.pumpWidget(
MaterialApp.router(
routerConfig: router,
),
);
await tester.pump();
// Проверяем, что экран отображается
expect(find.byType(GlossaryScreen), findsOneWidget);
expect(find.byType(Scaffold), findsOneWidget);
expect(find.text('Глоссарий'), findsOneWidget);
expect(find.byType(Loader), findsOneWidget);
});
testWidgets('GlossaryScreen создается с правильным passKey', (WidgetTester tester) async {
const passKey = 'test-pass-key-456';
final router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) => const GlossaryScreen(passKey: passKey),
),
],
);
await tester.pumpWidget(
MaterialApp.router(
routerConfig: router,
),
);
await tester.pump();
expect(find.byType(GlossaryScreen), findsOneWidget);
});
testWidgets('показывает стандартный лоадер при загрузке WebView', (WidgetTester tester) async {
const passKey = 'test-pass-key';
final router = GoRouter(
initialLocation: '/',
routes: [
GoRoute(
path: '/',
builder: (context, state) => const GlossaryScreen(passKey: passKey),
),
],
);
await tester.pumpWidget(
MaterialApp.router(
routerConfig: router,
),
);
await tester.pump();
expect(find.byType(Loader), findsOneWidget);
});
});
group('shouldHideGlossaryLoader', () {
test('не скрывает лоадер на странице login_with_pass_key', () {
expect(
shouldHideGlossaryLoader(
url: 'https://eatvio.ru/login_with_pass_key?id=1',
progress: 100,
),
isFalse,
);
});
test('не скрывает лоадер пока URL ещё не известен', () {
expect(shouldHideGlossaryLoader(url: '', progress: 80), isFalse);
});
test('не скрывает лоадер пока прогресс глоссария ниже порога', () {
expect(
shouldHideGlossaryLoader(
url: 'https://eatvio.ru/product_nutritional_value',
progress: 39,
),
isFalse,
);
});
test('скрывает лоадер когда страница глоссария уже начала отрисовываться', () {
expect(
shouldHideGlossaryLoader(
url: 'https://eatvio.ru/product_nutritional_value',
progress: 40,
),
isTrue,
);
});
});
}