Bläddra i källkod

[Fix] Integration test flakes. (#2635)

* feat: add tearDown and tearDownAll to reset workspaces

* fix: register tearDown and tearDownAll in empty_document_test

* feat: register tearDown and tearDownAll in board_test

* feat: register tearDown and tearDownAll in open_ai
Alex Wallen 2 år sedan
förälder
incheckning
5a7339b092

+ 2 - 0
frontend/appflowy_flutter/integration_test/board_test.dart

@@ -34,6 +34,8 @@ void main() {
   group('board', () {
     setUpAll(() async => await service.setUpAll());
     setUp(() async => await service.setUp());
+    tearDown(() async => await service.tearDown());
+    tearDownAll(() async => await service.tearDownAll());
 
     testWidgets(
         'integration test unzips the proper workspace and loads it correctly.',

+ 9 - 1
frontend/appflowy_flutter/integration_test/empty_document_test.dart

@@ -30,6 +30,8 @@ void main() {
   group('Tests on a workspace with only an empty document', () {
     setUpAll(() async => await service.setUpAll());
     setUp(() async => await service.setUp());
+    tearDown(() async => await service.tearDown());
+    tearDownAll(() async => await service.tearDownAll());
 
     testWidgets('/board shortcut creates a new board and view of the board',
         (tester) async {
@@ -69,6 +71,7 @@ void main() {
         ],
         tester: tester,
       );
+      await tester.pumpAndSettle();
 
       // Checks whether new board is referenced and properly on the page.
       expect(find.byType(BuiltInPageWidget), findsOneWidget);
@@ -113,7 +116,12 @@ void main() {
       expect(find.byType(SelectionMenuItemWidget), findsAtLeastNWidgets(2));
 
       // Finalizes the slash command that creates the board.
-      await simulateKeyDownEvent(LogicalKeyboardKey.enter);
+      await FlowyTestKeyboard.simulateKeyDownEvent(
+        [
+          LogicalKeyboardKey.enter,
+        ],
+        tester: tester,
+      );
       await tester.pumpAndSettle();
 
       // Checks whether new board is referenced and properly on the page.

+ 2 - 0
frontend/appflowy_flutter/integration_test/open_ai_smart_menu_test.dart

@@ -16,6 +16,8 @@ void main() {
   group('integration tests for open-ai smart menu', () {
     setUpAll(() async => await service.setUpAll());
     setUp(() async => await service.setUp());
+    tearDown(() async => await service.tearDown());
+    tearDownAll(() async => await service.tearDownAll());
 
     testWidgets('testing selection on open-ai smart menu replace', (tester) async {
       final appFlowyEditor = await setUpOpenAITesting(tester);

+ 15 - 0
frontend/appflowy_flutter/integration_test/util/data.dart

@@ -39,6 +39,13 @@ enum TestWorkspace {
     return root;
   }
 
+  Future<void> clean() async {
+    final Directory workspaceRoot = await root;
+    if (await workspaceRoot.exists()) {
+      workspaceRoot.delete(recursive: true);
+    }
+  }
+
   String get _asset => 'assets/test/workspaces/$_name.zip';
 }
 
@@ -67,4 +74,12 @@ class TestWorkspaceService {
       await TestWorkspace._parent.then((value) => value.path),
     );
   }
+
+  Future<void> tearDown() async {
+    await workspace.clean();
+  }
+
+  Future<void> tearDownAll() async {
+    await SharedPreferences.getInstance().then((value) => value.remove(kSettingsLocationDefaultLocation));
+  }
 }