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

246 lines
7.1 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/features/divination/data/models/divination_params.dart';
import 'package:meeyao_qianwen/features/divination/data/models/divination_result.dart';
2026-04-03 16:56:47 +08:00
import 'package:meeyao_qianwen/features/divination/presentation/screens/divination_result_screen.dart';
import 'package:meeyao_qianwen/l10n/app_localizations.dart';
2026-04-03 16:56:47 +08:00
void main() {
DivinationResultData buildResultData() {
final params = DivinationParams(
2026-04-03 16:56:47 +08:00
method: DivinationMethod.auto,
questionType: QuestionType.health,
question: '近期状态是否平稳',
divinationTime: DateTime(2026, 4, 3, 20, 30),
coinBalance: 10,
userId: 'u_test',
2026-04-03 16:56:47 +08:00
);
return DivinationResultData(
2026-04-03 16:56:47 +08:00
params: params,
binaryCode: '101001',
changedBinaryCode: '100001',
guaName: '山火贲',
targetGuaName: '山雷颐',
upperName: '',
lowerName: '',
signType: '中上签',
keywords: '稳中求进、审时度势、蓄势待发',
focusPoints: const ['世应有情,主事可成', '动爻化退,宜稳不宜急'],
conclusion: '1. 方向可行\n2. 节奏宜稳',
analysis: '当前阶段需先稳住节奏,再做关键推进。',
suggestion: '1. 控节奏\n2. 重复盘',
ganzhi: GanzhiData(
yearGanZhi: '丙午',
monthGanZhi: '辛卯',
dayGanZhi: '丁未',
timeGanZhi: '庚戌',
yearKongWang: '子丑',
monthKongWang: '戌亥',
dayKongWang: '寅卯',
timeKongWang: '寅卯',
yueJian: '卯木',
riChen: '未土',
yuePo: '酉金',
riChong: '丑土',
),
wuXingStatus: {'': '', '': '', '': '', '': '', '': ''},
yaoLines: [
YaoLineData(
index: 0,
spirit: '',
relation: '父母',
branch: '',
element: '',
type: YaoType.oldYin,
mark: '',
),
YaoLineData(
index: 1,
spirit: '',
relation: '兄弟',
branch: '',
element: '',
type: YaoType.youngYang,
mark: '',
),
YaoLineData(
index: 2,
spirit: '',
relation: '妻财',
branch: '',
element: '',
type: YaoType.youngYin,
mark: '',
),
YaoLineData(
index: 3,
spirit: '',
relation: '妻财',
branch: '',
element: '',
type: YaoType.oldYang,
mark: '',
),
YaoLineData(
index: 4,
spirit: '',
relation: '子孙',
branch: '',
element: '',
type: YaoType.youngYang,
mark: '',
),
YaoLineData(
index: 5,
spirit: '',
relation: '兄弟',
branch: '',
element: '',
type: YaoType.oldYin,
mark: '',
),
],
targetYaoLines: [
YaoLineData(
index: 0,
spirit: '',
relation: '父母',
branch: '',
element: '',
type: YaoType.youngYang,
mark: '',
),
YaoLineData(
index: 1,
spirit: '',
relation: '兄弟',
branch: '',
element: '',
type: YaoType.youngYang,
mark: '',
),
YaoLineData(
index: 2,
spirit: '',
relation: '妻财',
branch: '',
element: '',
type: YaoType.youngYin,
mark: '',
),
YaoLineData(
index: 3,
spirit: '',
relation: '妻财',
branch: '',
element: '',
type: YaoType.youngYin,
mark: '',
),
YaoLineData(
index: 4,
spirit: '',
relation: '子孙',
branch: '',
element: '',
type: YaoType.youngYang,
mark: '',
),
YaoLineData(
index: 5,
spirit: '',
relation: '兄弟',
branch: '',
element: '',
type: YaoType.youngYang,
mark: '',
),
2026-04-03 16:56:47 +08:00
],
);
}
testWidgets('result screen shows key sections', (tester) async {
final data = buildResultData();
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,
2026-04-03 16:56:47 +08:00
home: DivinationResultScreen(data: data),
),
);
await tester.pump(const Duration(milliseconds: 1000));
await tester.pumpAndSettle();
2026-04-03 16:56:47 +08:00
expect(find.text('解卦结果'), findsOneWidget);
expect(find.text('AI解卦'), findsOneWidget);
expect(find.text('基础信息'), findsOneWidget);
expect(find.text('卦象详情'), findsOneWidget);
expect(find.text('解卦结论'), findsOneWidget);
expect(find.text('○ 老阳(变)'), findsOneWidget);
expect(find.text('× 老阴(变)'), findsOneWidget);
expect(find.text(''), findsWidgets);
expect(find.text('×'), findsWidgets);
});
testWidgets('result screen back returns directly to root home', (
tester,
) async {
final data = buildResultData();
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: Builder(
builder: (context) {
return Scaffold(
body: Center(
child: FilledButton(
onPressed: () {
Navigator.of(context).push<void>(
MaterialPageRoute<void>(
builder: (_) => DivinationResultScreen(data: data),
),
);
},
child: const Text('open_result'),
),
),
);
},
),
),
);
await tester.tap(find.text('open_result'));
await tester.pumpAndSettle();
await tester.pump(const Duration(milliseconds: 1000));
await tester.pumpAndSettle();
expect(find.byType(DivinationResultScreen), findsOneWidget);
await tester.tap(find.byIcon(Icons.arrow_back_ios_new_rounded));
await tester.pumpAndSettle();
expect(find.text('open_result'), findsOneWidget);
expect(find.byType(DivinationResultScreen), findsNothing);
});
2026-04-03 16:56:47 +08:00
}