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/features/chat/ui/sessions/chat_color_palette.dart # app/lib/ui/theme/app_design.dart # app/lib/ui/theme/app_design_tokens.dart
This commit is contained in:
@@ -151,7 +151,7 @@ void main() {
|
||||
);
|
||||
expect(painter.circle, circle.width);
|
||||
expect(
|
||||
painter.radius - ChatUsageRingPainter.stroke / 2,
|
||||
painter.radius - painter.stroke / 2,
|
||||
circle.width / 2 + ChatUsageRingPainter.gap,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -107,6 +107,7 @@ void main() {
|
||||
AppDesign.terminal,
|
||||
AppDesign.paper,
|
||||
AppDesign.notebook,
|
||||
AppDesign.highContrast,
|
||||
AppDesign.compact,
|
||||
AppDesign.retroCrt,
|
||||
AppDesign.retroCrtAmber,
|
||||
|
||||
@@ -0,0 +1,313 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_colors.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/platform.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
import 'package:pipelines_app/ui/theme/high_contrast_palette.dart';
|
||||
|
||||
ThemeData _theme(AppDesign design, Brightness brightness) =>
|
||||
brightness == Brightness.dark ? design.dark() : design.light();
|
||||
|
||||
/// Fails with the pair's name and ratio when [fg] on [bg] is below [min].
|
||||
void _expectContrast(String pair, Color fg, Color bg, double min) {
|
||||
final ratio = contrastRatio(fg, bg);
|
||||
expect(
|
||||
ratio,
|
||||
greaterThanOrEqualTo(min),
|
||||
reason: '$pair: ${ratio.toStringAsFixed(2)}:1, wanted $min:1',
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('High contrast is listed with a stable id, a label and one line', () {
|
||||
expect(AppDesign.values, contains(AppDesign.highContrast));
|
||||
expect(AppDesign.fromId('high-contrast'), AppDesign.highContrast);
|
||||
expect(AppDesign.highContrast.label, 'High contrast');
|
||||
expect(AppDesign.highContrast.description, isNot(contains('\n')));
|
||||
expect(AppDesign.highContrast.usesInterfaceFont, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'tokens: boxed transcript, inverted row, 6px corners, 2px frames, a '
|
||||
'thicker usage ring, a 3px focus ring, 48px targets, a contrast floor',
|
||||
() {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(AppDesign.highContrast, brightness);
|
||||
final scheme = theme.colorScheme;
|
||||
final tokens = theme.extension<AppDesignTokens>()!;
|
||||
expect(tokens.design, AppDesign.highContrast);
|
||||
expect(tokens.transcript, TranscriptStyle.boxed);
|
||||
expect(tokens.selectedRow, SelectedRowStyle.inverted);
|
||||
expect(tokens.composer, ComposerStyle.pill);
|
||||
expect(tokens.radius, 6);
|
||||
expect(tokens.flat, isTrue);
|
||||
expect(tokens.stroke, 2);
|
||||
expect(tokens.frameSide, BorderSide(color: scheme.outline, width: 2));
|
||||
expect(tokens.ringStroke, 3);
|
||||
expect(tokens.focusRing?.width, 3);
|
||||
expect(tokens.focusRing?.offset, greaterThan(0));
|
||||
expect(tokens.focusRing?.color, scheme.primary);
|
||||
expect(tokens.largeTargets, isTrue);
|
||||
expect(tokens.minContrast, highContrastMinimum);
|
||||
expect(tokens.windowRadius, 6);
|
||||
expect(tokens.snapSwitch, isTrue);
|
||||
expect(tokens.ansi, isNotNull);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test('pages are pure black and pure white, every container the page', () {
|
||||
final dark = AppDesign.highContrast.dark().colorScheme;
|
||||
final light = AppDesign.highContrast.light().colorScheme;
|
||||
expect(dark.surface, const Color(0xFF000000));
|
||||
expect(dark.onSurface, const Color(0xFFFFFFFF));
|
||||
expect(light.surface, const Color(0xFFFFFFFF));
|
||||
expect(light.onSurface, const Color(0xFF000000));
|
||||
for (final scheme in [dark, light]) {
|
||||
for (final container in [
|
||||
scheme.surfaceContainerLowest,
|
||||
scheme.surfaceContainerLow,
|
||||
scheme.surfaceContainer,
|
||||
scheme.surfaceContainerHigh,
|
||||
scheme.surfaceContainerHighest,
|
||||
]) {
|
||||
expect(container, scheme.surface);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
group('contrast', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
test('$brightness: body text and status words reach 7:1, everything '
|
||||
'else 4.5:1', () {
|
||||
final theme = _theme(AppDesign.highContrast, brightness);
|
||||
final s = theme.colorScheme;
|
||||
final page = s.surface;
|
||||
// WCAG AAA (7:1): reading text, the accent, errors and every
|
||||
// status colour a word is written in.
|
||||
for (final (name, fg, bg) in [
|
||||
('ink on page', s.onSurface, page),
|
||||
('secondary ink on page', s.onSurfaceVariant, page),
|
||||
('accent on page', s.primary, page),
|
||||
('text on accent', s.onPrimary, s.primary),
|
||||
('error on page', s.error, page),
|
||||
('error text on its container', s.onErrorContainer, s.errorContainer),
|
||||
('inverted row text', s.onSecondaryContainer, s.secondaryContainer),
|
||||
('tooltip/snack bar text', s.onInverseSurface, s.inverseSurface),
|
||||
('snack bar action', s.inversePrimary, s.inverseSurface),
|
||||
('green status', theme.ext.ansi!.green, page),
|
||||
('cyan status', theme.ext.ansi!.cyan, page),
|
||||
('yellow status', theme.ext.ansi!.yellow, page),
|
||||
('red status', theme.ext.ansi!.red, page),
|
||||
('magenta status', theme.ext.ansi!.magenta, page),
|
||||
('blue status', theme.ext.ansi!.blue, page),
|
||||
]) {
|
||||
_expectContrast(name, fg, bg, highContrastText);
|
||||
}
|
||||
// AA (4.5:1) for everything else, disabled text included.
|
||||
for (final (name, fg, bg) in [
|
||||
('control border', s.outline, page),
|
||||
('rule', s.outlineVariant, page),
|
||||
('warning (usage ring)', s.tertiary, page),
|
||||
('text on warning', s.onTertiary, s.tertiary),
|
||||
('text on error', s.onError, s.error),
|
||||
('disabled text', theme.disabledColor, page),
|
||||
('hint text', theme.hintColor, page),
|
||||
('focus ring', theme.ext.focusRing!.color, page),
|
||||
]) {
|
||||
_expectContrast(name, fg, bg, highContrastMinimum);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('$brightness: every chat colour reaches 4.5:1 on the page, '
|
||||
'and keeps its hue', (tester) async {
|
||||
final theme = _theme(AppDesign.highContrast, brightness);
|
||||
late BuildContext context;
|
||||
await tester.pumpWidget(
|
||||
Theme(
|
||||
data: theme,
|
||||
child: Builder(
|
||||
builder: (c) {
|
||||
context = c;
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
for (final name in chatColorNames) {
|
||||
final shade = chatColorShade(context, name)!;
|
||||
_expectContrast(
|
||||
'chat colour $name',
|
||||
shade,
|
||||
theme.scaffoldBackgroundColor,
|
||||
highContrastMinimum,
|
||||
);
|
||||
}
|
||||
// The orange's hue survives the darkening on white.
|
||||
final orange = HSVColor.fromColor(chatColorShade(context, 'orange')!);
|
||||
expect(orange.hue, inInclusiveRange(15, 45));
|
||||
});
|
||||
}
|
||||
|
||||
test('colorWithContrast moves away from the page, never past it', () {
|
||||
const yellow = Color(0xFFFFEB3B);
|
||||
final onWhite = colorWithContrast(yellow, const Color(0xFFFFFFFF), 4.5);
|
||||
expect(contrastRatio(onWhite, const Color(0xFFFFFFFF)), greaterThan(4.5));
|
||||
expect(onWhite.computeLuminance(), lessThan(yellow.computeLuminance()));
|
||||
// Already enough: unchanged.
|
||||
expect(
|
||||
colorWithContrast(yellow, const Color(0xFF000000), 4.5),
|
||||
same(yellow),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('flat, bordered surfaces: no elevation, 2px borders, 6px corners', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(AppDesign.highContrast, brightness);
|
||||
final scheme = theme.colorScheme;
|
||||
expect(theme.cardTheme.elevation, 0);
|
||||
expect(theme.dialogTheme.elevation, 0);
|
||||
expect(theme.popupMenuTheme.elevation, 0);
|
||||
expect(theme.snackBarTheme.elevation, 0);
|
||||
expect(theme.floatingActionButtonTheme.elevation, 0);
|
||||
expect(theme.appBarTheme.scrolledUnderElevation, 0);
|
||||
for (final shape in [
|
||||
theme.cardTheme.shape,
|
||||
theme.dialogTheme.shape,
|
||||
theme.popupMenuTheme.shape,
|
||||
theme.snackBarTheme.shape,
|
||||
]) {
|
||||
final border = shape! as RoundedRectangleBorder;
|
||||
expect(border.borderRadius, BorderRadius.circular(6));
|
||||
expect(border.side.width, 2);
|
||||
}
|
||||
expect(
|
||||
(theme.cardTheme.shape! as RoundedRectangleBorder).side.color,
|
||||
scheme.outline,
|
||||
);
|
||||
// Tooltips: large, inverted, framed.
|
||||
final tip = theme.tooltipTheme.decoration! as BoxDecoration;
|
||||
expect(tip.color, scheme.inverseSurface);
|
||||
expect(theme.tooltipTheme.textStyle!.fontSize, greaterThanOrEqualTo(16));
|
||||
// Fields: 2px, 3px of the accent while focused.
|
||||
final field = theme.inputDecorationTheme.border!;
|
||||
final idle = WidgetStateProperty.resolveAs<InputBorder>(field, {});
|
||||
final focused = WidgetStateProperty.resolveAs<InputBorder>(field, {
|
||||
WidgetState.focused,
|
||||
});
|
||||
expect(idle.borderSide.width, 2);
|
||||
expect(focused.borderSide.width, 3);
|
||||
expect(focused.borderSide.color, scheme.primary);
|
||||
// Outlined and filled buttons framed at 2px; disabled ones in the
|
||||
// disabled ink, still 4.5:1.
|
||||
final outlined = theme.outlinedButtonTheme.style!;
|
||||
expect(outlined.side!.resolve({})!.width, 2);
|
||||
expect(
|
||||
outlined.foregroundColor!.resolve({WidgetState.disabled}),
|
||||
theme.disabledColor,
|
||||
);
|
||||
expect(theme.filledButtonTheme.style!.side!.resolve({})!.width, 2);
|
||||
}
|
||||
});
|
||||
|
||||
test('larger, heavier type: body 16-17px at weight 500', () {
|
||||
final text = AppDesign.highContrast.light().textTheme;
|
||||
expect(text.bodyLarge!.fontSize, 17);
|
||||
expect(text.bodyMedium!.fontSize, 16);
|
||||
expect(text.bodySmall!.fontSize, greaterThanOrEqualTo(14));
|
||||
for (final style in [text.bodyLarge, text.bodyMedium, text.bodySmall]) {
|
||||
expect(style!.fontWeight, FontWeight.w500);
|
||||
}
|
||||
expect(text.labelSmall!.fontSize, greaterThanOrEqualTo(13));
|
||||
});
|
||||
|
||||
test('the inverse theme is the same design in the other brightness', () {
|
||||
final dark = AppDesign.highContrast.dark();
|
||||
final inverse = AppDesignTokens.inverseTheme(dark);
|
||||
expect(inverse.brightness, Brightness.light);
|
||||
expect(
|
||||
inverse.extension<AppDesignTokens>()!.design,
|
||||
AppDesign.highContrast,
|
||||
);
|
||||
expect(AppDesignTokens.inverseTheme(dark), same(inverse));
|
||||
});
|
||||
|
||||
group('the others are unchanged', () {
|
||||
test('Classic is the original theme; new tokens default for every other '
|
||||
'design', () {
|
||||
expect(AppDesign.standard.light(), appLightTheme());
|
||||
expect(AppDesign.standard.dark(), appDarkTheme());
|
||||
for (final design in AppDesign.values) {
|
||||
if (design == AppDesign.highContrast) continue;
|
||||
for (final brightness in Brightness.values) {
|
||||
final tokens =
|
||||
_theme(design, brightness).extension<AppDesignTokens>() ??
|
||||
AppDesignTokens.standard;
|
||||
expect(tokens.stroke, 1, reason: design.id);
|
||||
expect(tokens.ringStroke, 2, reason: design.id);
|
||||
expect(tokens.focusRing, isNull, reason: design.id);
|
||||
expect(tokens.largeTargets, isFalse, reason: design.id);
|
||||
expect(tokens.minContrast, isNull, reason: design.id);
|
||||
expect(tokens.windowRadius, isNull, reason: design.id);
|
||||
expect(tokens.snapSwitch, isFalse, reason: design.id);
|
||||
expect(tokens.transcript, isNot(TranscriptStyle.boxed));
|
||||
expect(tokens.selectedRow, isNot(SelectedRowStyle.inverted));
|
||||
final frame = tokens.frame;
|
||||
expect(
|
||||
tokens.frameSide,
|
||||
frame == null ? isNull : BorderSide(color: frame),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test('a switch into or out of High contrast snaps; Paper to Terminal '
|
||||
'still blends', () async {
|
||||
final designs = AppDesignController(store: MemoryAppDesignStore());
|
||||
await designs.select(AppDesign.paper);
|
||||
await designs.select(AppDesign.terminal);
|
||||
expect(designs.themeAnimationDuration, kThemeAnimationDuration);
|
||||
await designs.select(AppDesign.highContrast);
|
||||
expect(designs.themeAnimationDuration, Duration.zero);
|
||||
await designs.select(AppDesign.paper);
|
||||
expect(designs.themeAnimationDuration, Duration.zero);
|
||||
});
|
||||
|
||||
testWidgets('touch targets on a desktop only under High contrast', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
final compact = <AppDesign, bool>{};
|
||||
for (final design in AppDesign.values) {
|
||||
await tester.pumpWidget(
|
||||
Theme(
|
||||
data: design.light(),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
compact[design] = prefersCompactHitTargets(context);
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
expect(compact[AppDesign.highContrast], isFalse);
|
||||
for (final design in AppDesign.values) {
|
||||
if (design == AppDesign.highContrast) continue;
|
||||
expect(compact[design], isTrue, reason: design.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
extension on ThemeData {
|
||||
AppDesignTokens get ext => extension<AppDesignTokens>()!;
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
|
||||
final _rows = transcriptRows([
|
||||
for (var i = 0; i < 6; i++) ...[
|
||||
{
|
||||
'id': 'u$i',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Step $i'},
|
||||
],
|
||||
},
|
||||
{
|
||||
'id': 'a$i',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
{
|
||||
'type': 'tool',
|
||||
'id': 't$i',
|
||||
'name': 'Bash',
|
||||
'state': {
|
||||
'status': 'completed',
|
||||
'input': {'command': 'go test'},
|
||||
},
|
||||
},
|
||||
{'type': 'text', 'text': 'Fixed `x`.\n\n- one\n\n```go\nreturn 1\n```'},
|
||||
],
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
/// A live design switch to and from High contrast animates the theme (or
|
||||
/// snaps it, beside a dense design) without an error in any frame: a
|
||||
/// component text style from the unlocalized text theme cannot blend with
|
||||
/// another design's default (High contrast sets none on buttons).
|
||||
void main() {
|
||||
testWidgets('switching to and from High contrast lerps every frame cleanly', (
|
||||
tester,
|
||||
) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
final design = ValueNotifier(AppDesign.highContrast);
|
||||
await tester.pumpWidget(
|
||||
ValueListenableBuilder<AppDesign>(
|
||||
valueListenable: design,
|
||||
builder: (_, d, _) => MaterialApp(
|
||||
theme: d.dark(),
|
||||
darkTheme: d.dark(),
|
||||
home: Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('New run'),
|
||||
),
|
||||
body: Row(
|
||||
children: [
|
||||
NavigationRail(
|
||||
destinations: const [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.add),
|
||||
label: Text('a'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.add),
|
||||
label: Text('b'),
|
||||
),
|
||||
],
|
||||
selectedIndex: 0,
|
||||
),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
IconButton(onPressed: () {}, icon: const Icon(Icons.add)),
|
||||
IconButton.filled(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
Checkbox(value: true, onChanged: (_) {}),
|
||||
FilledButton(onPressed: () {}, child: const Text('f')),
|
||||
OutlinedButton(onPressed: () {}, child: const Text('o')),
|
||||
TextButton(onPressed: () {}, child: const Text('t')),
|
||||
MenuItemButton(onPressed: () {}, child: const Text('m')),
|
||||
const Badge(label: Text('3'), child: Icon(Icons.add)),
|
||||
const Tooltip(message: 'tip', child: Text('tip')),
|
||||
const DefaultTabController(
|
||||
length: 2,
|
||||
child: TabBar(
|
||||
tabs: [
|
||||
Tab(text: 'a'),
|
||||
Tab(text: 'b'),
|
||||
],
|
||||
),
|
||||
),
|
||||
Switch(value: true, onChanged: (_) {}),
|
||||
const ListTile(title: Text('t'), subtitle: Text('s')),
|
||||
const TextField(),
|
||||
Chip(label: const Text('c'), onDeleted: () {}),
|
||||
SegmentedButton<int>(
|
||||
segments: const [
|
||||
ButtonSegment(value: 1, label: Text('one')),
|
||||
ButtonSegment(value: 2, label: Text('two')),
|
||||
],
|
||||
selected: const {1},
|
||||
),
|
||||
for (final row in _rows) ChatMessageView(row: row),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
for (var round = 0; round < 3; round++) {
|
||||
for (final other in [
|
||||
for (final d in AppDesign.values)
|
||||
if (d != AppDesign.highContrast) ...[d, AppDesign.highContrast],
|
||||
]) {
|
||||
design.value = other;
|
||||
for (var f = 0; f < 20; f++) {
|
||||
await tester.pump(const Duration(milliseconds: 16));
|
||||
final e = tester.takeException();
|
||||
if (e != null) fail('to ${other.id} frame $f: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,376 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.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_message_bubble.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_design_section.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_avatar.dart';
|
||||
import 'package:pipelines_app/ui/layout/app_list_row.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/design_focus_ring.dart';
|
||||
|
||||
JsonMap _tool(String id, String status) => {
|
||||
'type': 'tool',
|
||||
'id': id,
|
||||
'name': 'Bash',
|
||||
'state': {
|
||||
'status': status,
|
||||
'input': {'command': 'go test ./internal/notes/...'},
|
||||
'content': [
|
||||
{'type': 'text', 'text': 'ok notes 0.2s'},
|
||||
],
|
||||
if (status == 'error') 'error': {'message': 'exit status 1'},
|
||||
},
|
||||
};
|
||||
|
||||
/// An operator turn, then an answer with a passing and a failing tool call.
|
||||
final List<JsonMap> _rows = transcriptRows([
|
||||
{
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{
|
||||
'type': 'text',
|
||||
'text': 'The release notes job fails on Windows paths. Fix it.',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
'id': 'a1',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
_tool('t1', 'completed'),
|
||||
_tool('t2', 'error'),
|
||||
{'type': 'text', 'text': 'Fixed: `filepath.Join` now.'},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
/// [child] under [design]'s theme at [width], with [textScale], inside the
|
||||
/// focus ring host the app's builders use.
|
||||
Widget _host(
|
||||
Widget child, {
|
||||
AppDesign design = AppDesign.highContrast,
|
||||
Brightness brightness = Brightness.dark,
|
||||
double textScale = 1,
|
||||
}) => MaterialApp(
|
||||
theme: design.light(),
|
||||
darkTheme: design.dark(),
|
||||
themeMode: brightness == Brightness.dark ? ThemeMode.dark : ThemeMode.light,
|
||||
builder: (context, child) => DesignFocusRing(
|
||||
child: MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(textScaler: TextScaler.linear(textScale)),
|
||||
child: child!,
|
||||
),
|
||||
),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
void _size(WidgetTester tester, Size size) {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
FocusRingPainter? _ring(WidgetTester tester) => tester
|
||||
.widgetList<CustomPaint>(find.byType(CustomPaint))
|
||||
.map((paint) => paint.painter)
|
||||
.whereType<FocusRingPainter>()
|
||||
.firstOrNull;
|
||||
|
||||
void main() {
|
||||
group('focus ring', () {
|
||||
testWidgets('a 3px ring with an offset goes round the control with '
|
||||
'keyboard focus', (tester) async {
|
||||
_size(tester, const Size(600, 400));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Center(
|
||||
child: FilledButton(onPressed: () {}, child: const Text('Go')),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(_ring(tester)?.rect.value, isNull);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
final ring = _ring(tester)!;
|
||||
final rect = ring.rect.value!;
|
||||
final button = tester.getRect(find.byType(FilledButton));
|
||||
// The ring's target is the button itself (within its tap padding).
|
||||
expect(button.inflate(1).contains(rect.topLeft), isTrue);
|
||||
expect(button.inflate(1).contains(rect.bottomRight), isTrue);
|
||||
expect(ring.style.width, 3);
|
||||
expect(ring.style.offset, greaterThan(0));
|
||||
final scheme = AppDesign.highContrast.dark().colorScheme;
|
||||
expect(
|
||||
find.byWidgetPredicate(
|
||||
(w) => w is CustomPaint && w.painter is FocusRingPainter,
|
||||
),
|
||||
paints
|
||||
..rrect(color: scheme.surface, strokeWidth: ring.style.offset)
|
||||
..rrect(color: scheme.primary, strokeWidth: 3),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a text field rings its whole decorated box', (tester) async {
|
||||
_size(tester, const Size(600, 400));
|
||||
await tester.pumpWidget(
|
||||
_host(const Center(child: SizedBox(width: 300, child: TextField()))),
|
||||
);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
final rect = _ring(tester)!.rect.value!;
|
||||
expect(rect.size, tester.getSize(find.byType(InputDecorator)));
|
||||
});
|
||||
|
||||
testWidgets('a pointer press hides the ring, as :focus-visible does; '
|
||||
'no ring under another design', (tester) async {
|
||||
_size(tester, const Size(600, 400));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Center(
|
||||
child: FilledButton(onPressed: () {}, child: const Text('Go')),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(_ring(tester)!.rect.value, isNotNull);
|
||||
await tester.tap(find.byType(FilledButton));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(_ring(tester)!.rect.value, isNull);
|
||||
|
||||
for (final design in AppDesign.values) {
|
||||
if (design == AppDesign.highContrast) continue;
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Center(
|
||||
child: FilledButton(onPressed: () {}, child: const Text('Go')),
|
||||
),
|
||||
design: design,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
|
||||
await tester.pump();
|
||||
expect(_ring(tester), isNull, reason: design.id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('every control keeps a 48px target on a desktop', (tester) async {
|
||||
debugDefaultTargetPlatformOverride = TargetPlatform.linux;
|
||||
addTearDown(() => debugDefaultTargetPlatformOverride = null);
|
||||
_size(tester, const Size(800, 900));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ListView(
|
||||
children: [
|
||||
Wrap(
|
||||
children: [
|
||||
IconButton(onPressed: () {}, icon: const Icon(Icons.add)),
|
||||
TextButton(onPressed: () {}, child: const Text('Ok')),
|
||||
OutlinedButton(onPressed: () {}, child: const Text('Ok')),
|
||||
FilledButton(onPressed: () {}, child: const Text('Ok')),
|
||||
Checkbox(value: true, onChanged: (_) {}),
|
||||
Switch(value: true, onChanged: (_) {}),
|
||||
ActionChip(label: const Text('Chip'), onPressed: () {}),
|
||||
FilterChip(
|
||||
label: const Text('Filter'),
|
||||
selected: true,
|
||||
onSelected: (_) {},
|
||||
),
|
||||
],
|
||||
),
|
||||
const ListTile(title: Text('Tile')),
|
||||
MenuItemButton(onPressed: () {}, child: const Text('Item')),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
for (final type in [
|
||||
IconButton,
|
||||
TextButton,
|
||||
OutlinedButton,
|
||||
FilledButton,
|
||||
Checkbox,
|
||||
Switch,
|
||||
ActionChip,
|
||||
FilterChip,
|
||||
ListTile,
|
||||
MenuItemButton,
|
||||
]) {
|
||||
final size = tester.getSize(find.byType(type).first);
|
||||
expect(size.height, greaterThanOrEqualTo(48), reason: '$type');
|
||||
expect(size.width, greaterThanOrEqualTo(48), reason: '$type');
|
||||
}
|
||||
debugDefaultTargetPlatformOverride = null;
|
||||
});
|
||||
|
||||
group('boxed transcript', () {
|
||||
testWidgets('the operator\'s turn is a framed box under "You"; tools are '
|
||||
'bordered rows that say Done and Failed', (tester) async {
|
||||
_size(tester, const Size(900, 900));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ListView(
|
||||
children: [for (final row in _rows) ChatMessageView(row: row)],
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const Key('chat-boxed-quote')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-boxed-quote-label')), findsOneWidget);
|
||||
expect(find.text('You'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-boxed-activity')), findsOneWidget);
|
||||
expect(find.byKey(const Key('boxed-status-done')), findsOneWidget);
|
||||
expect(find.byKey(const Key('boxed-status-failed')), findsOneWidget);
|
||||
expect(find.text('Done'), findsOneWidget);
|
||||
expect(find.text('Failed'), findsOneWidget);
|
||||
// The activity block is one big target.
|
||||
final block = tester.getSize(
|
||||
find.byKey(const Key('chat-boxed-activity')),
|
||||
);
|
||||
expect(block.height, greaterThanOrEqualTo(48));
|
||||
// The two tool names start at one column, whatever the status word.
|
||||
final names = tester
|
||||
.widgetList<RichText>(find.byType(RichText))
|
||||
.where((t) => t.text.toPlainText().startsWith('Bash'));
|
||||
final starts = {
|
||||
for (final name in names) tester.getTopLeft(find.byWidget(name)).dx,
|
||||
};
|
||||
expect(starts, hasLength(1));
|
||||
// No bubble fill: the agent's answer sits on the page.
|
||||
expect(find.byType(ChatUserBubble), findsOneWidget);
|
||||
});
|
||||
});
|
||||
|
||||
group('inverted open row', () {
|
||||
Widget rows({AppDesign design = AppDesign.highContrast}) => _host(
|
||||
Column(
|
||||
children: [
|
||||
AppListRow(
|
||||
key: const Key('open'),
|
||||
selected: true,
|
||||
leading: const AppListAvatar(child: Icon(Icons.check)),
|
||||
title: const Text('Release train run'),
|
||||
subtitle: const Text('release-train · 30m'),
|
||||
time: '09:12',
|
||||
onTap: () {},
|
||||
),
|
||||
AppListRow(
|
||||
key: const Key('closed'),
|
||||
title: const Text('Nightly docs run'),
|
||||
subtitle: const Text('nightly-docs · 3m'),
|
||||
time: '23:00',
|
||||
onTap: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
design: design,
|
||||
);
|
||||
|
||||
testWidgets('the open row is the ink with the page as its text, and a '
|
||||
'thicker bar', (tester) async {
|
||||
_size(tester, const Size(500, 400));
|
||||
await tester.pumpWidget(rows());
|
||||
final dark = AppDesign.highContrast.dark();
|
||||
final surface = tester.widget<Material>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('open')),
|
||||
matching: find.byKey(appListRowSurfaceKey),
|
||||
),
|
||||
);
|
||||
expect(surface.color, dark.colorScheme.onSurface);
|
||||
final title = tester.widget<DefaultTextStyle>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.text('Release train run'),
|
||||
matching: find.byType(DefaultTextStyle),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(title.style.color, dark.colorScheme.surface);
|
||||
final bar = tester.widget<DecoratedBox>(
|
||||
find.byKey(appListRowSelectionKey),
|
||||
);
|
||||
final border = (bar.decoration as BoxDecoration).border!;
|
||||
expect((border as BorderDirectional).start.width, 6);
|
||||
// The closed row keeps the page and the ink.
|
||||
final closed = tester.widget<DefaultTextStyle>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.text('Nightly docs run'),
|
||||
matching: find.byType(DefaultTextStyle),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(closed.style.color, dark.colorScheme.onSurface);
|
||||
});
|
||||
|
||||
testWidgets('Terminal\'s open row is unchanged: washed and framed', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(500, 400));
|
||||
await tester.pumpWidget(rows(design: AppDesign.terminal));
|
||||
final bar = tester.widget<DecoratedBox>(
|
||||
find.byKey(appListRowSelectionKey),
|
||||
);
|
||||
final border =
|
||||
(bar.decoration as BoxDecoration).border! as BorderDirectional;
|
||||
expect(border.start.width, kAppListRowBarWidth);
|
||||
expect(border.top.width, 1);
|
||||
});
|
||||
});
|
||||
|
||||
group('200% text scale: nothing overflows', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('transcript, rows and the design picker on a phone '
|
||||
'(${brightness.name})', (tester) async {
|
||||
_size(tester, const Size(360, 2400));
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ListView(
|
||||
children: [
|
||||
for (final row in _rows) ChatMessageView(row: row),
|
||||
AppListRow(
|
||||
selected: true,
|
||||
leading: const AppListAvatar(child: Icon(Icons.check)),
|
||||
title: const Text('Release train run with a long title'),
|
||||
subtitle: const Text('release-train · 30m 0s · v4'),
|
||||
detail: const Text('Release 2.4 shipped; notes published.'),
|
||||
time: '09:12',
|
||||
menu: IconButton(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.more_vert),
|
||||
),
|
||||
onTap: () {},
|
||||
),
|
||||
SettingsDesignSection(
|
||||
controller: AppDesignController(
|
||||
store: MemoryAppDesignStore(AppDesign.highContrast.id),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
brightness: brightness,
|
||||
textScale: 2,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Done'), findsOneWidget);
|
||||
expect(find.text('High contrast'), findsWidgets);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -80,6 +80,8 @@ void main() {
|
||||
expect(tokens.flat, isTrue);
|
||||
expect(tokens.frame, theme.colorScheme.outlineVariant);
|
||||
expect(tokens.monochrome, theme.colorScheme.onSurface);
|
||||
// Live switches snap: a blended glow hung skwasm.
|
||||
expect(tokens.snapSwitch, isTrue);
|
||||
expect(tokens.screen, isNotNull);
|
||||
expect(tokens.ansi, isNotNull);
|
||||
final dialog = theme.dialogTheme.shape! as RoundedRectangleBorder;
|
||||
|
||||
Reference in New Issue
Block a user