Grow the tapped chat row into the chat page on phones
Replace the identity-avatar Hero with a container transform: the row's surface, tint and edge marker morph into the full page while the content cross-fades, and Back, the Cupertino edge swipe or Android predictive back shrink the page into the open chat's row. Reduced motion or a row off screen fades instead; wide layouts are unchanged.
This commit is contained in:
@@ -1,106 +1,192 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/session_row_content.dart';
|
||||
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/ui/motion/container_transform_flight.dart';
|
||||
import 'package:pipelines_app/ui/motion/container_transform_route.dart';
|
||||
import 'package:pipelines_app/ui/motion/container_transform_source.dart';
|
||||
import 'package:pipelines_app/ui/motion/motion.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
const _session = <String, dynamic>{
|
||||
'id': 'fake-chat',
|
||||
'title': 'Fake chat',
|
||||
'directory': '/tmp/fake-chat',
|
||||
'color': 'blue',
|
||||
};
|
||||
import '../../native_back.dart';
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
{'id': 'a', 'title': 'First chat', 'color': 'blue'},
|
||||
{'id': 'b', 'title': 'Second chat'},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pumpShell(WidgetTester tester, Size size) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage(const []);
|
||||
addTearDown(gateway.close);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: appLightTheme(),
|
||||
home: AdaptiveShell(
|
||||
destination: AppDestination.chat,
|
||||
destinationBodies: {
|
||||
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Finder get _surface => find.byKey(containerTransformSurfaceKey);
|
||||
|
||||
void main() {
|
||||
testWidgets('mobile identity flies into the header and returns to the row', (
|
||||
testWidgets('a phone grows the tapped row into the chat and back', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
// Chat tests run with reduced motion (flutter_test_config); this one
|
||||
// covers the motion itself.
|
||||
final reduced = tester.platformDispatcher.accessibilityFeatures;
|
||||
tester.platformDispatcher.accessibilityFeaturesTestValue =
|
||||
const FakeAccessibilityFeatures();
|
||||
addTearDown(
|
||||
() => tester.platformDispatcher.accessibilityFeaturesTestValue = reduced,
|
||||
);
|
||||
await _pumpShell(tester, const Size(390, 844));
|
||||
final row = tester.getRect(find.byKey(const Key('chat-row-a')));
|
||||
expect(
|
||||
find.byType(Hero),
|
||||
findsNothing,
|
||||
reason: 'the row is the shared element',
|
||||
);
|
||||
|
||||
await tester.tap(find.text('First chat'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 120));
|
||||
final navigator = tester.state<NavigatorState>(
|
||||
find.byType(Navigator).first,
|
||||
);
|
||||
expect(navigator.canPop(), isTrue);
|
||||
final mid = tester.getRect(_surface);
|
||||
expect(mid.top, lessThan(row.top));
|
||||
expect(mid.height, greaterThan(row.height));
|
||||
expect(mid.height, lessThan(844));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(_surface), const Rect.fromLTWH(0, 0, 390, 844));
|
||||
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
|
||||
expect(find.byType(Hero), findsNothing);
|
||||
|
||||
await tester.tap(findNativeBack());
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
final closing = tester.getRect(_surface);
|
||||
expect(closing.height, lessThan(844));
|
||||
expect(closing.height, greaterThan(row.height));
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(navigator.canPop(), isFalse);
|
||||
expect(_surface, findsNothing);
|
||||
expect(tester.getRect(find.byKey(const Key('chat-row-a'))), row);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('a phone under reduced motion fades the chat in place', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpShell(tester, const Size(390, 844));
|
||||
await tester.tap(find.text('First chat'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
expect(tester.getRect(_surface), const Rect.fromLTWH(0, 0, 390, 844));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
|
||||
await tester.tap(findNativeBack());
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
expect(tester.getRect(_surface), const Rect.fromLTWH(0, 0, 390, 844));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_surface, findsNothing);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('a wide window opens the chat beside the list, untransformed', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpShell(tester, const Size(1280, 800));
|
||||
await tester.tap(find.text('First chat'));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 120));
|
||||
expect(_surface, findsNothing);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('chat-thread-a')), findsOneWidget);
|
||||
expect(_surface, findsNothing);
|
||||
final navigator = tester.state<NavigatorState>(
|
||||
find.byType(Navigator).first,
|
||||
);
|
||||
expect(navigator.canPop(), isFalse);
|
||||
expect(
|
||||
find.byWidgetPredicate((w) => w is ContainerTransformSource),
|
||||
findsWidgets,
|
||||
reason: 'rows still register, but nothing grows from them',
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('a row offers its tinted surface and edge marker', (
|
||||
tester,
|
||||
) async {
|
||||
final sources = ContainerTransformSources();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: appLightTheme(),
|
||||
builder: (context, child) => MediaQuery(
|
||||
data: MediaQuery.of(
|
||||
context,
|
||||
).copyWith(size: const Size(390, 844), disableAnimations: false),
|
||||
child: child!,
|
||||
),
|
||||
home: Scaffold(
|
||||
body: ChatSessionRow(
|
||||
session: _session,
|
||||
onOpen: (session) =>
|
||||
Navigator.of(
|
||||
tester.element(find.byType(ChatSessionRow)),
|
||||
).push<void>(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => Scaffold(
|
||||
body: ChatThreadHeader(
|
||||
title: 'Fake chat',
|
||||
folder: 'fake-chat',
|
||||
onInfo: () {},
|
||||
showBack: true,
|
||||
identity: ChatSessionAvatar(
|
||||
session: session,
|
||||
selected: true,
|
||||
),
|
||||
identityHeroTag: 'chat-identity-fake-chat',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
onAction: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(Hero), findsOneWidget);
|
||||
final rowAvatar = find.byType(ChatSessionAvatar);
|
||||
final rowRect = tester.getRect(rowAvatar);
|
||||
await tester.tap(find.byKey(const Key('chat-row-fake-chat')));
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
expect(find.text('Fake chat'), findsOneWidget);
|
||||
final heroFinder = find.byType(Hero, skipOffstage: false);
|
||||
final heroRects = [
|
||||
for (var index = 0; index < tester.widgetList(heroFinder).length; index++)
|
||||
tester.getRect(heroFinder.at(index)),
|
||||
];
|
||||
expect(heroRects, hasLength(2));
|
||||
expect(
|
||||
heroRects.any((rect) => rect.size != rowRect.size && rect != rowRect),
|
||||
isTrue,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final headerAvatar = tester.getRect(find.byType(ChatSessionAvatar));
|
||||
expect(headerAvatar.top, isNot(rowRect.top));
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('chat-row-fake-chat')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('reduced motion keeps the identity in place without a Hero', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(disableAnimations: true),
|
||||
child: MaterialApp(
|
||||
theme: appLightTheme(),
|
||||
home: Scaffold(
|
||||
body: ChatThreadHeader(
|
||||
title: 'Fake chat',
|
||||
folder: 'fake-chat',
|
||||
onInfo: () {},
|
||||
identity: ChatSessionAvatar(session: _session, selected: true),
|
||||
identityHeroTag: 'chat-identity-fake-chat',
|
||||
body: ContainerTransformScope(
|
||||
sources: sources,
|
||||
child: ChatSessionRow(
|
||||
session: const {'id': 'x', 'title': 'Tinted', 'color': 'blue'},
|
||||
visible: true,
|
||||
selected: true,
|
||||
onOpen: (_) {},
|
||||
onAction: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(Hero), findsNothing);
|
||||
final origin = sources.originOf('x')!;
|
||||
expect(origin.rect, tester.getRect(find.byKey(const Key('chat-row-x'))));
|
||||
final background = appLightTheme().scaffoldBackgroundColor;
|
||||
expect(origin.color, isNot(background), reason: 'the chat colour tints it');
|
||||
expect(origin.color.a, 1);
|
||||
expect(origin.markerWidth, 10);
|
||||
expect(origin.marker, isNotNull);
|
||||
});
|
||||
|
||||
test('the route reads its timing from Motion', () {
|
||||
final route = ContainerTransformPageRoute<void>(
|
||||
link: ContainerTransformLink(() => null),
|
||||
cupertino: false,
|
||||
builder: (_) => const SizedBox(),
|
||||
);
|
||||
expect(route.transitionDuration, Motion.containerTransform);
|
||||
expect(route.reverseTransitionDuration, Motion.containerTransformReverse);
|
||||
expect(route.opaque, isTrue);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user