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

246 lines
7.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: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/features/divination/data/models/divination_params.dart';
import 'package:meeyao_qianwen/features/divination/data/models/divination_result.dart';
import 'package:meeyao_qianwen/features/divination/presentation/screens/divination_result_screen.dart';
import 'package:meeyao_qianwen/l10n/app_localizations.dart';
void main() {
DivinationResultData buildResultData() {
final params = DivinationParams(
method: DivinationMethod.auto,
questionType: QuestionType.health,
question: '近期状态是否平稳',
divinationTime: DateTime(2026, 4, 3, 20, 30),
coinBalance: 10,
userId: 'u_test',
);
return DivinationResultData(
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: '',
),
],
);
}
testWidgets('result screen shows key sections', (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: DivinationResultScreen(data: data),
),
);
await tester.pump(const Duration(milliseconds: 1000));
await tester.pumpAndSettle();
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);
});
}