feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
@@ -0,0 +1,141 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/assistant/agent_chat_panel.dart';
|
||||
import 'package:cutdex/features/assistant/agent_reply_region.dart';
|
||||
import 'package:cutdex/features/assistant/chat_controller.dart';
|
||||
import 'package:cutdex/features/assistant/chat_state.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
class _Chat extends ChatController {
|
||||
@override
|
||||
ChatState build(
|
||||
String projectId, {
|
||||
String? conversationId,
|
||||
String? draftKey,
|
||||
}) => const ChatState(
|
||||
busy: true,
|
||||
messages: [ChatMessage(text: 'Previous answer')],
|
||||
);
|
||||
void stream(String text) => state = state.copyWith(partialResponse: text);
|
||||
}
|
||||
|
||||
class _Projects extends Projects {
|
||||
@override
|
||||
Future<ProjectState> build() async => const ProjectState();
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'streaming updates reply without rebuilding history or composer',
|
||||
(tester) async {
|
||||
final chat = _Chat();
|
||||
final container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(_Projects.new),
|
||||
chatControllerProvider('project').overrideWith(() => chat),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
var visible = true;
|
||||
late StateSetter visibility;
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penDark,
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
visibility = setState;
|
||||
return TickerMode(
|
||||
enabled: visible,
|
||||
child: const Scaffold(
|
||||
body: AgentChatPanel(
|
||||
projectId: 'project',
|
||||
timelineId: 'timeline',
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final input = tester.element(find.byType(TextField));
|
||||
final history = tester.element(find.text('Previous answer'));
|
||||
var panelBuilds = 0;
|
||||
var historyBuilds = 0;
|
||||
var replyBuilds = 0;
|
||||
final previous = debugOnRebuildDirtyWidget;
|
||||
debugOnRebuildDirtyWidget = (element, built) {
|
||||
previous?.call(element, built);
|
||||
if (element.widget is AgentChatPanel) panelBuilds++;
|
||||
if (element.widget is AgentReplyRegion) replyBuilds++;
|
||||
if (identical(element, history)) historyBuilds++;
|
||||
};
|
||||
addTearDown(() => debugOnRebuildDirtyWidget = previous);
|
||||
for (var chunk = 0; chunk < 120; chunk++) {
|
||||
chat.stream('Reply $chunk');
|
||||
await tester.pump();
|
||||
}
|
||||
expect(find.text('Reply 119'), findsOneWidget);
|
||||
expect(panelBuilds, 0);
|
||||
expect(historyBuilds, 0);
|
||||
expect(replyBuilds, 120);
|
||||
expect(tester.element(find.byType(TextField)), same(input));
|
||||
visibility(() => visible = false);
|
||||
await tester.pumpAndSettle();
|
||||
replyBuilds = 0;
|
||||
for (var chunk = 120; chunk < 240; chunk++) {
|
||||
chat.stream('Reply $chunk');
|
||||
await tester.pump();
|
||||
}
|
||||
expect(replyBuilds, 0);
|
||||
visibility(() => visible = true);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Reply 239'), findsOneWidget);
|
||||
expect(tester.element(find.byType(TextField)), same(input));
|
||||
expect(tester.takeException(), isNull);
|
||||
String? copied;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied = (call.arguments as Map)['text'] as String;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
final selection = tester
|
||||
.state<SelectionAreaState>(
|
||||
find.descendant(
|
||||
of: find.byType(AgentReplyRegion),
|
||||
matching: find.byType(SelectionArea),
|
||||
),
|
||||
)
|
||||
.selectableRegion;
|
||||
selection.selectAll(SelectionChangedCause.keyboard);
|
||||
await tester.pump();
|
||||
selection.contextMenuButtonItems
|
||||
.singleWhere((item) => item.type == ContextMenuButtonType.copy)
|
||||
.onPressed!();
|
||||
await tester.pump();
|
||||
expect(copied, 'Reply 239');
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user