Remove Cupertino chat conversation branches

Keep the Material-only conversation implementation while preserving public Cupertino parameters for callers. Narrow affected tests to Material hosts so the dead platform paths are no longer exercised.
This commit is contained in:
2026-11-11 13:11:05 +00:00
parent 8f52c7ec55
commit 96de9f5bea
32 changed files with 812 additions and 2005 deletions
+100 -109
View File
@@ -226,124 +226,115 @@ Future<void> replyChatHistory(
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'a wide /chat/s1 deep link shows that thread beside the list and route Back returns to /chat ($cupertino)',
(tester) async {
tester.view.physicalSize = const Size(900, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
if (cupertino) {
tester.platformDispatcher.platformBrightnessTestValue =
Brightness.dark;
addTearDown(
tester.platformDispatcher.clearPlatformBrightnessTestValue,
);
}
testWidgets(
'a wide /chat/s1 deep link shows that thread beside the list and route Back returns to /chat',
(tester) async {
tester.view.physicalSize = const Size(900, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/s1')),
);
addTearDown(provider.dispose);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat/s1')),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
androidSupported: false,
server: webServer(),
client: client,
cupertino: cupertino,
routeInformationProvider: provider,
),
);
await tester.pump();
await tester.pumpWidget(
PipelinesApp(
androidSupported: false,
server: webServer(),
client: client,
cupertino: false,
routeInformationProvider: provider,
),
);
await tester.pump();
await replySessions(tester, channel);
await replySubscribe(tester, channel);
await replyHistory(tester, channel);
await tester.pumpAndSettle();
await replySessions(tester, channel);
await replySubscribe(tester, channel);
await replyHistory(tester, channel);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/s1');
expect(find.byType(ChatThreadView), findsOneWidget);
// The exact route names the session; the request carries the same id.
expect(requestOf(channel, 'chat_subscribe')!['chat_subscribe'], {
'session_id': 's1',
});
expect(requestOf(channel, 'chat_messages')!['chat_query'], {
'session_id': 's1',
'limit': 200,
'cursor': '',
});
expect(find.text('The stored reply stays readable.'), findsOneWidget);
expect(find.text('Ran 1 command'), findsOneWidget);
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
expect(find.text('Kept behind a native disclosure.'), findsNothing);
expect(provider.value.uri.path, '/chat/s1');
expect(find.byType(ChatThreadView), findsOneWidget);
// The exact route names the session; the request carries the same id.
expect(requestOf(channel, 'chat_subscribe')!['chat_subscribe'], {
'session_id': 's1',
});
expect(requestOf(channel, 'chat_messages')!['chat_query'], {
'session_id': 's1',
'limit': 200,
'cursor': '',
});
expect(find.text('The stored reply stays readable.'), findsOneWidget);
expect(find.text('Ran 1 command'), findsOneWidget);
expect(find.byKey(const Key('chat-turn-activity')), findsOneWidget);
expect(find.text('Kept behind a native disclosure.'), findsNothing);
// The shell bar stays over the list and tabs; the open chat draws its
// own floating bar in its pane, with no Back: the list beside it is the
// way out.
expect(find.byType(ChatSessionsScreen), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
// The shell's bar and the conversation's own header.
expect(find.byType(SegmentedBar), findsNWidgets(2));
expect(find.byType(AppBar), findsNothing);
expect(find.byType(CupertinoNavigationBar), findsNothing);
expect(find.byKey(const Key('chat-thread-header')), findsOneWidget);
expect(findNativeBack(), findsNothing);
// The shell bar stays over the list and tabs; the open chat draws its
// own floating bar in its pane, with no Back: the list beside it is the
// way out.
expect(find.byType(ChatSessionsScreen), findsOneWidget);
expect(find.byType(NavigationRail), findsNothing);
expect(find.byType(FloatingDestinationBar), findsOneWidget);
// The shell's bar and the conversation's own header.
expect(find.byType(SegmentedBar), findsNWidgets(2));
expect(find.byType(AppBar), findsNothing);
expect(find.byType(CupertinoNavigationBar), findsNothing);
expect(find.byKey(const Key('chat-thread-header')), findsOneWidget);
expect(findNativeBack(), findsNothing);
// A live frame updates the held thread.
channel.incoming.add(
jsonEncode({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'message_id': 'a1',
'kind': 'text',
'part': {'id': 'p2', 'type': 'text'},
'delta': 'A live line arrived.',
},
}),
);
await tester.pump();
await tester.pump();
expect(find.text('A live line arrived.'), findsOneWidget);
// A live frame updates the held thread.
channel.incoming.add(
jsonEncode({
'type': 'chat_event',
'chat_event': {
'session_id': 's1',
'message_id': 'a1',
'kind': 'text',
'part': {'id': 'p2', 'type': 'text'},
'delta': 'A live line arrived.',
},
}),
);
await tester.pump();
await tester.pump();
expect(find.text('A live line arrived.'), findsOneWidget);
// The thread's own bar carries its controls once: no second bar.
expect(find.byKey(const Key('chat-thread-header')), findsOneWidget);
// Browser Back to /chat clears the open pane and keeps the list.
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/chat')),
);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat');
expect(find.byType(ChatThreadView), findsNothing);
expect(find.byType(ChatSessionsScreen), findsOneWidget);
expect(find.text('Wire chat'), findsOneWidget);
expect(find.text('Select a chat to open it here.'), findsOneWidget);
// The thread's own bar carries its controls once: no second bar.
expect(find.byKey(const Key('chat-thread-header')), findsOneWidget);
// Browser Back to /chat clears the open pane and keeps the list.
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/chat')),
);
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat');
expect(find.byType(ChatThreadView), findsNothing);
expect(find.byType(ChatSessionsScreen), findsOneWidget);
expect(find.text('Wire chat'), findsOneWidget);
expect(find.text('Select a chat to open it here.'), findsOneWidget);
// Browser Forward re-opens the same session through its route.
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/chat/s1')),
);
await tester.pump();
expect(provider.value.uri.path, '/chat/s1');
await replySubscribe(tester, channel, index: 1);
await replyHistory(
tester,
channel,
index: 1,
text: 'Reopened from the route.',
);
expect(find.text('Reopened from the route.'), findsOneWidget);
// Browser Forward re-opens the same session through its route.
await provider.didPushRouteInformation(
RouteInformation(uri: Uri.parse('/chat/s1')),
);
await tester.pump();
expect(provider.value.uri.path, '/chat/s1');
await replySubscribe(tester, channel, index: 1);
await replyHistory(
tester,
channel,
index: 1,
text: 'Reopened from the route.',
);
expect(find.text('Reopened from the route.'), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
},
);
}
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
},
);
testWidgets(
'mobile Chats retap reopens the retained multi-pane workspace after tabs',
@@ -64,7 +64,7 @@ Future<_Gateway> _pumpShell(
MaterialApp(
theme: ThemeData(platform: platform, brightness: brightness),
home: AdaptiveShell(
cupertino: platform == TargetPlatform.iOS,
cupertino: false,
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
@@ -234,55 +234,50 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
for (final platform in [TargetPlatform.android, TargetPlatform.iOS]) {
for (final brightness in Brightness.values) {
final host =
'${platform == TargetPlatform.iOS ? 'Cupertino' : 'Material'} '
'${brightness.name}';
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),
platform: platform,
brightness: brightness,
);
await _ctrl(tester, LogicalKeyboardKey.digit1);
expect(_thread('a'), findsOneWidget);
// 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);
for (final brightness in Brightness.values) {
final host = 'Material ${brightness.name}';
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),
brightness: brightness,
);
await _ctrl(tester, LogicalKeyboardKey.digit1);
expect(_thread('a'), findsOneWidget);
// 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);
// 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();
expect(find.byKey(const Key('chat-color-section')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-color-blue')));
await tester.pumpAndSettle();
expect(gateway.calls.last.fields, {
'chat_query': {'session_id': 'r', 'color': 'blue'},
});
await tester.tap(find.byKey(const Key('chat-info-close')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
await tester.tap(find.byKey(const Key('chat-info')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-color-section')), findsOneWidget);
await tester.tap(find.byKey(const Key('chat-color-blue')));
await tester.pumpAndSettle();
expect(gateway.calls.last.fields, {
'chat_query': {'session_id': 'r', 'color': 'blue'},
});
}
await tester.tap(find.byKey(const Key('chat-info-close')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('chat-bar-tint')), findsOneWidget);
await tester.pumpWidget(const SizedBox.shrink());
});
}
}
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -31,9 +30,7 @@ class _FakePicker {
ChatPickedFile _file(String name, {int size = 3, String mime = 'text/plain'}) =>
ChatPickedFile(name: name, mime: mime, bytes: Uint8List(size));
Widget _host(Widget bar, {required bool cupertino}) => cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: bar))
: materialHost(bar);
Widget _host(Widget bar) => materialHost(bar);
void main() {
late ComposerBarGateway gateway;
@@ -68,49 +65,37 @@ void main() {
Future<void> pumpBar(
WidgetTester tester, {
ChatAttachmentPicker? picker,
bool cupertino = false,
}) async {
newComposer();
await tester.pumpWidget(
_host(
ChatComposerBar(composer: composer, running: false, picker: picker),
cupertino: cupertino,
),
);
await tester.pump();
}
for (final cupertino in [false, true]) {
testWidgets('picking a file shows its recorded name and removes it '
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
final fake = _FakePicker([
[_file('notes.txt')],
]);
await pumpBar(tester, picker: fake.picker, cupertino: cupertino);
testWidgets('picking a file shows its recorded name and removes it', (
tester,
) async {
final fake = _FakePicker([
[_file('notes.txt')],
]);
await pumpBar(tester, picker: fake.picker);
await tester.tap(find.byKey(const Key('chat-composer-attach')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-composer-attach')));
await tester.pumpAndSettle();
expect(fake.calls, 1);
expect(
find.byKey(const Key('chat-composer-attachments')),
findsOneWidget,
);
expect(find.text('notes.txt'), findsOneWidget);
expect(fake.calls, 1);
expect(find.byKey(const Key('chat-composer-attachments')), findsOneWidget);
expect(find.text('notes.txt'), findsOneWidget);
if (cupertino) {
await tester.tap(
find.byKey(const Key('chat-composer-attachment-remove-0')),
);
} else {
await tester.tap(find.byTooltip('Remove notes.txt'));
}
await tester.pump();
await tester.tap(find.byTooltip('Remove notes.txt'));
await tester.pump();
expect(find.text('notes.txt'), findsNothing);
expect(find.byKey(const Key('chat-composer-attachments')), findsNothing);
});
}
expect(find.text('notes.txt'), findsNothing);
expect(find.byKey(const Key('chat-composer-attachments')), findsNothing);
});
testWidgets('a file over the draft budget shows the draft refusal line', (
tester,
@@ -218,32 +203,28 @@ void main() {
expect(attach.onPressed, isNull);
});
for (final cupertino in [false, true]) {
testWidgets('a long attachment name fits a narrow 2x composer '
'(${cupertino ? 'cupertino' : 'material'})', (tester) async {
tester.view.physicalSize = const Size(640, 1200);
tester.view.devicePixelRatio = 2;
tester.platformDispatcher.textScaleFactorTestValue = 2;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
testWidgets('a long attachment name fits a narrow 2x composer', (
tester,
) async {
tester.view.physicalSize = const Size(640, 1200);
tester.view.devicePixelRatio = 2;
tester.platformDispatcher.textScaleFactorTestValue = 2;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
final name =
'a-very-long-recorded-attachment-name-that-must-not-overflow.pdf';
final fake = _FakePicker([
[_file(name)],
]);
await pumpBar(tester, picker: fake.picker, cupertino: cupertino);
final name =
'a-very-long-recorded-attachment-name-that-must-not-overflow.pdf';
final fake = _FakePicker([
[_file(name)],
]);
await pumpBar(tester, picker: fake.picker);
await tester.tap(find.byKey(const Key('chat-composer-attach')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-composer-attach')));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(find.text(name), findsOneWidget);
expect(
find.byKey(const Key('chat-composer-attachments')),
findsOneWidget,
);
});
}
expect(tester.takeException(), isNull);
expect(find.text(name), findsOneWidget);
expect(find.byKey(const Key('chat-composer-attachments')), findsOneWidget);
});
}
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -185,42 +184,4 @@ void main() {
expect(find.text('Thinking: Max'), findsOneWidget);
expect(changes.single.defaultEffort, 'max');
});
testWidgets('Cupertino uses an action sheet that reports a refusal', (
tester,
) async {
Widget app(ApiGateway gateway) => CupertinoApp(
home: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
trailing: ChatEffortControl(
gateway: gateway,
sessionId: 's',
session: _row(),
),
),
child: const SizedBox.shrink(),
),
);
final refusing = _EffortGateway(refuse: 'level refused');
await tester.pumpWidget(app(refusing));
await tester.tap(find.byKey(const Key('chat-effort')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsOneWidget);
await tester.tap(find.byKey(const ValueKey('chat-effort-option-low')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsOneWidget);
expect(find.textContaining('level refused'), findsOneWidget);
final gateway = _EffortGateway();
await tester.pumpWidget(app(gateway));
await tester.pumpAndSettle();
await tester.tapAt(const Offset(10, 10));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('chat-effort')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('chat-effort-option-xhigh')));
await tester.pumpAndSettle();
expect(find.byType(CupertinoActionSheet), findsNothing);
expect(gateway.requests.single['type'], 'chat_effort');
});
}
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/core/api_gateway.dart';
@@ -19,16 +18,6 @@ Widget materialHost(Widget child) => MaterialApp(
Widget scrollHost(Widget child) =>
materialHost(SingleChildScrollView(child: child));
Widget cupertinoHost(Widget child) => CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoPageScaffold(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: child,
),
),
);
List<JsonMap> fields() => [
{
'key': 'colour',
@@ -235,19 +224,6 @@ void main() {
expect(find.text('Send answer'), findsNothing);
});
testWidgets('Cupertino field labels stay subordinate to the card title', (
tester,
) async {
await tester.pumpWidget(
cupertinoHost(
ChatQuestionCard(form: question(), onSubmit: (_, _) async {}),
),
);
final title = tester.widget<Text>(find.text('A demo question'));
final label = tester.widget<Text>(find.text('Colour'));
expect(label.style!.fontSize, lessThan(title.style!.fontSize!));
});
testWidgets('a free-text input carries its visual label in semantics', (
tester,
) async {
@@ -424,29 +400,6 @@ void main() {
expect(find.text('kept'), findsOneWidget);
});
testWidgets('320px at 2x in dark Cupertino keeps native controls', (
tester,
) async {
tester.view.physicalSize = const Size(640, 1600);
tester.view.devicePixelRatio = 2;
tester.platformDispatcher.textScaleFactorTestValue = 2;
tester.platformDispatcher.platformBrightnessTestValue = Brightness.dark;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
addTearDown(tester.platformDispatcher.clearPlatformBrightnessTestValue);
await tester.pumpWidget(
cupertinoHost(
ChatQuestionCard(form: question(), onSubmit: (_, _) async {}),
),
);
expect(tester.takeException(), isNull);
expect(find.text('A demo question'), findsOneWidget);
expect(find.text('Send answer'), findsOneWidget);
expect(find.byType(Material), findsNothing);
});
testWidgets('a pushed form renders and sends one exact chat_answer', (
tester,
) async {
@@ -1,4 +1,3 @@
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_stop_icon.dart';
@@ -121,61 +120,55 @@ void main() {
await tester.pumpWidget(const SizedBox.shrink());
});
for (final cupertino in [false, true]) {
testWidgets(
'rotating Stop keeps its target and interrupt action; Send stays available ($cupertino)',
(tester) async {
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
final composer = ChatComposerController(
gateway,
's',
drafts: MemoryChatDraftStore(),
);
addTearDown(composer.dispose);
final running = ValueNotifier<bool>(true);
addTearDown(running.dispose);
final bar = ValueListenableBuilder<bool>(
valueListenable: running,
builder: (_, value, _) =>
ChatComposerBar(composer: composer, running: value),
);
await tester.pumpWidget(
cupertino
? CupertinoApp(
home: CupertinoPageScaffold(child: Center(child: bar)),
)
: MaterialApp(
home: Scaffold(body: Center(child: bar)),
),
);
// The composer pops in first; Stop's target is measured once it has.
await tester.pump(Motion.tabEntranceDuration);
final stop = find.byKey(const Key('chat-composer-stop'));
final target = tester.getRect(stop);
await tester.pump(const Duration(seconds: 3));
expect(tester.getRect(stop), target);
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
expect(
tester
.widget<RotationTransition>(
find.byKey(const Key('chat-stop-rotation')),
)
.turns
.value,
greaterThan(0),
);
await tester.tap(stop);
await tester.pump();
await tester.pump();
expect(gateway.interruptBodies, [
{'session_id': 's'},
]);
running.value = false;
await tester.pumpAndSettle();
expect(find.byType(ChatStopIcon), findsNothing);
expect(tester.binding.transientCallbackCount, 0);
},
);
}
testWidgets(
'rotating Stop keeps its target and interrupt action; Send stays available',
(tester) async {
final gateway = ComposerBarGateway();
addTearDown(gateway.close);
final composer = ChatComposerController(
gateway,
's',
drafts: MemoryChatDraftStore(),
);
addTearDown(composer.dispose);
final running = ValueNotifier<bool>(true);
addTearDown(running.dispose);
final bar = ValueListenableBuilder<bool>(
valueListenable: running,
builder: (_, value, _) =>
ChatComposerBar(composer: composer, running: value),
);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(body: Center(child: bar)),
),
);
// The composer pops in first; Stop's target is measured once it has.
await tester.pump(Motion.tabEntranceDuration);
final stop = find.byKey(const Key('chat-composer-stop'));
final target = tester.getRect(stop);
await tester.pump(const Duration(seconds: 3));
expect(tester.getRect(stop), target);
expect(find.byKey(const Key('chat-composer-primary')), findsOneWidget);
expect(
tester
.widget<RotationTransition>(
find.byKey(const Key('chat-stop-rotation')),
)
.turns
.value,
greaterThan(0),
);
await tester.tap(stop);
await tester.pump();
await tester.pump();
expect(gateway.interruptBodies, [
{'session_id': 's'},
]);
running.value = false;
await tester.pumpAndSettle();
expect(find.byType(ChatStopIcon), findsNothing);
expect(tester.binding.transientCallbackCount, 0);
},
);
}
@@ -19,15 +19,10 @@ const _session = <String, dynamic>{
'model_provider': 'p1',
};
Widget _host(Widget child, {required bool cupertino}) => cupertino
? CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
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 _useNarrowText(WidgetTester tester) {
tester.view.physicalSize = const Size(320, 640);
@@ -39,58 +34,49 @@ void _useNarrowText(WidgetTester tester) {
}
void main() {
for (final cupertino in [false, true]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} wide header uses one explicit control gap',
(tester) async {
tester.view.physicalSize = const Size(1440, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
testWidgets('wide header uses one explicit control gap', (tester) async {
tester.view.physicalSize = const Size(1440, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
Widget control(String key) =>
SizedBox(key: Key(key), width: 48, height: 48);
Widget control(String key) =>
SizedBox(key: Key(key), width: 48, height: 48);
await tester.pumpWidget(
_host(
ChatThreadHeader(
title: 'Chat',
folder: 'demo',
onInfo: () {},
controls: [
control('header-control-1'),
control('header-control-2'),
],
actions: [control('header-action-1'), control('header-action-2')],
moreActions: [
ChatBarAction(
label: 'More action',
onPressed: () {},
materialIcon: Icons.more_horiz,
cupertinoIcon: CupertinoIcons.ellipsis,
),
],
await tester.pumpWidget(
_host(
ChatThreadHeader(
title: 'Chat',
folder: 'demo',
onInfo: () {},
controls: [control('header-control-1'), control('header-control-2')],
actions: [control('header-action-1'), control('header-action-2')],
moreActions: [
ChatBarAction(
label: 'More action',
onPressed: () {},
materialIcon: Icons.more_horiz,
cupertinoIcon: CupertinoIcons.ellipsis,
),
cupertino: cupertino,
),
);
await tester.pumpAndSettle();
double gap(String left, String right) =>
tester.getTopLeft(find.byKey(Key(right))).dx -
tester.getTopRight(find.byKey(Key(left))).dx;
expect(gap('header-control-1', 'header-control-2'), 8);
expect(gap('header-control-2', 'header-action-1'), 8);
expect(gap('header-action-1', 'header-action-2'), 8);
expect(
tester.getTopLeft(find.byKey(segmentedMoreKey).first).dx -
tester.getTopRight(find.byKey(const Key('header-action-2'))).dx,
8,
);
},
],
),
),
);
}
await tester.pumpAndSettle();
double gap(String left, String right) =>
tester.getTopLeft(find.byKey(Key(right))).dx -
tester.getTopRight(find.byKey(Key(left))).dx;
expect(gap('header-control-1', 'header-control-2'), 8);
expect(gap('header-control-2', 'header-action-1'), 8);
expect(gap('header-action-1', 'header-action-2'), 8);
expect(
tester.getTopLeft(find.byKey(segmentedMoreKey).first).dx -
tester.getTopRight(find.byKey(const Key('header-action-2'))).dx,
8,
);
});
testWidgets('short large-text header keeps controls in its single row', (
tester,
@@ -116,7 +102,6 @@ void main() {
),
),
),
cupertino: false,
),
);
await tester.pumpAndSettle();
@@ -148,7 +133,6 @@ void main() {
session: _session,
onBack: () => backed++,
),
cupertino: false,
),
);
await tester.pumpAndSettle();
@@ -194,157 +178,134 @@ void main() {
);
// The mode control is Material only.
for (final cupertino in [false]) {
for (final width in [320.0, 390.0, 1280.0]) {
testWidgets(
'${cupertino ? 'Cupertino' : 'Material'} grouped actions at $width and text scale 2',
(tester) async {
_useNarrowText(tester);
tester.view.physicalSize = Size(width, 800);
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage(const []);
gateway.subscribe = () async => const {};
var sidebar = 0;
var pane = 0;
var next = 0;
await tester.pumpWidget(
_host(
ChatThreadView(
gateway: gateway,
sessionId: 's',
title: _title,
session: {
..._session,
'mode': 'safe',
'mode_name': 'Ask before making changes',
},
onBack: () {},
onNextChat: () => next++,
sidebarControl: ChatBarAction(
label: 'Sidebar action',
onPressed: () => sidebar++,
materialIcon: Icons.menu,
cupertinoIcon: CupertinoIcons.sidebar_left,
),
paneControls: [
ChatBarAction(
label: 'Pane action',
onPressed: () => pane++,
materialIcon: Icons.add_box,
cupertinoIcon: CupertinoIcons.plus_square,
),
],
),
cupertino: cupertino,
for (final width in [320.0, 390.0, 1280.0]) {
testWidgets('grouped actions at $width and text scale 2', (tester) async {
_useNarrowText(tester);
tester.view.physicalSize = Size(width, 800);
final gateway = FakeChatGateway();
addTearDown(gateway.close);
gateway.history = (_) async => chatPage(const []);
gateway.subscribe = () async => const {};
var sidebar = 0;
var pane = 0;
var next = 0;
await tester.pumpWidget(
_host(
ChatThreadView(
gateway: gateway,
sessionId: 's',
title: _title,
session: {
..._session,
'mode': 'safe',
'mode_name': 'Ask before making changes',
},
onBack: () {},
onNextChat: () => next++,
sidebarControl: ChatBarAction(
label: 'Sidebar action',
onPressed: () => sidebar++,
materialIcon: Icons.menu,
cupertinoIcon: CupertinoIcons.sidebar_left,
),
);
await tester.pumpAndSettle();
final selectors = find.byKey(
const Key('chat-model-permission-island'),
);
final actions = find.byKey(const Key('chat-actions-island'));
expect(selectors, findsOneWidget);
expect(actions, findsOneWidget);
expect(
(tester.getCenter(selectors).dy - tester.getCenter(actions).dy)
.abs(),
lessThan(16),
);
expect(find.byKey(const Key('chat-next')), findsNothing);
expect(find.text('Next chat'), findsNothing);
expect(find.byKey(const Key('chat-model')), findsOneWidget);
expect(find.byKey(const Key('chat-mode')), findsOneWidget);
if (width < 600) {
expect(find.text('model-a'), findsNothing);
expect(find.text('Ask before making changes'), findsNothing);
expect(find.byIcon(Icons.memory_outlined), findsOneWidget);
expect(
find.byIcon(
cupertino
? CupertinoIcons.shield_lefthalf_fill
: Icons.shield_outlined,
paneControls: [
ChatBarAction(
label: 'Pane action',
onPressed: () => pane++,
materialIcon: Icons.add_box,
cupertinoIcon: CupertinoIcons.plus_square,
),
findsOneWidget,
);
if (!cupertino) {
expect(
tester.getSemantics(find.byKey(const Key('chat-model'))).label,
contains('Change model, currently'),
);
expect(
tester.getSemantics(find.byKey(const Key('chat-mode'))).label,
contains('Change mode, currently'),
);
}
expect(
(tester.getCenter(selectors).dy - tester.getCenter(actions).dy)
.abs(),
lessThan(16),
);
}
for (final key in ['chat-model', 'chat-mode']) {
expect(
tester.getSize(find.byKey(Key(key))).width,
greaterThanOrEqualTo(cupertino ? 44 : 48),
);
}
expect(find.text('Sidebar action'), findsNothing);
expect(find.text('Pane action'), findsNothing);
expect(tester.takeException(), isNull);
// Both More entries retain their original callbacks in native menus.
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Sidebar action'));
await tester.pumpAndSettle();
expect(sidebar, 1);
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Pane action'));
await tester.pumpAndSettle();
expect(pane, 1);
expect(next, 0);
expect(tester.takeException(), isNull);
},
],
),
),
);
}
await tester.pumpAndSettle();
final selectors = find.byKey(const Key('chat-model-permission-island'));
final actions = find.byKey(const Key('chat-actions-island'));
expect(selectors, findsOneWidget);
expect(actions, findsOneWidget);
expect(
(tester.getCenter(selectors).dy - tester.getCenter(actions).dy).abs(),
lessThan(16),
);
expect(find.byKey(const Key('chat-next')), findsNothing);
expect(find.text('Next chat'), findsNothing);
expect(find.byKey(const Key('chat-model')), findsOneWidget);
expect(find.byKey(const Key('chat-mode')), findsOneWidget);
if (width < 600) {
expect(find.text('model-a'), findsNothing);
expect(find.text('Ask before making changes'), findsNothing);
expect(find.byIcon(Icons.memory_outlined), findsOneWidget);
expect(find.byIcon(Icons.shield_outlined), findsOneWidget);
expect(
tester.getSemantics(find.byKey(const Key('chat-model'))).label,
contains('Change model, currently'),
);
expect(
tester.getSemantics(find.byKey(const Key('chat-mode'))).label,
contains('Change mode, currently'),
);
expect(
(tester.getCenter(selectors).dy - tester.getCenter(actions).dy).abs(),
lessThan(16),
);
}
for (final key in ['chat-model', 'chat-mode']) {
expect(
tester.getSize(find.byKey(Key(key))).width,
greaterThanOrEqualTo(48),
);
}
expect(find.text('Sidebar action'), findsNothing);
expect(find.text('Pane action'), findsNothing);
expect(tester.takeException(), isNull);
// Both More entries retain their original callbacks in native menus.
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Sidebar action'));
await tester.pumpAndSettle();
expect(sidebar, 1);
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Pane action'));
await tester.pumpAndSettle();
expect(pane, 1);
expect(next, 0);
expect(tester.takeException(), isNull);
});
}
for (final cupertino in [false, true]) {
testWidgets(
'sidebar layout submenu retains callback on ${cupertino ? 'Cupertino' : 'Material'}',
(tester) async {
ChatSidebarMode? picked;
await tester.pumpWidget(
_host(
ChatThreadHeader(
title: 'Chat',
folder: 'demo',
onInfo: () {},
actions: const [Icon(Icons.folder_outlined)],
moreActions: [
ChatSidebarButton(
mode: ChatSidebarMode.expanded,
onChanged: (value) => picked = value,
),
],
testWidgets('sidebar layout submenu retains callback on Material', (
tester,
) async {
ChatSidebarMode? picked;
await tester.pumpWidget(
_host(
ChatThreadHeader(
title: 'Chat',
folder: 'demo',
onInfo: () {},
actions: const [Icon(Icons.folder_outlined)],
moreActions: [
ChatSidebarButton(
mode: ChatSidebarMode.expanded,
onChanged: (value) => picked = value,
),
cupertino: cupertino,
),
);
await tester.pumpAndSettle();
expect(find.byType(ChatSidebarButton), findsNothing);
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Chat list layout'));
await tester.pumpAndSettle();
await tester.tap(find.text('Hide chat list'));
await tester.pumpAndSettle();
expect(picked, ChatSidebarMode.hidden);
expect(tester.takeException(), isNull);
},
],
),
),
);
}
await tester.pumpAndSettle();
expect(find.byType(ChatSidebarButton), findsNothing);
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
await tester.pumpAndSettle();
await tester.tap(find.text('Chat list layout'));
await tester.pumpAndSettle();
await tester.tap(find.text('Hide chat list'));
await tester.pumpAndSettle();
expect(picked, ChatSidebarMode.hidden);
expect(tester.takeException(), isNull);
});
testWidgets('a conversation without a model keeps the same compact row', (
tester,
@@ -364,7 +325,6 @@ void main() {
session: {..._session, 'backend': 'other'},
onBack: () {},
),
cupertino: false,
),
);
await tester.pumpAndSettle();