130c1e6708
Chat stack is now the default phone chat navigation (a stored choice is kept), and on Android or iOS it stays on a wide layout (an unfolded foldable) above the active pane, where floating is ignored too. When expanded, the pile turns into a close button at its own spot and the column rises above it; while a chat is dragged that button is the remove target, replacing the separate x at the bottom. Chat widget tests start on Quick switch (they run as Android); the stack's tests choose it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
176 lines
6.2 KiB
Dart
176 lines
6.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/chat/screen.dart';
|
|
import 'package:pipelines_app/features/chat/stack/chat_stack_entry.dart';
|
|
import 'package:pipelines_app/features/chat/stack/mobile_chat_navigation.dart';
|
|
import 'package:pipelines_app/features/chat/workspace/chat_peek_header.dart';
|
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
|
import 'package:pipelines_app/shell/destination.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../conversation/chat_thread_fixtures.dart';
|
|
|
|
const _rows = <JsonMap>[
|
|
{'id': 'a', 'title': 'Alpha', 'directory': '/w', 'color': 'teal'},
|
|
{'id': 'b', 'title': 'Beta', 'directory': '/w'},
|
|
{'id': 'c', 'title': 'Gamma', 'directory': '/v'},
|
|
];
|
|
|
|
class _Gateway extends FakeChatGateway {
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
|
if (type == 'chat_sessions') {
|
|
return Future.value({
|
|
'chat_sessions': [
|
|
for (final row in _rows) {...row},
|
|
],
|
|
});
|
|
}
|
|
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
|
return super.call(type, fields);
|
|
}
|
|
}
|
|
|
|
class _Store implements MobileChatNavigationStore {
|
|
_Store(this.value);
|
|
final String? value;
|
|
@override
|
|
Future<String?> load() async => value;
|
|
@override
|
|
Future<bool> save(String value) async => true;
|
|
}
|
|
|
|
Future<void> _pump(WidgetTester tester, Size size) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
unawaited(
|
|
MobileChatNavigationController.instance.setValue(
|
|
MobileChatNavigation.chatStack,
|
|
),
|
|
);
|
|
tester.view.physicalSize = size;
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
final gateway = _Gateway()..history = (_) async => chatPage(const []);
|
|
addTearDown(gateway.close);
|
|
final route = ValueNotifier<String?>(null);
|
|
addTearDown(route.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: AdaptiveShell(
|
|
destination: AppDestination.chat,
|
|
destinationBodies: {
|
|
AppDestination.chat: (_) => ValueListenableBuilder<String?>(
|
|
valueListenable: route,
|
|
builder: (context, id, _) => ChatScreen(
|
|
gateway: gateway,
|
|
initialSessionId: id,
|
|
onSessionSelected: (next) => route.value = next,
|
|
onBack: () => route.value = null,
|
|
),
|
|
),
|
|
},
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
Finder _thread(String id) => find.byKey(ValueKey('chat-thread-$id'));
|
|
final _stack = find.byKey(const Key('chat-stack'));
|
|
|
|
void main() {
|
|
final navigation = MobileChatNavigationController.instance;
|
|
tearDown(() {
|
|
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
|
|
});
|
|
|
|
testWidgets('the setting swaps the peek for the stack, live', (tester) async {
|
|
await _pump(tester, const Size(390, 844));
|
|
await tester.tap(find.byKey(const Key('chat-row-a')));
|
|
await tester.pumpAndSettle();
|
|
expect(_thread('a'), findsOneWidget);
|
|
expect(_stack.hitTestable(), findsOneWidget);
|
|
expect(find.bySemanticsLabel(chatStackLabel(1)), findsOneWidget);
|
|
|
|
// Add chat picks a chat that is not open and opens it.
|
|
await tester.tap(_stack);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Beta').last);
|
|
await tester.pumpAndSettle();
|
|
expect(_thread('b').hitTestable(), findsOneWidget);
|
|
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
|
|
// The stack replaces the peek.
|
|
expect(find.byType(ChatPeekHeader), findsNothing);
|
|
|
|
// A chat in the column opens as its list row would.
|
|
await tester.tap(_stack);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Alpha').last);
|
|
await tester.pumpAndSettle();
|
|
expect(_thread('a').hitTestable(), findsOneWidget);
|
|
expect(_stack.hitTestable(), findsOneWidget);
|
|
|
|
// Back to Quick switch: the peek returns, the stack leaves.
|
|
unawaited(navigation.setValue(MobileChatNavigation.quickSwitch));
|
|
await tester.pumpAndSettle();
|
|
expect(_stack, findsNothing);
|
|
expect(find.byType(ChatPeekHeader), findsOneWidget);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
});
|
|
|
|
testWidgets(
|
|
'a wide desktop window keeps its panes and shows no stack',
|
|
variant: TargetPlatformVariant.desktop(),
|
|
(tester) async {
|
|
await _pump(tester, const Size(1280, 800));
|
|
await tester.tap(find.byKey(const Key('chat-row-a')));
|
|
await tester.pumpAndSettle();
|
|
expect(_thread('a'), findsOneWidget);
|
|
expect(_stack, findsNothing);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
'a wide phone or tablet layout (an unfolded foldable) keeps the stack',
|
|
variant: TargetPlatformVariant({
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
(tester) async {
|
|
await _pump(tester, const Size(1280, 800));
|
|
await tester.tap(find.byKey(const Key('chat-row-a')));
|
|
await tester.pumpAndSettle();
|
|
expect(_thread('a'), findsOneWidget);
|
|
// The list stays beside the chat, the stack floats over the pane.
|
|
expect(find.byKey(const Key('chat-row-b')), findsOneWidget);
|
|
expect(_stack.hitTestable(), findsOneWidget);
|
|
await tester.tap(_stack);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.byKey(const ValueKey('chat-stack-button-add')));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Beta').last);
|
|
await tester.pumpAndSettle();
|
|
expect(find.bySemanticsLabel(chatStackLabel(2)), findsOneWidget);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
},
|
|
);
|
|
|
|
test('Chat stack is the default without a stored choice', () async {
|
|
final controller = MobileChatNavigationController(store: _Store(null));
|
|
expect(controller.value, MobileChatNavigation.chatStack);
|
|
await controller.restore();
|
|
expect(controller.value, MobileChatNavigation.chatStack);
|
|
final chosen = MobileChatNavigationController(store: _Store('quickSwitch'));
|
|
await chosen.restore();
|
|
expect(chosen.value, MobileChatNavigation.quickSwitch);
|
|
controller.dispose();
|
|
chosen.dispose();
|
|
});
|
|
}
|