2026-04-03 16:56:47 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2026-04-03 19:04:46 +08:00
|
|
|
|
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';
|
2026-04-03 19:04:46 +08:00
|
|
|
|
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';
|
2026-04-03 19:04:46 +08:00
|
|
|
|
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';
|
2026-04-15 18:56:41 +08:00
|
|
|
|
import 'package:meeyao_qianwen/features/settings/data/models/profile_settings.dart';
|
2026-04-03 19:04:46 +08:00
|
|
|
|
import 'package:meeyao_qianwen/l10n/app_localizations.dart';
|
2026-04-03 16:56:47 +08:00
|
|
|
|
|
|
|
|
|
|
void main() {
|
2026-04-03 19:04:46 +08:00
|
|
|
|
final runService = DivinationRunService(
|
|
|
|
|
|
api: DivinationApi(apiClient: ApiClient(baseUrl: 'http://localhost:5775')),
|
|
|
|
|
|
);
|
|
|
|
|
|
final sessionStore = SessionStore(LocalKvStore());
|
2026-04-15 18:56:41 +08:00
|
|
|
|
final profileSettings = ProfileSettingsV1.defaultsForLocale(
|
|
|
|
|
|
const Locale('zh'),
|
|
|
|
|
|
);
|
2026-04-03 19:04:46 +08:00
|
|
|
|
|
2026-04-03 16:56:47 +08:00
|
|
|
|
testWidgets('divination screen navigates to auto screen', (tester) async {
|
|
|
|
|
|
await tester.pumpWidget(
|
2026-04-03 19:04:46 +08:00
|
|
|
|
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',
|
2026-04-06 01:28:10 +08:00
|
|
|
|
onCompleted: (_) async {},
|
2026-04-03 19:04:46 +08:00
|
|
|
|
runServiceOverride: runService,
|
2026-04-15 18:56:41 +08:00
|
|
|
|
profileSettings: profileSettings,
|
|
|
|
|
|
onProfileSettingsChanged: (_) async {},
|
2026-04-03 19:04:46 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
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 {
|
2026-04-03 19:04:46 +08:00
|
|
|
|
final params = DivinationParams(
|
2026-04-03 16:56:47 +08:00
|
|
|
|
method: DivinationMethod.auto,
|
2026-04-03 19:04:46 +08:00
|
|
|
|
questionType: QuestionType.career,
|
2026-04-03 16:56:47 +08:00
|
|
|
|
question: '测试问题',
|
2026-04-03 19:04:46 +08:00
|
|
|
|
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(),
|
2026-04-03 19:04:46 +08:00
|
|
|
|
locale: const Locale('zh'),
|
|
|
|
|
|
localizationsDelegates: const [
|
|
|
|
|
|
AppLocalizations.delegate,
|
|
|
|
|
|
GlobalMaterialLocalizations.delegate,
|
|
|
|
|
|
GlobalWidgetsLocalizations.delegate,
|
|
|
|
|
|
GlobalCupertinoLocalizations.delegate,
|
|
|
|
|
|
],
|
|
|
|
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
2026-04-06 01:28:10 +08:00
|
|
|
|
home: AutoDivinationScreen(
|
|
|
|
|
|
params: params,
|
|
|
|
|
|
runService: runService,
|
|
|
|
|
|
onCompleted: (_) async {},
|
2026-04-15 18:56:41 +08:00
|
|
|
|
profileSettings: profileSettings,
|
|
|
|
|
|
onProfileSettingsChanged: (_) async {},
|
2026-04-06 01:28:10 +08:00
|
|
|
|
),
|
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(
|
2026-04-03 19:04:46 +08:00
|
|
|
|
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',
|
2026-04-06 01:28:10 +08:00
|
|
|
|
onCompleted: (_) async {},
|
2026-04-03 19:04:46 +08:00
|
|
|
|
runServiceOverride: runService,
|
2026-04-15 18:56:41 +08:00
|
|
|
|
profileSettings: profileSettings,
|
|
|
|
|
|
onProfileSettingsChanged: (_) async {},
|
2026-04-03 19:04:46 +08:00
|
|
|
|
),
|
|
|
|
|
|
),
|
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);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|