Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: update test

Nathan0d0c6fff32a3
diff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/document/document_ai_writer_test.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/document/document_ai_writer_test.dart
index e5548b0d97..6b64f3f8af 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/cloud/document/document_ai_writer_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/document/document_ai_writer_test.dart
@@ -121,11 +121,7 @@ void main() {
);
await tester.pumpAndSettle();
- await tester.tapButton(find.byType(AiWriterToolbarActionList));
- await tester.tapButton(
- find.text(AiWriterCommand.fixSpellingAndGrammar.i18n),
- );
- await tester.pumpAndSettle();
+ await tester.selectAIWriter(AiWriterCommand.fixSpellingAndGrammar);
final editorState = tester.editor.getCurrentEditorState();
final document = editorState.document;
@@ -169,22 +165,38 @@ void main() {
);
await tester.pumpAndSettle();
- await tester.tapButton(find.byType(AiWriterToolbarActionList));
- await tester.tapButton(
- find.text(AiWriterCommand.userQuestion.i18n),
- );
- await tester.pumpAndSettle();
+ await tester.selectAIWriter(AiWriterCommand.userQuestion);
await tester.enterTextInPromptTextField("Explain the concept of TPU");
+ await tester.simulateKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pumpAndSettle();
+
+ await tester.selectModel("GPT-4o-mini");
- // click enter button
+ await tester.enterTextInPromptTextField("How about GPU?");
await tester.simulateKeyEvent(LogicalKeyboardKey.enter);
- await tester.pumpAndSettle(Duration(seconds: 10));
+ await tester.pumpAndSettle();
});
});
}
class _CompletionHistoryValidator extends StreamCompletionValidator {
+ static const _expectedResponses = {
+ 1: "What is TPU?",
+ 3: [
+ "What is TPU?",
+ "Explain the concept of TPU",
+ "TPU is a tensor processing unit that is designed to accelerate machine",
+ ],
+ 5: [
+ "What is TPU?",
+ "Explain the concept of TPU",
+ "TPU is a tensor processing unit that is designed to accelerate machine",
+ "How about GPU?",
+ "GPU is a graphics processing unit that is designed to accelerate machine learning tasks.",
+ ],
+ };
+
@override
bool validate(
String text,
@@ -195,15 +207,28 @@ class _CompletionHistoryValidator extends StreamCompletionValidator {
List<AiWriterRecord> history,
) {
assert(completionType == CompletionTypePB.UserQuestion);
+ if (history.isEmpty) return false;
+
+ final expectedMessages = _expectedResponses[history.length];
+ if (expectedMessages == null) return false;
+
+ if (expectedMessages is String) {
+ _assertMessage(history[0].content, expectedMessages);
+ return true;
+ } else if (expectedMessages is List<String>) {
+ for (var i = 0; i < expectedMessages.length; i++) {
+ _assertMessage(history[i].content, expectedMessages[i]);
+ }
+ return true;
+ }
+
+ return false;
+ }
+
+ void _assertMessage(String actual, String expected) {
assert(
- history.length == 1,
- "expect history length is 1, but got ${history.length}",
- );
- assert(
- history[0].content.trim() == "What is TPU?",
- "expect history[0].content is 'What is TPU?', but got '${history[0].content.trim()}'",
+ actual.trim() == expected,
+ "expected '$expected', but got '${actual.trim()}'",
);
-
- return true;
}
}
diff --git a/frontend/appflowy_flutter/integration_test/shared/ai_test_op.dart b/frontend/appflowy_flutter/integration_test/shared/ai_test_op.dart
index 6d5b34ba0c..e92a92b727 100644
--- a/frontend/appflowy_flutter/integration_test/shared/ai_test_op.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/ai_test_op.dart
@@ -1,8 +1,24 @@
import 'package:appflowy/ai/ai.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/ai/operations/ai_writer_entities.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:extended_text_field/extended_text_field.dart';
+import 'util.dart';
+
extension AppFlowyAITest on WidgetTester {
+ Future<void> selectAIWriter(AiWriterCommand command) async {
+ await tapButton(find.byType(AiWriterToolbarActionList));
+ await tapButton(find.text(command.i18n));
+ await pumpAndSettle();
+ }
+
+ Future<void> selectModel(String modelName) async {
+ await tapButton(find.byType(SelectModelMenu));
+ await tapButton(find.text(modelName));
+ await pumpAndSettle();
+ }
+
Future<void> enterTextInPromptTextField(String text) async {
// Wait for the text field to be visible
await pumpAndSettle();
@@ -17,6 +33,8 @@ extension AppFlowyAITest on WidgetTester {
final widget = element(textField).widget as ExtendedTextField;
expect(widget.enabled, isTrue, reason: 'TextField is not enabled');
+ await tap(textField);
+
testTextInput.enterText(text);
await pumpAndSettle(const Duration(milliseconds: 300));
}
diff --git a/frontend/appflowy_flutter/integration_test/shared/base.dart b/frontend/appflowy_flutter/integration_test/shared/base.dart
index 95bda89113..aadcc1d707 100644
--- a/frontend/appflowy_flutter/integration_test/shared/base.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/base.dart
@@ -43,6 +43,7 @@ extension AppFlowyTestBase on WidgetTester {
if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
await binding.setSurfaceSize(windowSize);
}
+ cloudType = AuthenticatorType.appflowyCloudDevelop;
mockHotKeyManagerHandlers();
final applicationDataDirectory = dataDirectory ??
diff --git a/frontend/appflowy_flutter/integration_test/shared/mock/mock_ai.dart b/frontend/appflowy_flutter/integration_test/shared/mock/mock_ai.dart
index 8f6d6757b4..cd4ecb931f 100644
--- a/frontend/appflowy_flutter/integration_test/shared/mock/mock_ai.dart
+++ b/frontend/appflowy_flutter/integration_test/shared/mock/mock_ai.dart
@@ -43,6 +43,22 @@ final _mockAiMap = <CompletionTypePB, Map<String, List<String>>>{
"accelerate",
"machine",
],
+ "How about GPU?": [
+ "GPU",
+ "is",
+ "a",
+ "graphics",
+ "processing",
+ "unit",
+ "that",
+ "is",
+ "designed",
+ "to",
+ "accelerate",
+ "machine",
+ "learning",
+ "tasks",
+ ],
},
};