Animate retained mobile chat reopening without remounting panes
This commit is contained in:
@@ -12,6 +12,7 @@ import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_composer_bar.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_mobile_peek_divider.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
|
||||
|
||||
@@ -321,7 +322,21 @@ void main() {
|
||||
testWidgets(
|
||||
'mobile Chats retap reopens the retained multi-pane workspace after tabs',
|
||||
(tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
// A restored empty layout chooses the retained inline mobile path from
|
||||
// the first selection, rather than the initial pushed detail route.
|
||||
SharedPreferences.setMockInitialValues({
|
||||
chatWorkspacePreferenceKey: jsonEncode({
|
||||
'version': 1,
|
||||
'root': null,
|
||||
'active_pane': null,
|
||||
'sidebar_mode': 'expanded',
|
||||
}),
|
||||
});
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||
addTearDown(
|
||||
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
|
||||
);
|
||||
tester.view.physicalSize = const Size(560, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
@@ -348,6 +363,9 @@ void main() {
|
||||
|
||||
await tester.tap(find.text('Chat a').first);
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/chat/a');
|
||||
expect(find.byType(ChatThreadView), findsOneWidget);
|
||||
await replyChatSessions(tester, channel, ['a', 'b'], index: 1);
|
||||
await replyChatHistory(
|
||||
tester,
|
||||
channel,
|
||||
@@ -409,6 +427,11 @@ void main() {
|
||||
expect(workspace.controller.paneCount, 2);
|
||||
expect(workspace.controller.activePane?.sessionId, 'b');
|
||||
expect(provider.value.uri.path, '/chat/b');
|
||||
final workspaceState = tester.state(find.byType(ChatWorkspace));
|
||||
final activeThreadState = tester.state(
|
||||
find.byKey(const ValueKey('chat-session-b')),
|
||||
);
|
||||
final restingTop = tester.getTopLeft(find.byType(ChatWorkspace)).dy;
|
||||
final paneOrder = workspace.controller.panes
|
||||
.map((p) => p.sessionId)
|
||||
.toList();
|
||||
@@ -455,7 +478,20 @@ void main() {
|
||||
// The selected Chats destination is already showing its list: the
|
||||
// second tap reuses the mounted workspace instead of opening a new one.
|
||||
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
||||
await tester.pump();
|
||||
final enteringTop = tester.getTopLeft(find.byType(ChatWorkspace)).dy;
|
||||
expect(enteringTop, greaterThan(restingTop + 1));
|
||||
await tester.pump(const Duration(milliseconds: 80));
|
||||
final midwayTop = tester.getTopLeft(find.byType(ChatWorkspace)).dy;
|
||||
expect(midwayTop, greaterThan(restingTop + 1));
|
||||
expect(midwayTop, lessThan(enteringTop));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getTopLeft(find.byType(ChatWorkspace)).dy, restingTop);
|
||||
expect(tester.state(find.byType(ChatWorkspace)), same(workspaceState));
|
||||
expect(
|
||||
tester.state(find.byKey(const ValueKey('chat-session-b'))),
|
||||
same(activeThreadState),
|
||||
);
|
||||
expect(provider.value.uri.path, '/chat/b');
|
||||
final restored = tester.widget<ChatWorkspace>(find.byType(ChatWorkspace));
|
||||
expect(restored.controller, same(workspace.controller));
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_entrance.dart';
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('retained entrance moves the same child ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||
addTearDown(
|
||||
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
|
||||
);
|
||||
final childKey = GlobalKey();
|
||||
final child = TextField(key: childKey);
|
||||
Widget host(bool visible, {bool reduced = false}) => MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(disableAnimations: reduced),
|
||||
child: SizedBox.expand(
|
||||
child: ChatWorkspaceEntrance(
|
||||
visible: visible,
|
||||
cupertino: cupertino,
|
||||
child: Material(child: child),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(host(false));
|
||||
final element = childKey.currentContext;
|
||||
final state = childKey.currentState;
|
||||
expect(find.byKey(childKey), findsNothing);
|
||||
await tester.pumpWidget(host(true));
|
||||
final start = tester.getTopLeft(find.byKey(childKey));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 80));
|
||||
final middle = tester.getTopLeft(find.byKey(childKey));
|
||||
await tester.pumpAndSettle();
|
||||
final end = tester.getTopLeft(find.byKey(childKey));
|
||||
expect(cupertino ? middle.dx : middle.dy, greaterThan(0));
|
||||
expect(
|
||||
cupertino ? middle.dx : middle.dy,
|
||||
lessThan(cupertino ? start.dx : start.dy),
|
||||
);
|
||||
expect(end, Offset.zero);
|
||||
expect(childKey.currentContext, same(element));
|
||||
expect(childKey.currentState, same(state));
|
||||
await tester.enterText(find.byType(TextField), 'Retained draft');
|
||||
await tester.pumpWidget(host(false));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(host(true, reduced: true));
|
||||
expect(tester.getTopLeft(find.byKey(childKey)), Offset.zero);
|
||||
expect(find.text('Retained draft'), findsOneWidget);
|
||||
expect(childKey.currentState, same(state));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user