Keep Cupertino chat summaries and contextual prompts readable
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_injected_rows.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_surface.dart';
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
|
||||
// Contrast uses the rendered/composited foreground, not the RGB of an alpha
|
||||
// system color as though it were opaque. These assertions cover only these
|
||||
// named text states/surfaces, not the whole app or every possible backdrop.
|
||||
double _contrast(Color foreground, Color background) {
|
||||
final ink = Color.alphaBlend(foreground, background).computeLuminance();
|
||||
final paper = background.computeLuminance();
|
||||
return (ink > paper ? ink + .05 : paper + .05) /
|
||||
(ink > paper ? paper + .05 : ink + .05);
|
||||
}
|
||||
|
||||
const _report = {
|
||||
'message': {
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Report summary', 'name': 'reviewer'},
|
||||
],
|
||||
},
|
||||
};
|
||||
const _notice = {
|
||||
'message': {
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Background task finished'},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
void main() {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final highContrast in [false, true]) {
|
||||
testWidgets(
|
||||
'report and completion text contrast $brightness highContrast=$highContrast',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(
|
||||
highContrast: highContrast,
|
||||
textScaler: const TextScaler.linear(2),
|
||||
),
|
||||
child: child!,
|
||||
),
|
||||
home: const CupertinoPageScaffold(
|
||||
child: Column(
|
||||
children: [
|
||||
ChatAgentReportCard(row: _report),
|
||||
ChatSystemNoticeLine(row: _notice),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final context = tester.element(find.byType(ChatAgentReportCard));
|
||||
final card = CupertinoColors.secondarySystemGroupedBackground
|
||||
.resolveFrom(context);
|
||||
final page = CupertinoTheme.of(context).scaffoldBackgroundColor;
|
||||
final summary = tester.widget<Text>(find.text('Report summary'));
|
||||
final notice = tester.widget<Text>(
|
||||
find.text('Background task finished'),
|
||||
);
|
||||
expect(
|
||||
_contrast(summary.style!.color!, card),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
expect(
|
||||
_contrast(notice.style!.color!, page),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
);
|
||||
debugPrint(
|
||||
'contrast $brightness highContrast=$highContrast report=${_contrast(summary.style!.color!, card).toStringAsFixed(2)} notice=${_contrast(notice.style!.color!, page).toStringAsFixed(2)} oldSecondary=${_contrast(CupertinoColors.secondaryLabel.resolveFrom(context), card).toStringAsFixed(2)}',
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
testWidgets(
|
||||
'contextual placeholder stays readable on the glass fill $brightness',
|
||||
(tester) async {
|
||||
final gateway = ComposerBarGateway();
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
home: CupertinoPageScaffold(
|
||||
child: ChatThreadView(
|
||||
gateway: gateway,
|
||||
sessionId: 's',
|
||||
onBack: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final field = tester.widget<CupertinoTextField>(
|
||||
find.byType(CupertinoTextField),
|
||||
);
|
||||
final context = tester.element(find.byType(CupertinoTextField));
|
||||
final base = CupertinoColors.systemGrey5.resolveFrom(context);
|
||||
final backdrop = CupertinoTheme.of(context).scaffoldBackgroundColor;
|
||||
final glass = Color.alphaBlend(
|
||||
base.withValues(alpha: GlassPill.fillOpacity),
|
||||
backdrop,
|
||||
);
|
||||
final highlighted = Color.alphaBlend(
|
||||
GlassLook.forFill(base).highlight,
|
||||
glass,
|
||||
);
|
||||
final foreground = CupertinoDynamicColor.resolve(
|
||||
field.placeholderStyle!.color!,
|
||||
context,
|
||||
);
|
||||
// White/black backdrop bounds also cover arbitrary blurred content
|
||||
// below the 82% native fill. High-contrast mode uses solid base.
|
||||
final backdropBounds = [
|
||||
const Color(0xFF000000),
|
||||
const Color(0xFFFFFFFF),
|
||||
];
|
||||
final boundedFills = [
|
||||
for (final background in backdropBounds)
|
||||
Color.alphaBlend(
|
||||
base.withValues(alpha: GlassPill.fillOpacity),
|
||||
background,
|
||||
),
|
||||
];
|
||||
for (final fill in [base, glass, highlighted, ...boundedFills]) {
|
||||
expect(_contrast(foreground, fill), greaterThanOrEqualTo(4.5));
|
||||
}
|
||||
debugPrint(
|
||||
'contrast $brightness placeholder=${_contrast(foreground, glass).toStringAsFixed(2)} oldPlaceholder=${_contrast(CupertinoColors.placeholderText.resolveFrom(context), glass).toStringAsFixed(2)} glass=${glass.toARGB32().toRadixString(16)}',
|
||||
);
|
||||
expect(
|
||||
field.placeholderStyle!.color,
|
||||
CupertinoColors.label.resolveFrom(context),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user