Files
pipelines/app/test/features/chat/chat_open_transition_test.dart
T

107 lines
3.6 KiB
Dart

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:pipelines_app/features/chat/ui/sessions/session_row_content.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',
};
void main() {
testWidgets('mobile identity flies into the header and returns to the row', (
tester,
) async {
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
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',
),
),
),
),
);
await tester.pump();
expect(find.byType(Hero), findsNothing);
});
}