From 33079769f331e385c7150250bceeeb69e04957c0 Mon Sep 17 00:00:00 2001 From: squidrye Date: Tue, 10 Oct 2023 02:57:12 +0530 Subject: [PATCH] test: added pane overlay test --- .../panes/panes_overlay_test.dart | 125 ++++++++++++++++++ .../integration_test/runner.dart | 2 + .../util/common_operations.dart | 23 +++- 3 files changed, 143 insertions(+), 7 deletions(-) create mode 100644 frontend/appflowy_flutter/integration_test/panes/panes_overlay_test.dart diff --git a/frontend/appflowy_flutter/integration_test/panes/panes_overlay_test.dart b/frontend/appflowy_flutter/integration_test/panes/panes_overlay_test.dart new file mode 100644 index 000000000000..99f46cf0c177 --- /dev/null +++ b/frontend/appflowy_flutter/integration_test/panes/panes_overlay_test.dart @@ -0,0 +1,125 @@ +import 'package:appflowy/generated/locale_keys.g.dart'; +import 'package:appflowy/workspace/presentation/home/panes/flowy_pane.dart'; +import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart'; +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +import '../util/util.dart'; + +const _documentName = 'First Doc'; +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + group('Panes overlay/read-only views test', () { + testWidgets( + 'Opening a new pane of same type marks existing pane as readonly, test assumes read only views are unmodifiable', + (tester) async { + await tester.initializeAppFlowy(); + await tester.tapGoButton(); + + expect(find.byType(FlowyPane), findsOneWidget); + + for (int i = 0; i < 2; i++) { + await tester.openViewInNewPane( + gettingStarted, + ViewLayoutPB.Document, + Axis.horizontal, + ); + } + + expect(find.byType(FlowyPane), findsNWidgets(3)); + expect( + find.textContaining(LocaleKeys.readOnlyViewText.tr()), + findsNWidgets(2), + ); + }); + testWidgets( + 'Switching view on writable pane or closing the writable pane, searches for and converts the first found read only pane to writable', + (tester) async { + await tester.initializeAppFlowy(); + await tester.tapGoButton(); + + expect(find.byType(FlowyPane), findsOneWidget); + + for (int i = 0; i < 2; i++) { + await tester.openViewInNewPane( + gettingStarted, + ViewLayoutPB.Document, + Axis.horizontal, + ); + } + expect(find.byType(FlowyPane), findsNWidgets(3)); + expect( + find.textContaining(LocaleKeys.readOnlyViewText.tr()), + findsNWidgets(2), + ); + + await tester.createNewPageWithName(name: _documentName); + + await tester.tap(find.byType(FlowyPane).first); + + await tester.openPage(_documentName); + + expect( + find.textContaining(LocaleKeys.readOnlyViewText.tr()), + findsNWidgets(1), + ); + + await tester.tap(find.byType(FlowyPane).last); + + await tester.closePaneWithVisibleCloseButton(first: false); + + expect( + find.textContaining(LocaleKeys.readOnlyViewText.tr()), + findsNWidgets(0), + ); + }); + testWidgets( + 'opening duplicate view in a new tab of different pane is marked as read only, closing the writable view leads to conversion of readonly view to writable view', + (tester) async { + await tester.initializeAppFlowy(); + await tester.tapGoButton(); + + expect(find.byType(FlowyPane), findsOneWidget); + + for (int i = 0; i < 1; i++) { + await tester.openViewInNewPane( + gettingStarted, + ViewLayoutPB.Document, + Axis.horizontal, + ); + } + expect(find.byType(FlowyPane), findsNWidgets(2)); + expect( + find.textContaining(LocaleKeys.readOnlyViewText.tr()), + findsNWidgets(1), + ); + await tester.tap(find.byType(FlowyPane).first); + + await tester.createNewPageWithName(name: _documentName); + + expect( + find.textContaining(LocaleKeys.readOnlyViewText.tr()), + findsNWidgets(0), + ); + + await tester.openAppInNewTab(gettingStarted, ViewLayoutPB.Document); + + expect( + find.textContaining(LocaleKeys.readOnlyViewText.tr()), + findsNWidgets(1), + ); + + await tester.tap(find.byType(FlowyPane).last); + + await tester.closePaneWithVisibleCloseButton(first: false); + + expect( + find.textContaining(LocaleKeys.readOnlyViewText.tr()), + findsNWidgets(0), + ); + }); + }); +} diff --git a/frontend/appflowy_flutter/integration_test/runner.dart b/frontend/appflowy_flutter/integration_test/runner.dart index 24156cfd573a..960f9439b5bb 100644 --- a/frontend/appflowy_flutter/integration_test/runner.dart +++ b/frontend/appflowy_flutter/integration_test/runner.dart @@ -25,6 +25,7 @@ import 'auth/auth_test.dart' as auth_test_runner; import 'settings/user_icon_test.dart' as user_icon_test; import 'settings/user_language_test.dart' as user_language_test; import 'panes/panes_test.dart' as panes_test; +import 'panes/panes_overlay_test.dart' as panes_overlay_test; /// The main task runner for all integration tests in AppFlowy. /// @@ -66,6 +67,7 @@ void main() { //Panes panes_test.main(); + panes_overlay_test.main(); // Others hotkeys_test.main(); diff --git a/frontend/appflowy_flutter/integration_test/util/common_operations.dart b/frontend/appflowy_flutter/integration_test/util/common_operations.dart index e06338a3ea1d..0d09f137bd67 100644 --- a/frontend/appflowy_flutter/integration_test/util/common_operations.dart +++ b/frontend/appflowy_flutter/integration_test/util/common_operations.dart @@ -454,14 +454,23 @@ extension CommonOperations on WidgetTester { }); } - Future closePaneWithVisibleCloseButton() async { + Future closePaneWithVisibleCloseButton({ + bool first = true, + }) async { await tapButton( - find - .descendant( - of: find.byType(BlocBuilder), - matching: find.byIcon(Icons.close_sharp), - ) - .first, + first + ? find + .descendant( + of: find.byType(BlocBuilder), + matching: find.byIcon(Icons.close_sharp), + ) + .first + : find + .descendant( + of: find.byType(BlocBuilder), + matching: find.byIcon(Icons.close_sharp), + ) + .last, ); } }