Merge branch 'main' into worktree-agent-abb9404cc062f4b30
# Conflicts: # app/lib/application/app.dart # app/lib/application/detached/detached_app.dart # app/lib/application/pipelines_root.dart # app/lib/ui/theme/app_design.dart # app/test/ui/theme/compact_switch_test.dart # app/test/ui/theme/high_contrast_design_test.dart
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
|
||||
JsonMap _row(JsonMap message) => transcriptRows([message]).single;
|
||||
|
||||
final JsonMap _operator = _row({
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Fix the Windows paths.'},
|
||||
],
|
||||
});
|
||||
|
||||
JsonMap _tool(String id, String name) => {
|
||||
'type': 'tool',
|
||||
'id': id,
|
||||
'name': name,
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'command': 'go test ./...'},
|
||||
},
|
||||
};
|
||||
|
||||
final JsonMap _agent = _row({
|
||||
'id': 'a1',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
_tool('t1', 'Bash'),
|
||||
_tool('t2', 'Read'),
|
||||
{
|
||||
'type': 'text',
|
||||
'text': 'Fixed the separators.\n\n```go\nreturn filepath.Join(a, b)\n```',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
final JsonMap _followup = _row({
|
||||
'id': 'f1',
|
||||
'role': 'user',
|
||||
'origin': 'followup',
|
||||
'client': 'Agent follow-up',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Check whether run 42 finished.'},
|
||||
],
|
||||
});
|
||||
|
||||
Widget _host(AppDesign design, List<JsonMap> rows, {Brightness? brightness}) =>
|
||||
MaterialApp(
|
||||
theme: brightness == Brightness.dark ? design.dark() : design.light(),
|
||||
home: Scaffold(
|
||||
body: ChatBubbleColor(
|
||||
name: 'teal',
|
||||
child: ListView(
|
||||
children: [
|
||||
for (final row in rows)
|
||||
ChatMessageView(row: row, textBuilder: chatMarkdownText),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
ShapeBorder _bubbleShape(WidgetTester tester) => tester
|
||||
.widget<Material>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(ChatUserBubble),
|
||||
matching: find.byType(Material),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.shape!;
|
||||
|
||||
void main() {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('Glass ($brightness): the operator turn is a frosted pill '
|
||||
'tinted with the chat colour, under a glass edge', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(AppDesign.glass, [_operator], brightness: brightness),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(_bubbleShape(tester), isA<GlassBorder>());
|
||||
final fill = tester
|
||||
.widget<Material>(
|
||||
find
|
||||
.descendant(
|
||||
of: find.byType(ChatUserBubble),
|
||||
matching: find.byType(Material),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.color!;
|
||||
expect(fill.a, lessThan(1), reason: 'translucent glass');
|
||||
// Tinted towards the chat's teal: more green than red.
|
||||
expect(fill.g, greaterThan(fill.r));
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('Glass draws the agent turn with its tools chip, code card and '
|
||||
'follow-up note as glass, without errors', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(AppDesign.glass, [_operator, _agent, _followup]),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.textContaining('Fixed the separators'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-code-body')), findsOneWidget);
|
||||
final note = tester.widget<Material>(
|
||||
find.byKey(const Key('chat-automated-prompt')),
|
||||
);
|
||||
expect(note.shape, isA<GlassBorder>());
|
||||
final glass = Theme.of(
|
||||
tester.element(find.byType(ListView)),
|
||||
).extension<AppDesignTokens>()!.glass!;
|
||||
expect(note.color, glass.card);
|
||||
});
|
||||
|
||||
testWidgets('Classic keeps its bubble and notes (no glass edges)', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
_host(AppDesign.standard, [_operator, _agent, _followup]),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_bubbleShape(tester), isA<RoundedRectangleBorder>());
|
||||
final note = tester.widget<Material>(
|
||||
find.byKey(const Key('chat-automated-prompt')),
|
||||
);
|
||||
expect(note.shape, isA<RoundedRectangleBorder>());
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_row.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_row_glow.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
|
||||
Widget _host(AppDesign design, List<Widget> rows) => MaterialApp(
|
||||
theme: design.light(),
|
||||
home: Scaffold(body: ListView(children: rows)),
|
||||
);
|
||||
|
||||
AppListRow _row(String key, {bool selected = false, Color? accent}) =>
|
||||
AppListRow(
|
||||
key: Key(key),
|
||||
selected: selected,
|
||||
accent: accent,
|
||||
onTap: () {},
|
||||
title: Text(key),
|
||||
subtitle: const Text('a line of facts'),
|
||||
);
|
||||
|
||||
Finder _in(String key, Finder finder) =>
|
||||
find.descendant(of: find.byKey(Key(key)), matching: finder);
|
||||
|
||||
void main() {
|
||||
testWidgets('Glass: the open row is a brighter slab with a ring and a '
|
||||
'glow in its accent, inset with rounded corners', (tester) async {
|
||||
const teal = Color(0xFF00796B);
|
||||
await tester.pumpWidget(
|
||||
_host(AppDesign.glass, [
|
||||
_row('open', selected: true, accent: teal),
|
||||
_row('coloured', accent: teal),
|
||||
_row('plain'),
|
||||
]),
|
||||
);
|
||||
final context = tester.element(find.byKey(const Key('open')));
|
||||
final glass = AppDesignTokens.of(context).glass!;
|
||||
expect(_in('open', find.byType(AppListRowGlow)), findsOneWidget);
|
||||
|
||||
final open = tester.widget<Material>(
|
||||
_in('open', find.byKey(appListRowSurfaceKey)),
|
||||
);
|
||||
final shape = open.shape! as RoundedRectangleBorder;
|
||||
expect(
|
||||
shape.borderRadius,
|
||||
const BorderRadius.all(Radius.circular(kAppListRowGlowRadius)),
|
||||
);
|
||||
expect(shape.side.color.r, closeTo(teal.r, 0.01));
|
||||
// Brighter than the pane: the slab, washed a little with the accent.
|
||||
expect(open.color, Color.alphaBlend(teal.withValues(alpha: 0.08), glass.slab));
|
||||
final glow = tester
|
||||
.widget<DecoratedBox>(
|
||||
find
|
||||
.ancestor(
|
||||
of: _in('open', find.byKey(appListRowSurfaceKey)),
|
||||
matching: find.byType(DecoratedBox),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.decoration as BoxDecoration;
|
||||
expect(glow.boxShadow!.first.color, teal.withValues(alpha: glass.glow));
|
||||
expect(_in('open', find.byKey(appListRowSelectionKey)), findsOneWidget);
|
||||
|
||||
// A coloured row is a faint tint with its mark; a plain row is clear.
|
||||
final coloured = tester.widget<Material>(
|
||||
_in('coloured', find.byKey(appListRowSurfaceKey)),
|
||||
);
|
||||
expect(coloured.color, AppListRow.tintFor(context, teal));
|
||||
expect(_in('coloured', find.byKey(appListRowAccentKey)), findsOneWidget);
|
||||
final plain = tester.widget<Material>(
|
||||
_in('plain', find.byKey(appListRowSurfaceKey)),
|
||||
);
|
||||
expect(plain.color!.a, 0);
|
||||
|
||||
// The slab sits inset from the pane's sides.
|
||||
final row = tester.getRect(find.byKey(const Key('open')));
|
||||
final slab = tester.getRect(_in('open', find.byKey(appListRowSurfaceKey)));
|
||||
expect(slab.left - row.left, kAppListRowGlowMargin.left);
|
||||
expect(row.right - slab.right, kAppListRowGlowMargin.right);
|
||||
});
|
||||
|
||||
testWidgets('other designs never draw a glass row', (tester) async {
|
||||
for (final design in AppDesign.values.where((d) => d != AppDesign.glass)) {
|
||||
await tester.pumpWidget(
|
||||
_host(design, [_row('open', selected: true)]),
|
||||
);
|
||||
expect(find.byType(AppListRowGlow), findsNothing, reason: design.label);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -108,7 +108,10 @@ void main() {
|
||||
AppDesign.paper,
|
||||
AppDesign.notebook,
|
||||
AppDesign.highContrast,
|
||||
// Glass snaps in and out (snapSwitch), to and from Compact too.
|
||||
AppDesign.glass,
|
||||
AppDesign.compact,
|
||||
AppDesign.glass,
|
||||
AppDesign.retroCrt,
|
||||
AppDesign.retroCrtAmber,
|
||||
]) {
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
import 'package:pipelines_app/ui/theme/glass_backdrop.dart';
|
||||
import 'package:pipelines_app/ui/theme/glass_palette.dart';
|
||||
|
||||
ThemeData _theme(AppDesign design, Brightness brightness) =>
|
||||
brightness == Brightness.dark ? design.dark() : design.light();
|
||||
|
||||
AppDesignTokens _tokens(AppDesign design, Brightness brightness) =>
|
||||
_theme(design, brightness).extension<AppDesignTokens>() ??
|
||||
AppDesignTokens.standard;
|
||||
|
||||
double _contrast(Color a, Color b) {
|
||||
final la = a.computeLuminance(), lb = b.computeLuminance();
|
||||
return (math.max(la, lb) + 0.05) / (math.min(la, lb) + 0.05);
|
||||
}
|
||||
|
||||
/// Every colour the backdrop can show at a point: its base and each glow at
|
||||
/// full strength (the worst cases), composited under [tints] in order.
|
||||
List<Color> _grounds(GlassStyle style, List<Color> tints) => [
|
||||
for (final under in [
|
||||
style.backdrop.base,
|
||||
for (final glow in style.backdrop.glows)
|
||||
Color.alphaBlend(glow.color, style.backdrop.base),
|
||||
])
|
||||
tints.fold(under, (ground, tint) => Color.alphaBlend(tint, ground)),
|
||||
];
|
||||
|
||||
void main() {
|
||||
test('Glass is listed with a stable id, a label and one line', () {
|
||||
expect(AppDesign.values, contains(AppDesign.glass));
|
||||
expect(AppDesign.fromId('glass'), AppDesign.glass);
|
||||
expect(AppDesign.glass.label, 'Glass');
|
||||
expect(AppDesign.glass.description, isNot(contains('\n')));
|
||||
expect(AppDesign.glass.usesInterfaceFont, isTrue);
|
||||
});
|
||||
|
||||
test('Glass tokens: bubbles and a pill composer on glass, a glowing open '
|
||||
'row, no flat frames, corners grown with the hierarchy kept', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(AppDesign.glass, brightness);
|
||||
final tokens = theme.extension<AppDesignTokens>()!;
|
||||
expect(tokens.design, AppDesign.glass);
|
||||
expect(tokens.transcript, TranscriptStyle.bubbles);
|
||||
expect(tokens.composer, ComposerStyle.pill);
|
||||
expect(tokens.selectedRow, SelectedRowStyle.glow);
|
||||
expect(tokens.flat, isFalse);
|
||||
expect(tokens.radius, isNull);
|
||||
expect(tokens.frame, isNull);
|
||||
expect(tokens.snapSwitch, isTrue);
|
||||
expect(tokens.ansi, isNotNull);
|
||||
expect(tokens.reading.family, isNull, reason: 'the interface sans');
|
||||
expect(tokens.reading.height, greaterThan(1.4));
|
||||
final glass = tokens.glass!;
|
||||
expect(glass, brightness == Brightness.dark ? glassDarkStyle : glassLightStyle);
|
||||
// Outer > inner: each widget's own radius grows by the same factor up
|
||||
// to the cap, so nesting order is kept.
|
||||
expect(tokens.corners(BorderRadius.circular(4)), BorderRadius.circular(6));
|
||||
expect(tokens.corners(BorderRadius.circular(8)), BorderRadius.circular(12));
|
||||
expect(tokens.corners(BorderRadius.circular(16)), BorderRadius.circular(20));
|
||||
expect(tokens.corners(BorderRadius.circular(28)), BorderRadius.circular(28));
|
||||
expect(tokens.shape(const StadiumBorder()), const StadiumBorder());
|
||||
expect(tokens.shape(const CircleBorder()), const CircleBorder());
|
||||
expect(
|
||||
tokens.shape(
|
||||
const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
),
|
||||
),
|
||||
const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(18)),
|
||||
),
|
||||
);
|
||||
// Pages are clear over the backdrop; floating pieces nearly opaque.
|
||||
expect(theme.scaffoldBackgroundColor.a, 0);
|
||||
expect(theme.dialogTheme.backgroundColor!.a, greaterThan(0.9));
|
||||
expect(theme.popupMenuTheme.color!.a, greaterThan(0.9));
|
||||
expect(theme.dialogTheme.shape, isA<GlassBorder>());
|
||||
expect(theme.popupMenuTheme.shape, isA<GlassBorder>());
|
||||
expect(theme.cardTheme.shape, isA<GlassBorder>());
|
||||
// Containers are glass tints; the page roles stay opaque for blends.
|
||||
expect(theme.colorScheme.surfaceContainerHigh.a, lessThan(1));
|
||||
expect(theme.colorScheme.surface.a, 1);
|
||||
expect(glass.solid.a, 1);
|
||||
}
|
||||
});
|
||||
|
||||
test('other designs keep their tokens and corners (no glass)', () {
|
||||
for (final design in AppDesign.values.where((d) => d != AppDesign.glass)) {
|
||||
for (final brightness in Brightness.values) {
|
||||
final tokens = _tokens(design, brightness);
|
||||
expect(tokens.glass, isNull, reason: design.label);
|
||||
expect(tokens.selectedRow, isNot(SelectedRowStyle.glow));
|
||||
final designed = BorderRadius.circular(8);
|
||||
expect(
|
||||
tokens.corners(designed),
|
||||
tokens.radius == null ? designed : BorderRadius.circular(tokens.radius!),
|
||||
);
|
||||
expect(tokens.solidFill(const Color(0x80FFFFFF)), const Color(0x80FFFFFF));
|
||||
expect(_theme(design, brightness).scaffoldBackgroundColor.a, 1);
|
||||
}
|
||||
}
|
||||
expect(_tokens(AppDesign.standard, Brightness.light), AppDesignTokens.standard);
|
||||
});
|
||||
|
||||
test('Glass body text keeps WCAG AA over every part of the backdrop', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(AppDesign.glass, brightness);
|
||||
final scheme = theme.colorScheme;
|
||||
final glass = theme.extension<AppDesignTokens>()!.glass!;
|
||||
final surfaces = <String, List<Color>>{
|
||||
'rail': _grounds(glass, [glass.rail]),
|
||||
'list pane': _grounds(glass, [glass.pane]),
|
||||
'reading pane': _grounds(glass, [glass.detail]),
|
||||
'card in the reading pane': _grounds(glass, [glass.detail, glass.card]),
|
||||
'bubble': _grounds(glass, [
|
||||
glass.detail,
|
||||
scheme.surfaceContainerHighest,
|
||||
]),
|
||||
'bar': _grounds(glass, [glass.bar]),
|
||||
'open row': _grounds(glass, [glass.pane, glass.slab]),
|
||||
};
|
||||
for (final MapEntry(key: name, value: grounds) in surfaces.entries) {
|
||||
for (final ground in grounds) {
|
||||
expect(
|
||||
_contrast(scheme.onSurface, ground),
|
||||
greaterThanOrEqualTo(7),
|
||||
reason: '$brightness body text on the $name',
|
||||
);
|
||||
expect(
|
||||
_contrast(scheme.onSurfaceVariant, ground),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
reason: '$brightness muted text on the $name',
|
||||
);
|
||||
expect(
|
||||
_contrast(scheme.primary, ground),
|
||||
greaterThanOrEqualTo(4.5),
|
||||
reason: '$brightness accent text on the $name',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('the backdrop paints only under Glass and keeps one tree '
|
||||
'shape for every design', (tester) async {
|
||||
for (final design in AppDesign.values) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: design.light(),
|
||||
home: const GlassBackdrop(child: SizedBox.expand()),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final paint = tester.widget<CustomPaint>(
|
||||
find.byKey(const ValueKey('glass-backdrop')),
|
||||
);
|
||||
if (design == AppDesign.glass) {
|
||||
expect(paint.painter, isA<GlassMeshPainter>());
|
||||
expect(
|
||||
(paint.painter! as GlassMeshPainter).mesh,
|
||||
glassLightStyle.backdrop,
|
||||
);
|
||||
} else {
|
||||
expect(paint.painter, isNull, reason: design.label);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('GlassBorder is value-equal, keeps a side it is given, and lerps', () {
|
||||
const a = GlassBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(16)),
|
||||
highlight: Color(0xFFFFFFFF),
|
||||
edge: Color(0x22000000),
|
||||
);
|
||||
const b = GlassBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(16)),
|
||||
highlight: Color(0xFFFFFFFF),
|
||||
edge: Color(0x22000000),
|
||||
);
|
||||
expect(a, b);
|
||||
expect(a.hashCode, b.hashCode);
|
||||
final ring = a.copyWith(side: const BorderSide(width: 2));
|
||||
expect(ring.side.width, 2);
|
||||
expect(ring.borderRadius, a.borderRadius);
|
||||
expect(ring.dimensions, const EdgeInsets.all(2));
|
||||
expect(ShapeBorder.lerp(a, ring, 0.5), isA<GlassBorder>());
|
||||
});
|
||||
}
|
||||
@@ -255,10 +255,11 @@ void main() {
|
||||
expect(tokens.largeTargets, isFalse, reason: design.id);
|
||||
expect(tokens.minContrast, isNull, reason: design.id);
|
||||
expect(tokens.windowRadius, isNull, reason: design.id);
|
||||
// Retro CRT snaps too: a blended text glow hung skwasm.
|
||||
// Glass snaps too (its clear pages do not blend with an opaque
|
||||
// design's), and Retro CRT (a blended text glow hung skwasm).
|
||||
expect(
|
||||
tokens.snapSwitch,
|
||||
design.crtPhosphor != null,
|
||||
design == AppDesign.glass || design.crtPhosphor != null,
|
||||
reason: design.id,
|
||||
);
|
||||
expect(tokens.transcript, isNot(TranscriptStyle.boxed));
|
||||
|
||||
@@ -168,7 +168,11 @@ void main() {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(design, brightness);
|
||||
final swatch = design.swatch(brightness);
|
||||
expect(swatch.page, theme.scaffoldBackgroundColor, reason: '$design');
|
||||
// A glass design's scaffold is clear: its page is its backdrop.
|
||||
final page =
|
||||
theme.extension<AppDesignTokens>()?.glass?.backdrop.base ??
|
||||
theme.scaffoldBackgroundColor;
|
||||
expect(swatch.page, page, reason: '$design');
|
||||
expect(swatch.ink, theme.colorScheme.onSurface, reason: '$design');
|
||||
expect(swatch.accent, theme.colorScheme.primary, reason: '$design');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user