mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: the markdown file name doesn't update after renaming the document (#2777)
* fix: the markdown file name doesn't update after renaming the document * test: add integration test
This commit is contained in:
parent
335861706e
commit
5bcf48a4f9
@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
|
||||
@ -47,6 +48,38 @@ void main() {
|
||||
final markdown = file.readAsStringSync();
|
||||
expect(markdown, expectedMarkdown);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'share the markdown after renaming the document name',
|
||||
(tester) async {
|
||||
await tester.initializeAppFlowy();
|
||||
await tester.tapGoButton();
|
||||
|
||||
// expect to see a readme page
|
||||
tester.expectToSeePageName(readme);
|
||||
|
||||
// rename the document
|
||||
await tester.hoverOnPageName(readme);
|
||||
await tester.renamePage('example');
|
||||
|
||||
final shareButton = find.byType(ShareActionList);
|
||||
final shareButtonState =
|
||||
tester.state(shareButton) as ShareActionListState;
|
||||
final path =
|
||||
await mockSaveFilePath(location, '${shareButtonState.name}.md');
|
||||
|
||||
// click the share button and select markdown
|
||||
await tester.tapShareButton();
|
||||
await tester.tapMarkdownButton();
|
||||
|
||||
// expect to see the success dialog
|
||||
tester.expectToExportSuccess();
|
||||
|
||||
final file = File(path);
|
||||
final isExist = file.existsSync();
|
||||
expect(isExist, true);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ import 'package:appflowy/workspace/presentation/home/menu/app/section/item.dart'
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||
import 'package:flowy_infra_ui/widget/buttons/primary_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'base.dart';
|
||||
@ -79,6 +81,26 @@ extension CommonOperations on WidgetTester {
|
||||
await tapButtonWithName(ViewDisclosureAction.delete.name);
|
||||
}
|
||||
|
||||
Future<void> tapRenamePageButton() async {
|
||||
await tapPageOptionButton();
|
||||
await tapButtonWithName(ViewDisclosureAction.rename.name);
|
||||
}
|
||||
|
||||
Future<void> renamePage(String name) async {
|
||||
await tapRenamePageButton();
|
||||
await enterText(find.byType(TextFormField), name);
|
||||
await tapOKButton();
|
||||
}
|
||||
|
||||
Future<void> tapOKButton() async {
|
||||
final okButton = find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is PrimaryTextButton &&
|
||||
widget.label == LocaleKeys.button_OK.tr(),
|
||||
);
|
||||
await tapButton(okButton);
|
||||
}
|
||||
|
||||
void expectToSeeDocumentBanner() {
|
||||
expect(find.byType(DocumentBanner), findsOneWidget);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';
|
||||
import 'package:appflowy/startup/startup.dart';
|
||||
import 'package:appflowy/plugins/document/application/share_bloc.dart';
|
||||
import 'package:appflowy/util/file_picker/file_picker_service.dart';
|
||||
import 'package:appflowy/workspace/application/view/view_listener.dart';
|
||||
import 'package:appflowy/workspace/presentation/home/toast.dart';
|
||||
import 'package:appflowy/workspace/presentation/widgets/pop_up_action.dart';
|
||||
import 'package:appflowy_backend/protobuf/flowy-document2/entities.pb.dart';
|
||||
@ -68,7 +69,7 @@ class DocumentShareButton extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class ShareActionList extends StatelessWidget {
|
||||
class ShareActionList extends StatefulWidget {
|
||||
const ShareActionList({
|
||||
super.key,
|
||||
required this.view,
|
||||
@ -76,6 +77,27 @@ class ShareActionList extends StatelessWidget {
|
||||
|
||||
final ViewPB view;
|
||||
|
||||
@override
|
||||
State<ShareActionList> createState() => ShareActionListState();
|
||||
}
|
||||
|
||||
@visibleForTesting
|
||||
class ShareActionListState extends State<ShareActionList> {
|
||||
late String name;
|
||||
late final ViewListener viewListener = ViewListener(view: widget.view);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
listenOnViewUpdated();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
viewListener.stop();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final docShareBloc = context.read<DocShareBloc>();
|
||||
@ -96,7 +118,7 @@ class ShareActionList extends StatelessWidget {
|
||||
case ShareAction.markdown:
|
||||
final exportPath = await getIt<FilePickerService>().saveFile(
|
||||
dialogTitle: '',
|
||||
fileName: '${view.name}.md',
|
||||
fileName: '$name.md',
|
||||
);
|
||||
if (exportPath != null) {
|
||||
docShareBloc.add(DocShareEvent.shareMarkdown(exportPath));
|
||||
@ -107,6 +129,15 @@ class ShareActionList extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void listenOnViewUpdated() {
|
||||
name = widget.view.name;
|
||||
viewListener.start(
|
||||
onViewUpdated: (view) {
|
||||
name = view.fold((l) => l.name, (r) => '');
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
enum ShareAction {
|
||||
|
@ -37,7 +37,7 @@ class InitAppWindowTask extends LaunchTask with WindowListener {
|
||||
title: title,
|
||||
);
|
||||
|
||||
await windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
windowManager.waitUntilReadyToShow(windowOptions, () async {
|
||||
await windowManager.show();
|
||||
await windowManager.focus();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user