Narrow chat tests to Material hosts
Remove Cupertino-only fixtures, test variants, and the obsolete readable-text test now that the app is Material-only. Preserve the Material coverage while avoiding unreachable platform branches.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -11,12 +10,10 @@ import 'chat_thread_fixtures.dart';
|
||||
|
||||
/// Floating composer, reading width and header controls of a conversation.
|
||||
|
||||
Widget _host(Widget child, {required bool cupertino}) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||
: MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
Widget _host(Widget child) => MaterialApp(
|
||||
theme: ThemeData(platform: TargetPlatform.android),
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
|
||||
void _size(WidgetTester tester, Size size) {
|
||||
tester.view.physicalSize = size;
|
||||
@@ -38,7 +35,6 @@ List<Map<String, dynamic>> _messages(int count) => [
|
||||
|
||||
Future<FakeChatGateway> _pump(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
int messages = 30,
|
||||
Map<String, dynamic>? session,
|
||||
}) async {
|
||||
@@ -55,7 +51,6 @@ Future<FakeChatGateway> _pump(
|
||||
session: session,
|
||||
onBack: () {},
|
||||
),
|
||||
cupertino: cupertino,
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -64,215 +59,146 @@ Future<FakeChatGateway> _pump(
|
||||
|
||||
void main() {
|
||||
// The mode control is Material only.
|
||||
for (final cupertino in [false]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
testWidgets('transcript viewport ends at the composer top', (tester) async {
|
||||
_size(tester, const Size(560, 800));
|
||||
await _pump(tester);
|
||||
|
||||
testWidgets('$host transcript viewport ends at the composer top', (
|
||||
final pill = find.byKey(const Key('chat-composer-pill'));
|
||||
expect(tester.widget(pill), isA<GlassPill>());
|
||||
Rect list() => tester.getRect(find.byKey(const ValueKey('chat-thread-s')));
|
||||
Rect composer() => tester.getRect(find.byKey(const Key('chat-composer')));
|
||||
Rect header() =>
|
||||
tester.getRect(find.byKey(const Key('chat-thread-header')));
|
||||
// The transcript has its own viewport below the complete header.
|
||||
expect(list().top, greaterThanOrEqualTo(header().bottom));
|
||||
// Nothing renders behind the composer: the viewport stops at its top.
|
||||
expect(list().bottom, composer().top);
|
||||
expect(composer().bottom, lessThanOrEqualTo(800));
|
||||
expect(tester.getRect(pill).top, greaterThanOrEqualTo(list().bottom));
|
||||
|
||||
// Following the end, the last message rests fully above the composer.
|
||||
final last = find.text('Message number 29 of the transcript.');
|
||||
expect(tester.getRect(last).bottom, lessThanOrEqualTo(composer().top));
|
||||
|
||||
// A multi-line draft grows the composer; the viewport shrinks with it
|
||||
// and the newest message stays in view above it.
|
||||
final oneLine = composer().top;
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
List.generate(6, (index) => 'Draft line $index').join('\n'),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(composer().top, lessThan(oneLine));
|
||||
expect(list().bottom, composer().top);
|
||||
expect(tester.getRect(last).bottom, lessThanOrEqualTo(composer().top));
|
||||
|
||||
// Scrolling back up moves history down inside the shortened viewport.
|
||||
final rested = tester.getRect(last).top;
|
||||
await tester.drag(
|
||||
find.byKey(const ValueKey('chat-thread-s')),
|
||||
const Offset(0, 120),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
if (last.evaluate().isNotEmpty) {
|
||||
expect(tester.getRect(last).top, greaterThan(rested));
|
||||
}
|
||||
expect(list().bottom, composer().top);
|
||||
expect(list().top, greaterThanOrEqualTo(header().bottom));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('transcript and composer share a centred reading width', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(1200, 800));
|
||||
await _pump(tester, messages: 4);
|
||||
|
||||
final pill = tester.getRect(find.byKey(const Key('chat-composer-pill')));
|
||||
expect(pill.width, lessThanOrEqualTo(kChatReadingWidth));
|
||||
expect(pill.center.dx, closeTo(600, 1));
|
||||
final message = tester.getRect(
|
||||
find.text('Message number 0 of the transcript.'),
|
||||
);
|
||||
final inset = chatReadingInset(1200);
|
||||
expect(message.left, greaterThanOrEqualTo(inset));
|
||||
expect(message.right, lessThanOrEqualTo(1200 - inset));
|
||||
// The list itself still spans the window, so its margins scroll it.
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('chat-thread-s'))).width,
|
||||
1200,
|
||||
);
|
||||
|
||||
// Narrow, the column fills the width less the usual margins.
|
||||
_size(tester, const Size(560, 800));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('chat-composer-pill'))).width,
|
||||
560 - 32,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('header draws no empty pill without model or mode', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(560, 800));
|
||||
await _pump(
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(560, 800));
|
||||
await _pump(tester, cupertino: cupertino);
|
||||
messages: 1,
|
||||
session: const {'id': 's', 'backend': 'pi', 'directory': '/srv'},
|
||||
);
|
||||
final header = find.byKey(const Key('chat-thread-header'));
|
||||
expect(find.byKey(const Key('chat-mode')), findsNothing);
|
||||
// The round Back, the title pill and the actions pill, which always
|
||||
// carries the Files toggle, so it is never drawn empty.
|
||||
expect(
|
||||
find.descendant(of: header, matching: find.byType(SegmentedPill)),
|
||||
findsNWidgets(3),
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: header,
|
||||
matching: find.bySemanticsIdentifier('chat-files-toggle'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
final pill = find.byKey(const Key('chat-composer-pill'));
|
||||
expect(tester.widget(pill), isA<GlassPill>());
|
||||
Rect list() =>
|
||||
tester.getRect(find.byKey(const ValueKey('chat-thread-s')));
|
||||
Rect composer() => tester.getRect(find.byKey(const Key('chat-composer')));
|
||||
Rect header() =>
|
||||
tester.getRect(find.byKey(const Key('chat-thread-header')));
|
||||
// The transcript has its own viewport below the complete header.
|
||||
expect(list().top, greaterThanOrEqualTo(header().bottom));
|
||||
// Nothing renders behind the composer: the viewport stops at its top.
|
||||
expect(list().bottom, composer().top);
|
||||
expect(composer().bottom, lessThanOrEqualTo(800));
|
||||
expect(tester.getRect(pill).top, greaterThanOrEqualTo(list().bottom));
|
||||
|
||||
// Following the end, the last message rests fully above the composer.
|
||||
final last = find.text('Message number 29 of the transcript.');
|
||||
expect(tester.getRect(last).bottom, lessThanOrEqualTo(composer().top));
|
||||
|
||||
// A multi-line draft grows the composer; the viewport shrinks with it
|
||||
// and the newest message stays in view above it.
|
||||
final oneLine = composer().top;
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('chat-composer-field')),
|
||||
List.generate(6, (index) => 'Draft line $index').join('\n'),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(composer().top, lessThan(oneLine));
|
||||
expect(list().bottom, composer().top);
|
||||
expect(tester.getRect(last).bottom, lessThanOrEqualTo(composer().top));
|
||||
|
||||
// Scrolling back up moves history down inside the shortened viewport.
|
||||
final rested = tester.getRect(last).top;
|
||||
await tester.drag(
|
||||
find.byKey(const ValueKey('chat-thread-s')),
|
||||
const Offset(0, 120),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
if (last.evaluate().isNotEmpty) {
|
||||
expect(tester.getRect(last).top, greaterThan(rested));
|
||||
}
|
||||
expect(list().bottom, composer().top);
|
||||
expect(list().top, greaterThanOrEqualTo(header().bottom));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('$host transcript and composer share a centred reading width', (
|
||||
testWidgets('header controls keep their natural width when wide', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(1200, 800));
|
||||
await _pump(
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(1200, 800));
|
||||
await _pump(tester, cupertino: cupertino, messages: 4);
|
||||
|
||||
final pill = tester.getRect(find.byKey(const Key('chat-composer-pill')));
|
||||
expect(pill.width, lessThanOrEqualTo(kChatReadingWidth));
|
||||
expect(pill.center.dx, closeTo(600, 1));
|
||||
final message = tester.getRect(
|
||||
find.text('Message number 0 of the transcript.'),
|
||||
);
|
||||
final inset = chatReadingInset(1200);
|
||||
expect(message.left, greaterThanOrEqualTo(inset));
|
||||
expect(message.right, lessThanOrEqualTo(1200 - inset));
|
||||
// The list itself still spans the window, so its margins scroll it.
|
||||
expect(
|
||||
tester.getRect(find.byKey(const ValueKey('chat-thread-s'))).width,
|
||||
1200,
|
||||
);
|
||||
|
||||
// Narrow, the column fills the width less the usual margins.
|
||||
_size(tester, const Size(560, 800));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('chat-composer-pill'))).width,
|
||||
560 - 32,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('$host header draws no empty pill without model or mode', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(560, 800));
|
||||
await _pump(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
messages: 1,
|
||||
session: const {'id': 's', 'backend': 'pi', 'directory': '/srv'},
|
||||
);
|
||||
final header = find.byKey(const Key('chat-thread-header'));
|
||||
expect(find.byKey(const Key('chat-mode')), findsNothing);
|
||||
// The round Back, the title pill and the actions pill, which always
|
||||
// carries the Files toggle, so it is never drawn empty.
|
||||
expect(
|
||||
find.descendant(of: header, matching: find.byType(SegmentedPill)),
|
||||
findsNWidgets(3),
|
||||
);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: header,
|
||||
matching: find.bySemanticsIdentifier('chat-files-toggle'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('$host header controls keep their natural width when wide', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, const Size(1200, 800));
|
||||
await _pump(
|
||||
tester,
|
||||
cupertino: cupertino,
|
||||
messages: 1,
|
||||
session: const {
|
||||
'id': 's',
|
||||
'backend': 'opencode',
|
||||
'model': 'p/sonnet-4-5',
|
||||
'mode': 'default',
|
||||
'mode_name': 'Ask for permission',
|
||||
},
|
||||
);
|
||||
final mode = find.byKey(const Key('chat-mode'));
|
||||
final model = find.byKey(const Key('chat-model'));
|
||||
expect(mode, findsOneWidget);
|
||||
expect(model, findsOneWidget);
|
||||
for (final control in [mode, model]) {
|
||||
final texts = find.descendant(of: control, matching: find.byType(Text));
|
||||
for (final element in texts.evaluate()) {
|
||||
final paragraph = element.renderObject! as RenderParagraph;
|
||||
expect(
|
||||
paragraph.didExceedMaxLines,
|
||||
isFalse,
|
||||
reason: 'truncated at 1200',
|
||||
);
|
||||
}
|
||||
}
|
||||
// Neutral like the bar's other actions, not the primary tint.
|
||||
if (!cupertino) {
|
||||
final button = tester.widget<TextButton>(mode);
|
||||
final theme = Theme.of(tester.element(mode));
|
||||
expect(
|
||||
button.style!.foregroundColor!.resolve({}),
|
||||
theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
} else {
|
||||
final label = tester.widget<RichText>(
|
||||
find.descendant(
|
||||
of: mode,
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is RichText &&
|
||||
widget.text.toPlainText() == 'Ask for permission',
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(
|
||||
label.text.style?.color,
|
||||
CupertinoColors.label.resolveFrom(tester.element(mode)),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Cupertino narrow header exposes the current permission on its icon',
|
||||
(tester) async {
|
||||
if (!cupertino) return;
|
||||
final semantics = tester.ensureSemantics();
|
||||
_size(tester, const Size(560, 800));
|
||||
await _pump(
|
||||
tester,
|
||||
cupertino: true,
|
||||
messages: 1,
|
||||
session: const {
|
||||
'id': 's',
|
||||
'backend': 'opencode',
|
||||
'model': 'p/sonnet-4-5',
|
||||
'mode': 'default',
|
||||
'mode_name': 'Ask for permission',
|
||||
},
|
||||
);
|
||||
|
||||
final mode = find.byKey(const Key('chat-mode'));
|
||||
expect(mode, findsOneWidget);
|
||||
expect(
|
||||
find.descendant(of: mode, matching: find.text('Ask for permission')),
|
||||
findsNothing,
|
||||
);
|
||||
expect(
|
||||
tester.getSemantics(mode).label,
|
||||
contains('Change mode, currently Ask for permission'),
|
||||
);
|
||||
await tester.tap(mode);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-mode-sheet')), findsOneWidget);
|
||||
// The fixture has no chat_modes catalog, but the recorded session mode
|
||||
// remains visible in the sheet.
|
||||
expect(
|
||||
find.byKey(const ValueKey('chat-mode-option-default')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Ask for permission'), findsWidgets);
|
||||
semantics.dispose();
|
||||
messages: 1,
|
||||
session: const {
|
||||
'id': 's',
|
||||
'backend': 'opencode',
|
||||
'model': 'p/sonnet-4-5',
|
||||
'mode': 'default',
|
||||
'mode_name': 'Ask for permission',
|
||||
},
|
||||
);
|
||||
}
|
||||
final mode = find.byKey(const Key('chat-mode'));
|
||||
final model = find.byKey(const Key('chat-model'));
|
||||
expect(mode, findsOneWidget);
|
||||
expect(model, findsOneWidget);
|
||||
for (final control in [mode, model]) {
|
||||
final texts = find.descendant(of: control, matching: find.byType(Text));
|
||||
for (final element in texts.evaluate()) {
|
||||
final paragraph = element.renderObject! as RenderParagraph;
|
||||
expect(
|
||||
paragraph.didExceedMaxLines,
|
||||
isFalse,
|
||||
reason: 'truncated at 1200',
|
||||
);
|
||||
}
|
||||
}
|
||||
// Neutral like the bar's other actions, not the primary tint.
|
||||
final button = tester.widget<TextButton>(mode);
|
||||
final theme = Theme.of(tester.element(mode));
|
||||
expect(
|
||||
button.style!.foregroundColor!.resolve({}),
|
||||
theme.colorScheme.onSurfaceVariant,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user