* chore: move selectionRects to editorState * chore: delete unused attributeKey font * feat: refactor showLinkMenu and LinkMenu * feat: replace old linkMenu * feat: add text color toolbar item - separate text color and highlight color item in toolbar - renaming in BuiltInAttributeKey(color -> textColor, backgroundColor -> highlightColor) - add text color and highlight color attribute in example.json - add icons for text color and highlight color in the toolbar * feat: add highlight color item in toolbar - add clear highlight color button - add onDismiss in ColorPicker to remove the overlay after remove highlight color * chore: delete old ColorPicker * test: migrate link menu test * chore: remove editorStyle from color menu and color picker * test: add color picker test * feat: remove editor style from link menu - add utils function and widgets for overlay - organize utils folder - add constant text into AppFlowyEditorLocalizations - improve pop up menu style * feat: add show link menu command shortcut - refactor CommandShortcutEventHandler - update related callback * feat: add showTextColorMenuCommand and showHighlightColorMenuCommand * fix: fix merge error in example.json * refactor: reorganize the file hierarchy * refactor: migrate format_style_handler_test.dart - delete format_style_handler_test.dart - migrate to markdown_commands_test.dart - move highlight test outside of markdown_commands_test * feat: delete show menu type command shortcut and their tooltip * fix: fix tooltip text * chore: delete context from CommandShortcutEventHandler * feat: add command shortcut for link menu * test: add show link menu command test
243 lines
8.5 KiB
Dart
243 lines
8.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() async {
|
|
setUpAll(() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
});
|
|
|
|
// group('toolbar_service.dart', () {
|
|
// testWidgets('Test toolbar service in multi text selection', (tester) async {
|
|
// const text = 'Welcome to Appflowy 😁';
|
|
// final editor = tester.editor..addParagraphs(3, initialText: text);
|
|
// await editor.startTesting();
|
|
|
|
// final selection = Selection(
|
|
// start: Position(path: [0], offset: 0),
|
|
// end: Position(path: [1], offset: text.length),
|
|
// );
|
|
// await editor.updateSelection(selection);
|
|
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
|
|
// // no link item
|
|
// final item = defaultToolbarItems
|
|
// .where((item) => item.id == 'appflowy.toolbar.link')
|
|
// .first;
|
|
// final finder = find.byType(ToolbarItemWidget);
|
|
|
|
// expect(
|
|
// tester
|
|
// .widgetList<ToolbarItemWidget>(finder)
|
|
// .where((element) => element.item.id == item.id)
|
|
// .isEmpty,
|
|
// true,
|
|
// );
|
|
// });
|
|
|
|
// testWidgets(
|
|
// 'Test toolbar service in single text selection with BuiltInAttributeKey.partialStyleKeys',
|
|
// (tester) async {
|
|
// final attributes = BuiltInAttributeKey.partialStyleKeys
|
|
// .fold<Attributes>({}, (previousValue, element) {
|
|
// if (element == BuiltInAttributeKey.highlightColor) {
|
|
// previousValue[element] = '0x6000BCF0';
|
|
// } else if (element == BuiltInAttributeKey.href) {
|
|
// previousValue[element] = 'appflowy.io';
|
|
// } else {
|
|
// previousValue[element] = true;
|
|
// }
|
|
// return previousValue;
|
|
// });
|
|
|
|
// const text = 'Welcome to Appflowy 😁';
|
|
// final editor = tester.editor
|
|
// ..insertTextNode(text)
|
|
// ..insertTextNode(
|
|
// null,
|
|
// delta: Delta(
|
|
// operations: [
|
|
// TextInsert(text),
|
|
// TextInsert(text, attributes: attributes),
|
|
// TextInsert(text),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// await editor.startTesting();
|
|
// await editor.updateSelection(
|
|
// Selection.single(path: [0], startOffset: 0, endOffset: text.length),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
|
|
// void testHighlight(bool expectedValue) {
|
|
// for (final styleKey in BuiltInAttributeKey.partialStyleKeys) {
|
|
// var key = styleKey;
|
|
// if (styleKey == BuiltInAttributeKey.highlightColor) {
|
|
// key = 'highlight';
|
|
// } else if (styleKey == BuiltInAttributeKey.href) {
|
|
// key = 'link';
|
|
// } else {
|
|
// continue;
|
|
// }
|
|
// final itemWidget = _itemWidgetForId(tester, 'appflowy.toolbar.$key');
|
|
// expect(itemWidget.isHighlight, expectedValue);
|
|
// }
|
|
// }
|
|
|
|
// await editor.updateSelection(
|
|
// Selection.single(path: [1], startOffset: 0, endOffset: text.length * 2),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// testHighlight(false);
|
|
|
|
// await editor.updateSelection(
|
|
// Selection.single(
|
|
// path: [1],
|
|
// startOffset: text.length,
|
|
// endOffset: text.length * 2,
|
|
// ),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// testHighlight(true);
|
|
|
|
// await editor.updateSelection(
|
|
// Selection.single(
|
|
// path: [1],
|
|
// startOffset: text.length + 2,
|
|
// endOffset: text.length * 2 - 2,
|
|
// ),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// testHighlight(true);
|
|
// });
|
|
|
|
// testWidgets(
|
|
// 'Test toolbar service in single text selection with BuiltInAttributeKey.globalStyleKeys',
|
|
// (tester) async {
|
|
// const text = 'Welcome to Appflowy 😁';
|
|
|
|
// final editor = tester.editor
|
|
// ..insertTextNode(
|
|
// text,
|
|
// attributes: {
|
|
// BuiltInAttributeKey.subtype: BuiltInAttributeKey.heading,
|
|
// BuiltInAttributeKey.heading: BuiltInAttributeKey.h1,
|
|
// },
|
|
// )
|
|
// ..insertTextNode(
|
|
// text,
|
|
// attributes: {BuiltInAttributeKey.subtype: BuiltInAttributeKey.quote},
|
|
// )
|
|
// ..insertTextNode(
|
|
// text,
|
|
// attributes: {
|
|
// BuiltInAttributeKey.subtype: BuiltInAttributeKey.bulletedList
|
|
// },
|
|
// );
|
|
// await editor.startTesting();
|
|
|
|
// await editor.updateSelection(
|
|
// Selection.single(path: [0], startOffset: 0, endOffset: text.length),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
// var itemWidget = _itemWidgetForId(tester, 'appflowy.toolbar.h1');
|
|
// expect(itemWidget.isHighlight, true);
|
|
|
|
// await editor.updateSelection(
|
|
// Selection.single(path: [1], startOffset: 0, endOffset: text.length),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
// itemWidget = _itemWidgetForId(tester, 'appflowy.toolbar.quote');
|
|
// expect(itemWidget.isHighlight, true);
|
|
|
|
// await editor.updateSelection(
|
|
// Selection.single(path: [2], startOffset: 0, endOffset: text.length),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
// itemWidget = _itemWidgetForId(tester, 'appflowy.toolbar.bulleted_list');
|
|
// expect(itemWidget.isHighlight, true);
|
|
// });
|
|
|
|
// testWidgets('Test toolbar service in multi text selection', (tester) async {
|
|
// const text = 'Welcome to Appflowy 😁';
|
|
|
|
// /// [h1][bold] Welcome to Appflowy 😁
|
|
// /// [EmptyLine]
|
|
// /// Welcome to Appflowy 😁
|
|
// final editor = tester.editor
|
|
// ..insertTextNode(
|
|
// null,
|
|
// attributes: {
|
|
// BuiltInAttributeKey.subtype: BuiltInAttributeKey.heading,
|
|
// BuiltInAttributeKey.heading: BuiltInAttributeKey.h1,
|
|
// },
|
|
// delta: Delta(
|
|
// operations: [
|
|
// TextInsert(
|
|
// text,
|
|
// attributes: {
|
|
// BuiltInAttributeKey.bold: true,
|
|
// },
|
|
// )
|
|
// ],
|
|
// ),
|
|
// )
|
|
// ..insertTextNode(null)
|
|
// ..insertTextNode(text);
|
|
// await editor.startTesting();
|
|
|
|
// await editor.updateSelection(
|
|
// Selection.single(path: [2], startOffset: text.length, endOffset: 0),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
// expect(
|
|
// _itemWidgetForId(tester, 'appflowy.toolbar.h1').isHighlight,
|
|
// false,
|
|
// );
|
|
// expect(
|
|
// _itemWidgetForId(tester, 'appflowy.toolbar.bold').isHighlight,
|
|
// false,
|
|
// );
|
|
|
|
// await editor.updateSelection(
|
|
// Selection(
|
|
// start: Position(path: [2], offset: text.length),
|
|
// end: Position(path: [1], offset: 0),
|
|
// ),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
// expect(
|
|
// _itemWidgetForId(tester, 'appflowy.toolbar.bold').isHighlight,
|
|
// false,
|
|
// );
|
|
|
|
// await editor.updateSelection(
|
|
// Selection(
|
|
// start: Position(path: [2], offset: text.length),
|
|
// end: Position(path: [0], offset: 0),
|
|
// ),
|
|
// );
|
|
// await tester.pumpAndSettle(const Duration(milliseconds: 500));
|
|
// expect(find.byType(ToolbarWidget), findsOneWidget);
|
|
// expect(
|
|
// _itemWidgetForId(tester, 'appflowy.toolbar.bold').isHighlight,
|
|
// false,
|
|
// );
|
|
// });
|
|
// });
|
|
}
|
|
|
|
// ToolbarItemWidget _itemWidgetForId(WidgetTester tester, String id) {
|
|
// final finder = find.byType(ToolbarItemWidget);
|
|
// final itemWidgets = tester
|
|
// .widgetList<ToolbarItemWidget>(finder)
|
|
// .where((element) => element.item.id == id);
|
|
// expect(itemWidgets.length, 1);
|
|
// return itemWidgets.first;
|
|
// }
|