Disable paste targets in hidden retained chat workspaces

This commit is contained in:
2026-11-08 00:17:32 +00:00
parent 8a409e2d0a
commit fa95bf57ff
3 changed files with 103 additions and 1 deletions
@@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
@@ -9,6 +10,7 @@ import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
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_mobile_peek_divider.dart';
import 'package:pipelines_app/features/chat/ui/sessions/chat_sessions_screen.dart';
@@ -505,6 +507,88 @@ void main() {
expect(tester.takeException(), isNull);
},
);
testWidgets(
'a folded workspace rejects paste while retained behind the list',
(tester) async {
SharedPreferences.setMockInitialValues({});
tester.view.physicalSize = const Size(1000, 1000);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/chat')),
);
addTearDown(provider.dispose);
addTearDown(client.dispose);
await tester.pumpWidget(
PipelinesApp(
server: webServer(),
client: client,
cupertino: false,
routeInformationProvider: provider,
),
);
await tester.pump();
await replyChatSessions(tester, channel, ['a']);
await tester.pumpAndSettle();
await tester.tap(find.text('Chat a').first);
await tester.pump();
await replyChatHistory(
tester,
channel,
subscribeIndex: 0,
historyIndex: 0,
);
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const Key('chat-composer-field')),
'original draft',
);
tester.view.physicalSize = const Size(560, 1000);
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Back').hitTestable());
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat');
final retained = tester.widgetList<ChatComposerBar>(
find.byType(ChatComposerBar, skipOffstage: false),
);
expect(retained, hasLength(1));
expect(retained.single.pasteTarget, isFalse);
var clipboardReads = 0;
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
if (call.method == 'Clipboard.getData') {
clipboardReads++;
return {'text': 'must not enter hidden chat'};
}
return null;
});
addTearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(SystemChannels.platform, null);
});
FocusManager.instance.primaryFocus?.unfocus();
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyV);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
expect(clipboardReads, 0);
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
await tester.pumpAndSettle();
expect(provider.value.uri.path, '/chat/a');
expect(find.text('original draft'), findsOneWidget);
expect(find.textContaining('must not enter hidden chat'), findsNothing);
expect(
tester
.widget<ChatComposerBar>(find.byType(ChatComposerBar))
.pasteTarget,
isTrue,
);
},
);
testWidgets(
'mobile Chats retap stays on list with no history or a removed chat',
(tester) async {