7d9b6c1d1b
Prioritize the conversation title on narrow chat bars, move compact controls and overflow actions into More, and omit the duplicate title in floating windows. Add focused widget coverage for title sizing, icon dimensions, menus, and floating chrome.
192 lines
6.2 KiB
Dart
192 lines
6.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import '../../native_back.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/chat/screen.dart';
|
|
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart'
|
|
show segmentedMoreKey;
|
|
|
|
/// A chat destination gateway: one listed session whose harness offers models.
|
|
class _ScreenGateway implements ApiGateway {
|
|
final calls = <({String type, JsonMap fields})>[];
|
|
|
|
List<JsonMap> sessions = [
|
|
{
|
|
'id': 's',
|
|
'title': 'Wire chat',
|
|
'backend': 'opencode',
|
|
'model': 'model-a',
|
|
'model_provider': 'p1',
|
|
},
|
|
];
|
|
|
|
JsonMap switchReply = const {
|
|
'chat_model': {'session_id': 's', 'provider': 'p2', 'model': 'model-b'},
|
|
};
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream.empty();
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
|
calls.add((type: type, fields: fields));
|
|
switch (type) {
|
|
case 'chat_sessions':
|
|
return {'chat_sessions': sessions};
|
|
case 'chat_subscribe':
|
|
return <String, dynamic>{};
|
|
case 'chat_messages':
|
|
return {
|
|
'chat_history': {
|
|
'messages': const [],
|
|
'next_cursor': '',
|
|
'has_more': false,
|
|
},
|
|
};
|
|
case 'chat_models':
|
|
return const {
|
|
'chat_models': [
|
|
{'id': 'model-a', 'provider': 'p1', 'name': 'Model Alpha'},
|
|
{'id': 'model-b', 'provider': 'p2', 'name': 'Model Beta'},
|
|
],
|
|
};
|
|
case 'chat_model':
|
|
return switchReply;
|
|
}
|
|
return <String, dynamic>{};
|
|
}
|
|
|
|
int count(String type) => calls.where((call) => call.type == type).length;
|
|
}
|
|
|
|
Future<void> _pumpScreen(
|
|
WidgetTester tester,
|
|
_ScreenGateway gateway, {
|
|
String? initialSessionId,
|
|
}) async {
|
|
// The phone layout: an open chat is its own page with the native Back.
|
|
tester.view.physicalSize = const Size(390, 844);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
theme: ThemeData(platform: TargetPlatform.android),
|
|
home: Scaffold(
|
|
body: ChatScreen(gateway: gateway, initialSessionId: initialSessionId),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
/// A phone bar keeps the model in the More menu's settings sheet: opens it
|
|
/// (a wide bar shows the control already).
|
|
Future<void> _openSettings(WidgetTester tester) async {
|
|
if (find.byKey(const Key('chat-model')).evaluate().isNotEmpty) return;
|
|
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Chat settings'));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
/// Dismisses that sheet through its barrier, above the bar.
|
|
Future<void> _closeSettings(WidgetTester tester) async {
|
|
await tester.tapAt(const Offset(5, 5));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('an accepted switch survives leaving and reopening the chat', (
|
|
tester,
|
|
) async {
|
|
final gateway = _ScreenGateway();
|
|
await _pumpScreen(tester, gateway);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-row-s')));
|
|
await tester.pumpAndSettle();
|
|
await _openSettings(tester);
|
|
expect(find.byTooltip('Change model (currently model-a)'), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-model')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Model Beta'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byTooltip('Change model (currently model-b)'), findsOneWidget);
|
|
await _closeSettings(tester);
|
|
|
|
await tester.tap(findNativeBack());
|
|
await tester.pumpAndSettle();
|
|
expect(find.byTooltip('Change model (currently model-b)'), findsNothing);
|
|
|
|
// The list still carries the row it read before the switch; reopening must
|
|
// still show the model the server accepted.
|
|
await tester.tap(find.byKey(const Key('chat-row-s')));
|
|
await tester.pumpAndSettle();
|
|
await _openSettings(tester);
|
|
|
|
expect(find.byTooltip('Change model (currently model-b)'), findsOneWidget);
|
|
expect(find.byTooltip('Change model (currently model-a)'), findsNothing);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-model')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const Key('chat-model-option-p2/model-b')),
|
|
matching: find.byIcon(Icons.check),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const Key('chat-model-option-p1/model-a')),
|
|
matching: find.byIcon(Icons.check),
|
|
),
|
|
findsNothing,
|
|
);
|
|
});
|
|
|
|
testWidgets('a routed chat resolves its row from the loaded list', (
|
|
tester,
|
|
) async {
|
|
final gateway = _ScreenGateway();
|
|
await _pumpScreen(tester, gateway, initialSessionId: 's');
|
|
|
|
// The deep link opened before any row was tapped: the list's own read
|
|
// supplies the title and the recorded model, with no second list request.
|
|
expect(find.text('Wire chat'), findsOneWidget);
|
|
await _openSettings(tester);
|
|
expect(find.byTooltip('Change model (currently model-a)'), findsOneWidget);
|
|
expect(find.byKey(const Key('chat-model')), findsOneWidget);
|
|
expect(gateway.count('chat_sessions'), 1);
|
|
|
|
await tester.tap(find.byKey(const Key('chat-model')));
|
|
await tester.pumpAndSettle();
|
|
expect(gateway.calls.last.type, 'chat_models');
|
|
expect(gateway.calls.last.fields, {
|
|
'chat_query': {'session_id': 's'},
|
|
});
|
|
|
|
await tester.tap(find.text('Model Beta'));
|
|
await tester.pumpAndSettle();
|
|
expect(gateway.calls.last.fields, {
|
|
'chat_model': {'session_id': 's', 'provider': 'p2', 'model': 'model-b'},
|
|
});
|
|
expect(find.byTooltip('Change model (currently model-b)'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets(
|
|
'a routed chat on a harness without model switching stays plain',
|
|
(tester) async {
|
|
final gateway = _ScreenGateway()
|
|
..sessions = [
|
|
{'id': 's', 'title': 'Wire chat', 'backend': 'other'},
|
|
];
|
|
await _pumpScreen(tester, gateway, initialSessionId: 's');
|
|
|
|
expect(find.text('Wire chat'), findsOneWidget);
|
|
expect(find.byKey(const Key('chat-model')), findsNothing);
|
|
expect(gateway.count('chat_models'), 0);
|
|
},
|
|
);
|
|
}
|