@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22import 'package:flutter_test/flutter_test.dart' ;
33import 'package:echo_loop/models/speech_practice_models.dart' ;
44import 'package:echo_loop/providers/saved_word_provider.dart' ;
5+ import 'package:echo_loop/theme/app_theme.dart' ;
56import 'package:echo_loop/utils/saved_text_index.dart' ;
67import 'package:echo_loop/widgets/practice/sense_group_text.dart' ;
78
@@ -34,6 +35,77 @@ void main() {
3435 SpeechTranscriptSegment word (String text, {required bool matched}) =>
3536 SpeechTranscriptSegment (text: text, isMatched: matched);
3637
38+ BoxDecoration badgeDecorationFor (WidgetTester tester, String text) {
39+ final badge = tester.widget <Container >(
40+ find
41+ .ancestor (of: find.text (text), matching: find.byType (Container ))
42+ .first,
43+ );
44+ return switch (badge.decoration) {
45+ BoxDecoration decoration => decoration,
46+ _ => throw StateError ('意群 badge 应使用 BoxDecoration' ),
47+ };
48+ }
49+
50+ Color badgeBorderColor (BoxDecoration decoration) {
51+ return switch (decoration.border) {
52+ Border border => border.top.color,
53+ _ => throw StateError ('意群 badge 应使用 Border' ),
54+ };
55+ }
56+
57+ testWidgets ('普通态与播放态意群无背景填充,播放态仍由边框区分' , (tester) async {
58+ await tester.pumpWidget (
59+ createTestApp (
60+ SenseGroupText (
61+ chunks: const ['idle group' , 'playing group' ],
62+ timings: const [],
63+ onTapGroup: (_) {},
64+ playingGroupIndex: 1 ,
65+ ),
66+ ),
67+ );
68+
69+ final idleDecoration = badgeDecorationFor (tester, 'idle group' );
70+ final playingDecoration = badgeDecorationFor (tester, 'playing group' );
71+
72+ expect (idleDecoration.color, isNull);
73+ expect (playingDecoration.color, isNull);
74+ expect (idleDecoration.border, isNot (equals (playingDecoration.border)));
75+ });
76+
77+ testWidgets ('暗色主题提高普通态与已播放态边框的可见度' , (tester) async {
78+ await tester.pumpWidget (
79+ createTestApp (
80+ Theme (
81+ data: AppTheme .dark (),
82+ child: Scaffold (
83+ backgroundColor: Colors .black,
84+ body: SenseGroupText (
85+ chunks: const ['idle group' , 'played group' ],
86+ timings: const [],
87+ onTapGroup: (_) {},
88+ playedGroupIndices: const {1 },
89+ ),
90+ ),
91+ ),
92+ ),
93+ );
94+
95+ final idleDecoration = badgeDecorationFor (tester, 'idle group' );
96+ final playedDecoration = badgeDecorationFor (tester, 'played group' );
97+ final darkColorScheme = AppTheme .dark ().colorScheme;
98+
99+ expect (
100+ badgeBorderColor (idleDecoration),
101+ darkColorScheme.outline.withValues (alpha: 0.6 ),
102+ );
103+ expect (
104+ badgeBorderColor (playedDecoration),
105+ darkColorScheme.primary.withValues (alpha: 0.6 ),
106+ );
107+ });
108+
37109 group ('SenseGroupText — 意群模式单词高亮' , () {
38110 testWidgets ('匹配单词染绿,未匹配单词不染绿' , (tester) async {
39111 // 原文 "Hello brave world" → 意群拆为 ["Hello brave", "world"]
0 commit comments