69b34bd723
- 后端 ProfileSettingsV1 添加 DivinationTutorialSettings 字段 - 前端三个起卦页面添加首次访问检测,自动弹出教程 - 教程展示后更新 settings 标记,避免重复弹出 - 使用本地状态管理避免并发更新覆盖问题 - Agent 系统提示添加时间上下文信息
133 lines
4.8 KiB
Dart
133 lines
4.8 KiB
Dart
import 'package:flutter/material.dart';
|
||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||
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';
|
||
import 'package:meeyao_qianwen/features/divination/data/models/divination_params.dart';
|
||
import 'package:meeyao_qianwen/features/divination/data/services/divination_run_service.dart';
|
||
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';
|
||
|
||
void main() {
|
||
final runService = DivinationRunService(
|
||
api: DivinationApi(apiClient: ApiClient(baseUrl: 'http://localhost:5775')),
|
||
);
|
||
final sessionStore = SessionStore(LocalKvStore());
|
||
final profileSettings = ProfileSettingsV1.defaultsForLocale(
|
||
const Locale('zh'),
|
||
);
|
||
|
||
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 {},
|
||
),
|
||
),
|
||
);
|
||
|
||
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(
|
||
method: DivinationMethod.auto,
|
||
questionType: QuestionType.career,
|
||
question: '测试问题',
|
||
divinationTime: DateTime(2026, 4, 3, 20, 30),
|
||
coinBalance: 9,
|
||
userId: 'user_test',
|
||
);
|
||
|
||
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 {},
|
||
),
|
||
),
|
||
);
|
||
|
||
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 {},
|
||
),
|
||
),
|
||
);
|
||
|
||
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);
|
||
});
|
||
}
|