Skip to content

Commit

Permalink
test: added pane overlay test
Browse files Browse the repository at this point in the history
  • Loading branch information
squidrye committed Oct 9, 2023
1 parent f5b6e6c commit 3307976
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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),
);
});
});
}
2 changes: 2 additions & 0 deletions frontend/appflowy_flutter/integration_test/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -66,6 +67,7 @@ void main() {

//Panes
panes_test.main();
panes_overlay_test.main();

// Others
hotkeys_test.main();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,23 @@ extension CommonOperations on WidgetTester {
});
}

Future<void> closePaneWithVisibleCloseButton() async {
Future<void> closePaneWithVisibleCloseButton({
bool first = true,
}) async {
await tapButton(
find
.descendant(
of: find.byType(BlocBuilder<PanesCubit, PanesState>),
matching: find.byIcon(Icons.close_sharp),
)
.first,
first
? find
.descendant(
of: find.byType(BlocBuilder<PanesCubit, PanesState>),
matching: find.byIcon(Icons.close_sharp),
)
.first
: find
.descendant(
of: find.byType(BlocBuilder<PanesCubit, PanesState>),
matching: find.byIcon(Icons.close_sharp),
)
.last,
);
}
}
Expand Down

0 comments on commit 3307976

Please sign in to comment.