d19a14b9f9
_back marked the open chat hidden without rebuilding and relied on the owner's route change to redraw. When the chat was shown while the app was already on /chat (a restored layout, the Chat tab re-selected) nothing changed, so the chat stayed on screen for seconds while the list behind it took the taps. Found on the device: closeChat logged route=null and the entrance never animated out. _back now rebuilds itself.
74 lines
2.6 KiB
Dart
74 lines
2.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:pipelines_app/core/api_gateway.dart';
|
|
import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart';
|
|
import 'package:pipelines_app/features/chat/screen.dart';
|
|
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
|
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.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': [
|
|
for (final id in ['a', 'b'])
|
|
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
|
|
],
|
|
});
|
|
}
|
|
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
|
return super.call(type, fields);
|
|
}
|
|
}
|
|
|
|
Finder _thread(String id) => find.byWidgetPredicate(
|
|
(widget) => widget is ChatThreadView && widget.sessionId == id,
|
|
);
|
|
|
|
void main() {
|
|
testWidgets('phone Back hides a restored chat at once when the owner is '
|
|
'already on the chat list route', (tester) async {
|
|
// A restored layout shows chat a while the app is already on /chat: Back
|
|
// asks the owner to go to /chat, which changes nothing, so the screen must
|
|
// hide the chat itself instead of waiting for an unrelated rebuild.
|
|
final layout = ChatWorkspaceController()..open('a');
|
|
SharedPreferences.setMockInitialValues({
|
|
chatWorkspacePreferenceKey: layout.snapshot()!.encode(),
|
|
});
|
|
tester.view.physicalSize = const Size(412, 915);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
|
addTearDown(gateway.close);
|
|
var backs = 0;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: ChatScreen(
|
|
gateway: gateway,
|
|
persistWorkspace: true,
|
|
onSessionSelected: (_) {},
|
|
onBack: () => backs++,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
expect(_thread('a'), findsOneWidget);
|
|
|
|
await tester.tap(find.byType(BackButton).hitTestable());
|
|
// Only the screen's own frames: nothing else rebuilds it.
|
|
for (var i = 0; i < 30; i++) {
|
|
await tester.pump(const Duration(milliseconds: 16));
|
|
}
|
|
expect(backs, 1);
|
|
expect(_thread('a'), findsNothing);
|
|
expect(find.text('Chat a').hitTestable(), findsWidgets);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|