Files
eryao/apps/test/features/divination/divination_screen_test.dart
T

133 lines
4.8 KiB
Dart
Raw Normal View History

2026-04-03 16:56:47 +08:00
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
2026-04-03 16:56:47 +08:00
import 'package:flutter_test/flutter_test.dart';
import 'package:meeyao_qianwen/app/app_theme.dart';
import 'package:meeyao_qianwen/core/auth/session_store.dart';
import 'package:meeyao_qianwen/data/network/api_client.dart';
import 'package:meeyao_qianwen/data/storage/local_kv_store.dart';
import 'package:meeyao_qianwen/features/divination/data/apis/divination_api.dart';
2026-04-03 16:56:47 +08:00
import 'package:meeyao_qianwen/features/divination/data/models/divination_params.dart';
import 'package:meeyao_qianwen/features/divination/data/services/divination_run_service.dart';
2026-04-03 16:56:47 +08:00
import 'package:meeyao_qianwen/features/divination/presentation/screens/auto_divination_screen.dart';
import 'package:meeyao_qianwen/features/divination/presentation/screens/divination_screen.dart';
import 'package:meeyao_qianwen/features/divination/presentation/screens/manual_divination_screen.dart';
import 'package:meeyao_qianwen/features/settings/data/models/profile_settings.dart';
import 'package:meeyao_qianwen/l10n/app_localizations.dart';
2026-04-03 16:56:47 +08:00
void main() {
final runService = DivinationRunService(
api: DivinationApi(apiClient: ApiClient(baseUrl: 'http://localhost:5775')),
);
final sessionStore = SessionStore(LocalKvStore());
final profileSettings = ProfileSettingsV1.defaultsForLocale(
const Locale('zh'),
);
2026-04-03 16:56:47 +08:00
testWidgets('divination screen navigates to auto screen', (tester) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.light(),
locale: const Locale('zh'),
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
home: DivinationScreen(
sessionStore: sessionStore,
userId: 'user_test',
onCompleted: (_) async {},
runServiceOverride: runService,
profileSettings: profileSettings,
onProfileSettingsChanged: (_) async {},
),
),
2026-04-03 16:56:47 +08:00
);
await tester.tap(find.text('自动起卦'));
await tester.enterText(find.byType(TextField), '最近事业发展是否顺利');
await tester.tap(find.text('开始起卦'));
await tester.pumpAndSettle();
expect(find.byType(AutoDivinationScreen), findsOneWidget);
expect(find.text('○ 老阳(变)'), findsOneWidget);
expect(find.text('× 老阴(变)'), findsOneWidget);
});
testWidgets('auto screen keeps resolve button disabled initially', (
tester,
) async {
final params = DivinationParams(
2026-04-03 16:56:47 +08:00
method: DivinationMethod.auto,
questionType: QuestionType.career,
2026-04-03 16:56:47 +08:00
question: '测试问题',
divinationTime: DateTime(2026, 4, 3, 20, 30),
coinBalance: 9,
userId: 'user_test',
2026-04-03 16:56:47 +08:00
);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.light(),
locale: const Locale('zh'),
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
home: AutoDivinationScreen(
params: params,
runService: runService,
onCompleted: (_) async {},
profileSettings: profileSettings,
onProfileSettingsChanged: (_) async {},
),
2026-04-03 16:56:47 +08:00
),
);
final resolveButton = tester.widget<FilledButton>(
find.widgetWithText(FilledButton, '开始解卦'),
);
expect(resolveButton.onPressed, isNull);
expect(find.text('您还需摇 6 次'), findsOneWidget);
});
testWidgets('divination screen navigates to manual screen by default', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.light(),
locale: const Locale('zh'),
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
home: DivinationScreen(
sessionStore: sessionStore,
userId: 'user_test',
onCompleted: (_) async {},
runServiceOverride: runService,
profileSettings: profileSettings,
onProfileSettingsChanged: (_) async {},
),
),
2026-04-03 16:56:47 +08:00
);
await tester.enterText(find.byType(TextField), '近期感情是否稳定');
await tester.tap(find.text('开始起卦'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 300));
expect(find.byType(ManualDivinationScreen), findsOneWidget);
});
}