Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s
142 lines
4.8 KiB
Dart
142 lines
4.8 KiB
Dart
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());
|
|
},
|
|
);
|
|
}
|