Skip to content

Commit

Permalink
fix: integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Sep 14, 2023
1 parent d41940f commit 1025315
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database_view/board/presentation/board_page.dart';
import 'package:appflowy/plugins/database_view/calendar/presentation/calendar_page.dart';
import 'package:appflowy/plugins/database_view/grid/presentation/grid_page.dart';
Expand All @@ -7,7 +8,7 @@ import 'package:appflowy/workspace/presentation/home/menu/view/view_item.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/view_more_action_button.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand All @@ -22,14 +23,11 @@ void main() {
await tester.tapGoButton();

// create a new page
const name = 'Hello AppFlowy';
await tester.tapNewPageButton();
await tester.enterText(find.byType(TextFormField), name);
await tester.tapOKButton();

// expect to see a new document
tester.expectToSeePageName(
name,
LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
);
// and with one paragraph block
expect(find.byType(TextBlockComponentWidget), findsOneWidget);
Expand Down
29 changes: 26 additions & 3 deletions frontend/appflowy_flutter/integration_test/util/base.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import 'dart:async';
import 'dart:io';

import 'package:appflowy/startup/entry_point.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/presentation/presentation.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
import 'package:flowy_infra/uuid.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

class FlowyTestContext {
FlowyTestContext({
Expand Down Expand Up @@ -39,8 +41,8 @@ extension AppFlowyTestBase on WidgetTester {
IntegrationMode.integrationTest,
);

await wait(3000);
await pumpAndSettle(const Duration(seconds: 2));
await waitUntilSignInPageShow();

return FlowyTestContext(
applicationDataDirectory: directory,
);
Expand Down Expand Up @@ -78,6 +80,27 @@ extension AppFlowyTestBase on WidgetTester {
return directory.path;
}

Future<void> waitUntilSignInPageShow() async {
final finder = find.byType(GoButton);
await pumpUntilFound(finder);
expect(finder, findsOneWidget);
}

Future<void> pumpUntilFound(
Finder finder, {
Duration timeout = const Duration(seconds: 10),
}) async {
bool timerDone = false;
final timer = Timer(timeout, () => timerDone = true);
while (timerDone != true) {
await pump();
if (any(finder)) {
timerDone = true;
}
}
timer.cancel();
}

Future<void> tapButton(
Finder finder, {
int? pointer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/presentation/screens/screens.dart';
import 'package:appflowy/workspace/presentation/home/menu/sidebar/sidebar_new_page_button.dart';
import 'package:appflowy/workspace/presentation/home/menu/view/draggable_view_item.dart';
Expand Down Expand Up @@ -279,7 +282,14 @@ extension CommonOperations on WidgetTester {
// create a new page
await tapAddViewButton(name: parentName ?? gettingStarted);
await tapButtonWithName(layout.menuName);
await tapOKButton();
final settingsOrFailure = await getIt<KeyValueStorage>().getWithFormat(
KVKeys.showRenameDialogWhenCreatingNewFile,
(value) => bool.parse(value),
);
final showRenameDialog = settingsOrFailure.fold((l) => false, (r) => r);
if (showRenameDialog) {
await tapOKButton();
}
await pumpAndSettle();

// hover on it and change it's name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart';
import 'dart:ui';

import 'package:flowy_infra/size.dart';
import 'package:flowy_infra_ui/style_widget/scrolling/styled_list.dart';
import 'package:flowy_infra_ui/widget/dialog/dialog_size.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:ui';

extension IntoDialog on Widget {
Future<dynamic> show(BuildContext context) async {
Expand Down Expand Up @@ -71,7 +72,7 @@ class StyledDialog extends StatelessWidget {
maxWidth: maxWidth ?? double.infinity,
),
child: ClipRRect(
borderRadius: borderRadius,
borderRadius: borderRadius ?? BorderRadius.zero,
child: SingleChildScrollView(
physics: StyledScrollPhysics(),
//https://medium.com/saugo360/https-medium-com-saugo360-flutter-using-overlay-to-display-floating-widgets-2e6d0e8decb9
Expand Down

0 comments on commit 1025315

Please sign in to comment.