Animate focused mobile chat panes while preserving saved geometry
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
|
||||
Widget _host(
|
||||
ChatWorkspaceController controller, {
|
||||
bool mobile = true,
|
||||
bool reduced = false,
|
||||
}) => MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(disableAnimations: reduced),
|
||||
child: SizedBox(
|
||||
width: 560,
|
||||
height: 800,
|
||||
child: ChatWorkspace(
|
||||
controller: controller,
|
||||
singlePane: mobile,
|
||||
mobilePeeks: mobile,
|
||||
paneBuilder: (_, pane, active) => _Draft(key: ValueKey(pane.sessionId)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
class _Draft extends StatefulWidget {
|
||||
const _Draft({super.key});
|
||||
@override
|
||||
State<_Draft> createState() => _DraftState();
|
||||
}
|
||||
|
||||
class _DraftState extends State<_Draft> {
|
||||
final controller = TextEditingController();
|
||||
@override
|
||||
void dispose() {
|
||||
controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
Material(child: TextField(controller: controller));
|
||||
}
|
||||
|
||||
Finder _rect(String pane) => find.byKey(ValueKey('chat-workspace-$pane'));
|
||||
void main() {
|
||||
testWidgets(
|
||||
'mobile peeks animate80/20 and retain drafts and saved geometry',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(560, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures(disableAnimations: false);
|
||||
addTearDown(
|
||||
tester.platformDispatcher.clearAccessibilityFeaturesTestValue,
|
||||
);
|
||||
addTearDown(tester.view.reset);
|
||||
final controller = ChatWorkspaceController()..open('a');
|
||||
final first = controller.activePaneId!;
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
final second = controller.activePaneId!;
|
||||
controller.resize(controller.root!.id, .31);
|
||||
final saved = controller.snapshot()!.encode();
|
||||
await tester.pumpWidget(_host(controller));
|
||||
await tester.pumpAndSettle();
|
||||
final aState = tester.state(find.byKey(const ValueKey('a')));
|
||||
final bState = tester.state(find.byKey(const ValueKey('b')));
|
||||
await tester.enterText(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('b')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
'Draft b',
|
||||
);
|
||||
final oldHeight = tester.getSize(_rect(first)).height;
|
||||
expect(oldHeight, closeTo((800 - 6) * .2, 1));
|
||||
expect(tester.getSize(_rect(second)).height, closeTo((800 - 6) * .8, 1));
|
||||
await tester.pumpAndSettle();
|
||||
final positionState = tester.state(_rect(first));
|
||||
await tester.tap(find.byKey(ValueKey('chat-peek-$first')));
|
||||
expect(
|
||||
controller.activePane?.sessionId,
|
||||
'a',
|
||||
reason: 'tap activates peek immediately',
|
||||
);
|
||||
await tester.pump();
|
||||
expect(tester.state(_rect(first)), same(positionState));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(
|
||||
tester.widget<AnimatedPositioned>(_rect(first)).duration,
|
||||
const Duration(milliseconds: 220),
|
||||
);
|
||||
final intermediate = tester.getSize(_rect(first)).height;
|
||||
expect(intermediate, greaterThan(oldHeight));
|
||||
expect(intermediate, lessThan((800 - 6) * .8));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.activePane?.sessionId, 'a');
|
||||
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1));
|
||||
expect(tester.state(find.byKey(const ValueKey('a'))), same(aState));
|
||||
expect(tester.state(find.byKey(const ValueKey('b'))), same(bState));
|
||||
expect((bState as _DraftState).controller.text, 'Draft b');
|
||||
expect(
|
||||
tester
|
||||
.widget<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('b')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
)
|
||||
.focusNode
|
||||
.hasFocus,
|
||||
isFalse,
|
||||
);
|
||||
controller.activate(second);
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.snapshot()!.encode(), saved);
|
||||
await tester.pumpWidget(_host(controller, mobile: false));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.state(find.byKey(const ValueKey('a'))), same(aState));
|
||||
expect(
|
||||
tester.getSize(_rect(first)).width,
|
||||
lessThan(tester.getSize(_rect(second)).width),
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
testWidgets(
|
||||
'three retained panes expose active+previous and honor reduced motion',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(560, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final controller = ChatWorkspaceController()..open('a');
|
||||
final first = controller.activePaneId!;
|
||||
controller.splitActive('b', ChatSplitAxis.horizontal);
|
||||
controller.splitActive('c', ChatSplitAxis.vertical);
|
||||
await tester.pumpWidget(_host(controller, reduced: true));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(_Draft), findsNWidgets(2));
|
||||
final third = controller.activePaneId!;
|
||||
controller.activate(first);
|
||||
await tester.pump();
|
||||
expect(tester.getSize(_rect(first)).height, closeTo((800 - 6) * .8, 1));
|
||||
expect(find.byType(_Draft), findsNWidgets(2));
|
||||
expect(find.byType(_Draft, skipOffstage: false), findsNWidgets(3));
|
||||
controller.activate(third);
|
||||
await tester.pump();
|
||||
expect(tester.getSize(_rect(third)).height, closeTo((800 - 6) * .8, 1));
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
controller.dispose();
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user