Merge branch 'worktree-agent-a1275d0f5d434eccb'
This commit is contained in:
@@ -3,9 +3,11 @@ import 'package:flutter/foundation.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/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
@@ -237,8 +239,8 @@ void main() {
|
||||
final host =
|
||||
'${platform == TargetPlatform.iOS ? 'Cupertino' : 'Material'} '
|
||||
'${brightness.name}';
|
||||
testWidgets('$host: a coloured chat washes its top; the info sheet '
|
||||
'changes the colour', (tester) async {
|
||||
testWidgets('$host: a coloured chat tints its bar, with no wash; the '
|
||||
'info sheet changes the colour', (tester) async {
|
||||
final gateway = await _pumpShell(
|
||||
tester,
|
||||
const Size(1280, 800),
|
||||
@@ -247,37 +249,26 @@ void main() {
|
||||
);
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit1);
|
||||
expect(_thread('a'), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsOneWidget);
|
||||
final washRect = tester.getRect(
|
||||
find.byKey(const Key('chat-color-wash')),
|
||||
);
|
||||
final pane = tester.getRect(
|
||||
find.byKey(const ValueKey('chat-detail-pane')),
|
||||
);
|
||||
// The wash starts at the very top of the pane, the bar's top edge,
|
||||
// over the bar's scrim, and carries on below the bar to fade out.
|
||||
expect(washRect.top, pane.top);
|
||||
final bar = tester.getRect(find.byKey(const Key('chat-thread-header')));
|
||||
expect(bar.top, pane.top);
|
||||
expect(washRect.bottom, bar.bottom);
|
||||
final below = find.byKey(const Key('chat-color-wash-below'));
|
||||
expect(tester.getRect(below).top, bar.bottom);
|
||||
expect(tester.getRect(below).bottom, lessThan(pane.height / 4));
|
||||
LinearGradient gradientOf(Finder finder) =>
|
||||
(tester.widget<DecoratedBox>(finder).decoration as BoxDecoration)
|
||||
.gradient!
|
||||
as LinearGradient;
|
||||
final top = gradientOf(find.byKey(const Key('chat-color-wash')));
|
||||
final rest = gradientOf(below);
|
||||
expect(top.colors.first.a, greaterThan(0.15));
|
||||
expect(top.colors.first.a, lessThanOrEqualTo(0.25));
|
||||
// One continuous fade across the two parts.
|
||||
expect(rest.colors.first.a, closeTo(top.colors.last.a, 1e-6));
|
||||
expect(rest.colors.last.a, 0);
|
||||
|
||||
// A plain chat has none.
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit3);
|
||||
// The colour lives in the bar's pieces; the page has no wash.
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsNothing);
|
||||
expect(find.byKey(const Key('chat-color-wash-below')), findsNothing);
|
||||
final tint = tester.widget<ChatBarTintScope>(
|
||||
find.byKey(const Key('chat-bar-tint')),
|
||||
);
|
||||
final pill = tester.widget<GlassPill>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.byKey(const Key('chat-info')),
|
||||
matching: find.byType(GlassPill),
|
||||
)
|
||||
.first,
|
||||
);
|
||||
expect(pill.fill, tint.tint.fill);
|
||||
|
||||
// A plain chat keeps the neutral bar.
|
||||
await _ctrl(tester, LogicalKeyboardKey.digit3);
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('chat-info')));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -289,7 +280,7 @@ void main() {
|
||||
});
|
||||
await tester.tap(find.byKey(const Key('chat-info-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-color-wash')), findsOneWidget);
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
@@ -174,6 +175,55 @@ void main() {
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('each pane bar carries its own colour; inactive ones fade', (
|
||||
tester,
|
||||
) async {
|
||||
await _mount(tester, const Size(1800, 1000));
|
||||
final controller = tester
|
||||
.widget<ChatWorkspace>(find.byType(ChatWorkspace))
|
||||
.controller;
|
||||
ChatBarTint tintOf(String id) => tester
|
||||
.widget<ChatBarTintScope>(
|
||||
find.descendant(
|
||||
of: _thread(id),
|
||||
matching: find.byKey(const Key('chat-bar-tint')),
|
||||
),
|
||||
)
|
||||
.tint;
|
||||
ChatBarTint expected(String id, String color, {required bool inactive}) {
|
||||
final context = tester.element(_thread(id));
|
||||
return ChatBarTint.from(
|
||||
shade: chatColorShade(context, color)!,
|
||||
raised: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
dark: false,
|
||||
inactive: inactive,
|
||||
);
|
||||
}
|
||||
|
||||
// One pane alone is active.
|
||||
expect(tintOf('a'), expected('a', 'orange', inactive: false));
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tintOf('a'), expected('a', 'orange', inactive: true));
|
||||
expect(tintOf('b'), expected('b', 'teal', inactive: false));
|
||||
controller.activate(
|
||||
controller.panes.firstWhere((p) => p.sessionId == 'a').id,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tintOf('a'), expected('a', 'orange', inactive: false));
|
||||
expect(tintOf('b'), expected('b', 'teal', inactive: true));
|
||||
// A chat with no colour keeps the neutral bar in its pane.
|
||||
controller.splitActive('c', ChatSplitAxis.vertical);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.descendant(
|
||||
of: _thread('c'),
|
||||
matching: find.byKey(const Key('chat-bar-tint')),
|
||||
),
|
||||
findsNothing,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('wide panes leave the shared divider to the workspace', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
import 'dart:io';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.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/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
double _luminance(Color c) {
|
||||
double channel(double v) =>
|
||||
v <= 0.03928 ? v / 12.92 : math.pow((v + 0.055) / 1.055, 2.4).toDouble();
|
||||
return 0.2126 * channel(c.r) + 0.7152 * channel(c.g) + 0.0722 * channel(c.b);
|
||||
}
|
||||
|
||||
/// WCAG contrast of [a] against [b], both opaque.
|
||||
double _ratio(Color a, Color b) {
|
||||
final x = _luminance(a), y = _luminance(b);
|
||||
return (math.max(x, y) + 0.05) / (math.min(x, y) + 0.05);
|
||||
}
|
||||
|
||||
/// The colours one host draws a chat's bar and composer with.
|
||||
typedef _Host = ({Color page, Color raised, Color shade});
|
||||
|
||||
/// Every palette colour's shade on one host and brightness, read through
|
||||
/// the app's own [chatColorShade] under the app's theme.
|
||||
Future<Map<String, _Host>> _hostColours(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
required bool dark,
|
||||
}) async {
|
||||
final result = <String, _Host>{};
|
||||
final brightness = dark ? Brightness.dark : Brightness.light;
|
||||
Widget probe() => Builder(
|
||||
builder: (context) {
|
||||
for (final name in chatColorNames) {
|
||||
result[name] = (
|
||||
page: cupertino
|
||||
? AppColors.background.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surface,
|
||||
raised: cupertino
|
||||
? CupertinoColors.systemGrey5.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh,
|
||||
shade: chatColorShade(context, name)!,
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
theme: appCupertinoTheme.copyWith(brightness: brightness),
|
||||
home: probe(),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: dark ? appDarkTheme() : appLightTheme(),
|
||||
home: probe(),
|
||||
),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
void main() {
|
||||
final rows = <String>['host\ttheme\tcolour\tmeasure\tratio\tminimum'];
|
||||
|
||||
tearDownAll(() {
|
||||
final out = Platform.environment['CHAT_BAR_CONTRAST_OUT'];
|
||||
if (out != null) File(out).writeAsStringSync('${rows.join('\n')}\n');
|
||||
});
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
for (final dark in [false, true]) {
|
||||
final host = cupertino ? 'cupertino' : 'material';
|
||||
final theme = dark ? 'dark' : 'light';
|
||||
testWidgets('$host $theme: every chat colour meets AA in the bar and '
|
||||
'the focus ring', (tester) async {
|
||||
final colours = await _hostColours(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
dark: dark,
|
||||
);
|
||||
expect(colours.keys, chatColorNames);
|
||||
void check(String name, String what, double ratio, double minimum) {
|
||||
rows.add(
|
||||
'$host\t$theme\t$name\t$what\t'
|
||||
'${ratio.toStringAsFixed(2)}\t$minimum',
|
||||
);
|
||||
expect(
|
||||
ratio,
|
||||
greaterThanOrEqualTo(minimum),
|
||||
reason: '$host $theme $name: $what',
|
||||
);
|
||||
}
|
||||
|
||||
for (final MapEntry(key: name, value: c) in colours.entries) {
|
||||
for (final inactive in [false, true]) {
|
||||
final tint = ChatBarTint.from(
|
||||
shade: c.shade,
|
||||
raised: c.raised,
|
||||
dark: dark,
|
||||
inactive: inactive,
|
||||
);
|
||||
// The glass lies over the bar's scrim, the page's colour.
|
||||
final pill = Color.alphaBlend(tint.fill, c.page);
|
||||
check(
|
||||
name,
|
||||
inactive ? 'inactive bar label' : 'bar label',
|
||||
_ratio(tint.foreground, pill),
|
||||
4.5,
|
||||
);
|
||||
// Solid under the system's high-contrast setting.
|
||||
final solid = ChatBarTint.from(
|
||||
shade: c.shade,
|
||||
raised: c.raised,
|
||||
dark: dark,
|
||||
inactive: inactive,
|
||||
solid: true,
|
||||
);
|
||||
check(
|
||||
name,
|
||||
inactive ? 'inactive solid bar label' : 'solid bar label',
|
||||
_ratio(solid.foreground, solid.fill),
|
||||
4.5,
|
||||
);
|
||||
}
|
||||
final ring = chatSeededScheme(c.shade, dark: dark).primary;
|
||||
check(name, 'focus ring vs page', _ratio(ring, c.page), 3);
|
||||
final composer = Color.alphaBlend(
|
||||
c.raised.withValues(alpha: GlassPill.fillOpacity),
|
||||
c.page,
|
||||
);
|
||||
check(name, 'focus ring vs composer', _ratio(ring, composer), 3);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_control_style.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
/// A header in the app's theme, with one model-style control, Files, and an
|
||||
/// optional split-pane activity around it.
|
||||
Widget _header({
|
||||
required bool cupertino,
|
||||
String? color,
|
||||
Brightness brightness = Brightness.light,
|
||||
bool? inactive,
|
||||
}) {
|
||||
Widget header = ChatThreadHeader(
|
||||
title: 'Colour chat',
|
||||
folder: 'demo',
|
||||
onInfo: () {},
|
||||
showBack: true,
|
||||
onBack: () {},
|
||||
chatColor: color,
|
||||
controls: [
|
||||
Builder(
|
||||
builder: (context) => cupertino
|
||||
? CupertinoButton(
|
||||
onPressed: () {},
|
||||
child: chatBarCupertinoContent(context, const Text('Model')),
|
||||
)
|
||||
: TextButton(
|
||||
style: chatBarTextButtonStyle(context),
|
||||
onPressed: () {},
|
||||
child: const Text('Model'),
|
||||
),
|
||||
),
|
||||
],
|
||||
actions: [
|
||||
ChatBarAction(
|
||||
label: 'Files',
|
||||
onPressed: () {},
|
||||
materialIcon: Icons.folder_outlined,
|
||||
cupertinoIcon: CupertinoIcons.folder,
|
||||
),
|
||||
],
|
||||
);
|
||||
if (inactive != null) {
|
||||
header = ChatPaneActivity(inactive: inactive, child: header);
|
||||
}
|
||||
final body = Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: SizedBox(width: 900, height: 120, child: header),
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(
|
||||
theme: appCupertinoTheme.copyWith(brightness: brightness),
|
||||
home: CupertinoPageScaffold(child: body),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: brightness == Brightness.dark
|
||||
? appDarkTheme()
|
||||
: appLightTheme(),
|
||||
home: Scaffold(body: body),
|
||||
);
|
||||
}
|
||||
|
||||
Future<BuildContext> _pump(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
String? color,
|
||||
Brightness brightness = Brightness.light,
|
||||
bool? inactive,
|
||||
}) async {
|
||||
tester.view.physicalSize = const Size(1000, 400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
await tester.pumpWidget(
|
||||
_header(
|
||||
cupertino: cupertino,
|
||||
color: color,
|
||||
brightness: brightness,
|
||||
inactive: inactive,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return tester.element(find.byType(ChatThreadHeader));
|
||||
}
|
||||
|
||||
Color? _titleFill(WidgetTester tester) => tester
|
||||
.widget<GlassPill>(
|
||||
find
|
||||
.ancestor(
|
||||
of: find.byKey(const Key('chat-info')),
|
||||
matching: find.byType(GlassPill),
|
||||
)
|
||||
.first,
|
||||
)
|
||||
.fill;
|
||||
|
||||
Color? _textColor(WidgetTester tester, String text) =>
|
||||
tester.renderObject<RenderParagraph>(find.text(text)).text.style?.color;
|
||||
|
||||
Color? _iconIn(WidgetTester tester, Finder control) => IconTheme.of(
|
||||
tester.element(find.descendant(of: control, matching: find.byType(Icon))),
|
||||
).color;
|
||||
|
||||
final _files = find.byType(ChatBarAction);
|
||||
final _back = find.byKey(const Key('chat-back'));
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host: a chat with no colour keeps the neutral bar', (
|
||||
tester,
|
||||
) async {
|
||||
final context = await _pump(tester, cupertino: cupertino);
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsNothing);
|
||||
expect(find.byType(ChatBarTintScope), findsNothing);
|
||||
expect(_titleFill(tester), isNull);
|
||||
for (final pill in tester.widgetList<GlassPill>(find.byType(GlassPill))) {
|
||||
expect(pill.fill, isNull);
|
||||
}
|
||||
final neutral = cupertino
|
||||
? CupertinoColors.label.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant;
|
||||
expect(_textColor(tester, 'Model'), isSameColorAs(neutral));
|
||||
});
|
||||
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('$host ${brightness.name}: a coloured chat tints every '
|
||||
'glass piece and takes its foreground', (tester) async {
|
||||
final context = await _pump(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
color: 'teal',
|
||||
brightness: brightness,
|
||||
);
|
||||
final dark = brightness == Brightness.dark;
|
||||
final shade = chatColorShade(context, 'teal')!;
|
||||
final raised = cupertino
|
||||
? CupertinoColors.systemGrey5.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final expected = ChatBarTint.from(
|
||||
shade: shade,
|
||||
raised: raised,
|
||||
dark: dark,
|
||||
);
|
||||
expect(expected.fill.a, closeTo(GlassPill.fillOpacity, 1e-6));
|
||||
expect(
|
||||
expected.fill.withValues(alpha: 1),
|
||||
Color.alphaBlend(
|
||||
shade.withValues(alpha: dark ? chatBarTintDark : chatBarTintLight),
|
||||
raised,
|
||||
),
|
||||
);
|
||||
expect(
|
||||
expected.foreground,
|
||||
chatSeededScheme(shade, dark: dark).onPrimaryContainer,
|
||||
);
|
||||
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
|
||||
// Back, title, the control island and the Files island.
|
||||
final pills = tester.widgetList<GlassPill>(find.byType(GlassPill));
|
||||
expect(pills.length, greaterThanOrEqualTo(4));
|
||||
for (final pill in pills) {
|
||||
expect(pill.fill, expected.fill);
|
||||
}
|
||||
expect(_titleFill(tester), expected.fill);
|
||||
expect(_textColor(tester, 'Colour chat'), expected.foreground);
|
||||
expect(_textColor(tester, 'Model'), expected.foreground);
|
||||
expect(_iconIn(tester, _files), expected.foreground);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('$host: an inactive split pane fades its bar tint to half', (
|
||||
tester,
|
||||
) async {
|
||||
final context = await _pump(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
color: 'orange',
|
||||
inactive: true,
|
||||
);
|
||||
final shade = chatColorShade(context, 'orange')!;
|
||||
final raised = cupertino
|
||||
? CupertinoColors.systemGrey5.resolveFrom(context)
|
||||
: Theme.of(context).colorScheme.surfaceContainerHigh;
|
||||
final faded = ChatBarTint.from(
|
||||
shade: shade,
|
||||
raised: raised,
|
||||
dark: false,
|
||||
inactive: true,
|
||||
);
|
||||
expect(
|
||||
faded.fill.withValues(alpha: 1),
|
||||
Color.alphaBlend(
|
||||
shade.withValues(alpha: chatBarTintLight * chatBarInactiveFade),
|
||||
raised,
|
||||
),
|
||||
);
|
||||
expect(_titleFill(tester), faded.fill);
|
||||
|
||||
// The same pane turning active takes the full tint.
|
||||
await tester.pumpWidget(
|
||||
_header(cupertino: cupertino, color: 'orange', inactive: false),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final full = ChatBarTint.from(shade: shade, raised: raised, dark: false);
|
||||
expect(_titleFill(tester), full.fill);
|
||||
expect(full.fill, isNot(faded.fill));
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('Material: bar icons take the seeded onPrimaryContainer', (
|
||||
tester,
|
||||
) async {
|
||||
final context = await _pump(tester, cupertino: false, color: 'purple');
|
||||
final shade = chatColorShade(context, 'purple')!;
|
||||
final foreground = ColorScheme.fromSeed(
|
||||
seedColor: shade,
|
||||
).onPrimaryContainer;
|
||||
expect(_iconIn(tester, _back), foreground);
|
||||
expect(_iconIn(tester, _files), foreground);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino: the colour is the bar tint, so Back and Files take '
|
||||
'it natively', (tester) async {
|
||||
final context = await _pump(tester, cupertino: true, color: 'purple');
|
||||
final tint = chatBarTintOf(context, 'purple')!;
|
||||
final inBar = tester.element(_files);
|
||||
expect(CupertinoTheme.of(inBar).primaryColor, tint.foreground);
|
||||
expect(_iconIn(tester, _files), tint.foreground);
|
||||
// The stock Back draws its chevron in its text style's colour.
|
||||
final chevron = tester.element(
|
||||
find.descendant(of: _back, matching: find.byType(RichText)).first,
|
||||
);
|
||||
expect(
|
||||
DefaultTextStyle.of(chevron).style.color,
|
||||
isSameColorAs(tint.foreground),
|
||||
);
|
||||
// Outside the bar the theme's tint is untouched.
|
||||
expect(
|
||||
CupertinoTheme.of(context).primaryColor,
|
||||
isNot(tint.foreground),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -1,19 +1,22 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_bar_tint.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/composer_focus_ring.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
|
||||
/// The focus ring wrapping the composer pill: its outer glow and inner ring.
|
||||
({Color glow, BorderSide side}) _ring(WidgetTester tester) {
|
||||
/// The focus ring wrapping the composer pill: its stroke and (absent) glow.
|
||||
({Decoration? decoration, BorderSide side}) _ring(WidgetTester tester) {
|
||||
final container = tester.widget<AnimatedContainer>(
|
||||
find.byKey(const Key('chat-composer-focus-ring')),
|
||||
);
|
||||
final glow = (container.decoration! as ShapeDecoration).shadows!.single;
|
||||
final shape = (container.foregroundDecoration! as ShapeDecoration).shape;
|
||||
return (glow: glow.color, side: (shape as RoundedRectangleBorder).side);
|
||||
return (
|
||||
decoration: container.decoration,
|
||||
side: (shape as RoundedRectangleBorder).side,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _focusField(WidgetTester tester) async {
|
||||
@@ -27,17 +30,20 @@ void main() {
|
||||
setUp(() => gateway = ComposerBarGateway()..page = fixtureTurn());
|
||||
tearDown(() => gateway.close());
|
||||
|
||||
testWidgets('unfocused composer draws no ring or glow', (tester) async {
|
||||
testWidgets('unfocused composer draws no ring and never a glow', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final ring = _ring(tester);
|
||||
expect(ring.side.color.a, 0);
|
||||
expect(ring.glow.a, 0);
|
||||
expect(ring.decoration, isNull);
|
||||
expect(ring.side.width, ComposerFocusRing.ringWidth);
|
||||
expect(ComposerFocusRing.ringWidth, 2);
|
||||
});
|
||||
|
||||
testWidgets('focused composer takes the primary colour as its ring', (
|
||||
testWidgets('focused composer rings in the primary colour, opaque', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
@@ -48,15 +54,12 @@ void main() {
|
||||
tester.element(find.byKey(const Key('chat-composer-field'))),
|
||||
).colorScheme.primary;
|
||||
final ring = _ring(tester);
|
||||
expect(
|
||||
ring.side.color,
|
||||
primary.withValues(alpha: ComposerFocusRing.ringOpacity),
|
||||
);
|
||||
expect(ring.glow, primary.withValues(alpha: ComposerFocusRing.glowOpacity));
|
||||
expect(ring.side.width, ComposerFocusRing.ringWidth);
|
||||
expect(ring.side.color, primary);
|
||||
expect(ring.side.color.a, 1);
|
||||
expect(ring.decoration, isNull);
|
||||
});
|
||||
|
||||
testWidgets('a coloured chat lends its own shade to the ring', (
|
||||
testWidgets('a coloured chat rings in its seeded scheme primary', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
@@ -65,14 +68,13 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
await _focusField(tester);
|
||||
|
||||
final teal = chatColorShade(
|
||||
tester.element(find.byKey(const Key('chat-composer-field'))),
|
||||
'teal',
|
||||
)!;
|
||||
expect(
|
||||
_ring(tester).side.color,
|
||||
teal.withValues(alpha: ComposerFocusRing.ringOpacity),
|
||||
);
|
||||
final context = tester.element(find.byKey(const Key('chat-composer-field')));
|
||||
final teal = chatColorShade(context, 'teal')!;
|
||||
final expected = chatSeededScheme(teal, dark: false).primary;
|
||||
expect(_ring(tester).side.color, expected);
|
||||
expect(chatFocusRingColor(context, 'teal'), expected);
|
||||
// Not the raw shade: tone 40 of the hue, so it keeps 3:1 on the page.
|
||||
expect(expected, isNot(teal));
|
||||
});
|
||||
|
||||
testWidgets('the ring fades out again when focus leaves', (tester) async {
|
||||
@@ -88,7 +90,7 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(_ring(tester).side.color.a, 0);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_ring(tester).glow.a, 0);
|
||||
expect(_ring(tester).side.color.a, 0);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino composer rings in the theme primary colour', (
|
||||
@@ -101,9 +103,6 @@ void main() {
|
||||
final primary = CupertinoTheme.of(
|
||||
tester.element(find.byKey(const Key('chat-composer-field'))),
|
||||
).primaryColor;
|
||||
expect(
|
||||
_ring(tester).side.color,
|
||||
primary.withValues(alpha: ComposerFocusRing.ringOpacity),
|
||||
);
|
||||
expect(_ring(tester).side.color, isSameColorAs(primary));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user