Merge branch 'worktree-agent-a979f00543edb836c'
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
|
||||
import 'chat_composer_bar_fixtures.dart';
|
||||
|
||||
/// The phones: Fuchsia counts as a keyboard host (Enter sends), like desktop.
|
||||
final _phones = TargetPlatformVariant({
|
||||
TargetPlatform.android,
|
||||
TargetPlatform.iOS,
|
||||
});
|
||||
|
||||
double _bottomMargin(WidgetTester tester) {
|
||||
final padding = tester.widget<Padding>(
|
||||
find.byKey(const Key('chat-composer')),
|
||||
);
|
||||
return (padding.padding as EdgeInsetsDirectional).bottom;
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('phones keep the close bottom margin, desktops a wider one', () {
|
||||
expect(
|
||||
chatComposerBottomMargin(TargetPlatform.android),
|
||||
kChatComposerBottomMargin,
|
||||
);
|
||||
expect(
|
||||
chatComposerBottomMargin(TargetPlatform.iOS),
|
||||
kChatComposerBottomMargin,
|
||||
);
|
||||
for (final desktop in [
|
||||
TargetPlatform.macOS,
|
||||
TargetPlatform.windows,
|
||||
TargetPlatform.linux,
|
||||
]) {
|
||||
expect(
|
||||
chatComposerBottomMargin(desktop),
|
||||
kChatComposerDesktopBottomMargin,
|
||||
);
|
||||
}
|
||||
expect(
|
||||
kChatComposerDesktopBottomMargin,
|
||||
greaterThan(kChatComposerBottomMargin),
|
||||
);
|
||||
});
|
||||
|
||||
group('rendered composer', () {
|
||||
late ComposerBarGateway gateway;
|
||||
|
||||
setUp(() => gateway = ComposerBarGateway()..page = fixtureTurn());
|
||||
tearDown(() => gateway.close());
|
||||
|
||||
testWidgets(
|
||||
'keeps more room from a desktop window bottom',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_bottomMargin(tester), kChatComposerDesktopBottomMargin);
|
||||
},
|
||||
variant: TargetPlatformVariant.desktop(),
|
||||
);
|
||||
|
||||
testWidgets('stays close to a phone bottom', (tester) async {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_bottomMargin(tester), kChatComposerBottomMargin);
|
||||
}, variant: _phones);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.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) {
|
||||
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);
|
||||
}
|
||||
|
||||
Future<void> _focusField(WidgetTester tester) async {
|
||||
await tester.tap(find.byKey(const Key('chat-composer-field')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
late ComposerBarGateway gateway;
|
||||
|
||||
setUp(() => gateway = ComposerBarGateway()..page = fixtureTurn());
|
||||
tearDown(() => gateway.close());
|
||||
|
||||
testWidgets('unfocused composer draws no ring or 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.side.width, ComposerFocusRing.ringWidth);
|
||||
});
|
||||
|
||||
testWidgets('focused composer takes the primary colour as its ring', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await _focusField(tester);
|
||||
|
||||
final primary = Theme.of(
|
||||
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);
|
||||
});
|
||||
|
||||
testWidgets('a coloured chat lends its own shade to the ring', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
composerThread(gateway, session: {'id': 's', 'color': 'teal'}),
|
||||
);
|
||||
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),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the ring fades out again when focus leaves', (tester) async {
|
||||
await tester.pumpWidget(composerThread(gateway));
|
||||
await tester.pumpAndSettle();
|
||||
await _focusField(tester);
|
||||
expect(_ring(tester).side.color.a, greaterThan(0));
|
||||
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
// One frame applies the focus change, the next rebuilds the ring towards
|
||||
// its unfocused decoration, which the container then animates into.
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(_ring(tester).side.color.a, 0);
|
||||
await tester.pumpAndSettle();
|
||||
expect(_ring(tester).glow.a, 0);
|
||||
});
|
||||
|
||||
testWidgets('Cupertino composer rings in the theme primary colour', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(composerThread(gateway, cupertino: true));
|
||||
await tester.pumpAndSettle();
|
||||
await _focusField(tester);
|
||||
|
||||
final primary = CupertinoTheme.of(
|
||||
tester.element(find.byKey(const Key('chat-composer-field'))),
|
||||
).primaryColor;
|
||||
expect(
|
||||
_ring(tester).side.color,
|
||||
primary.withValues(alpha: ComposerFocusRing.ringOpacity),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user