test: migrate test/core
This commit is contained in:
parent
2e3af171b7
commit
4f18b26715
2 changed files with 143 additions and 151 deletions
|
|
@ -1,143 +0,0 @@
|
|||
// import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
// import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
// import '../../infra/test_editor.dart';
|
||||
|
||||
// void main() {
|
||||
// group('command_extension.dart', () {
|
||||
// testWidgets('getTextInSelection w/ multiple nodes', (tester) async {
|
||||
// final editor = tester.editor
|
||||
// ..insertTextNode(
|
||||
// 'Welcome',
|
||||
// )
|
||||
// ..insertTextNode(
|
||||
// 'to',
|
||||
// )
|
||||
// ..insertTextNode(
|
||||
// 'Appflowy 😁',
|
||||
// );
|
||||
|
||||
// await editor.startTesting();
|
||||
|
||||
// final selection = Selection(
|
||||
// start: Position(path: [2], offset: 5),
|
||||
// end: Position(path: [0], offset: 5),
|
||||
// );
|
||||
|
||||
// await editor.updateSelection(selection);
|
||||
|
||||
// final textNodes = editor
|
||||
// .editorState.service.selectionService.currentSelectedNodes
|
||||
// .whereType<TextNode>()
|
||||
// .toList(growable: false);
|
||||
|
||||
// final text = editor.editorState.getTextInSelection(
|
||||
// textNodes.normalized,
|
||||
// selection.normalized,
|
||||
// );
|
||||
|
||||
// expect(text, ['me', 'to', 'Appfl']);
|
||||
// });
|
||||
|
||||
// testWidgets('getTextInSelection where selection.isSingle', (tester) async {
|
||||
// final editor = tester.editor
|
||||
// ..insertTextNode(
|
||||
// 'Welcome',
|
||||
// )
|
||||
// ..insertTextNode(
|
||||
// 'to',
|
||||
// )
|
||||
// ..insertTextNode(
|
||||
// 'Appflowy 😁',
|
||||
// );
|
||||
|
||||
// await editor.startTesting();
|
||||
|
||||
// final selection = Selection(
|
||||
// start: Position(path: [0], offset: 3),
|
||||
// end: Position(path: [0]),
|
||||
// );
|
||||
|
||||
// await editor.updateSelection(selection);
|
||||
|
||||
// final textNodes = editor
|
||||
// .editorState.service.selectionService.currentSelectedNodes
|
||||
// .whereType<TextNode>()
|
||||
// .toList(growable: false);
|
||||
|
||||
// final text = editor.editorState.getTextInSelection(
|
||||
// textNodes.normalized,
|
||||
// selection.normalized,
|
||||
// );
|
||||
|
||||
// expect(text, ['Wel']);
|
||||
// });
|
||||
|
||||
// testWidgets('getNode throws if node and path are null', (tester) async {
|
||||
// final editor = tester.editor;
|
||||
// await editor.startTesting();
|
||||
|
||||
// expect(() => editor.editorState.getNode(), throwsA(isA<Exception>()));
|
||||
// });
|
||||
|
||||
// testWidgets('getNode by path', (tester) async {
|
||||
// final editor = tester.editor
|
||||
// ..insertTextNode(
|
||||
// 'Welcome',
|
||||
// )
|
||||
// ..insertTextNode(
|
||||
// 'to',
|
||||
// )
|
||||
// ..insertTextNode(
|
||||
// 'Appflowy 😁',
|
||||
// );
|
||||
|
||||
// await editor.startTesting();
|
||||
|
||||
// final node = editor.editorState.getNode(path: [0]) as TextNode;
|
||||
|
||||
// expect(node.type, 'text');
|
||||
// expect((node.delta.first as TextInsert).text, 'Welcome');
|
||||
// });
|
||||
|
||||
// testWidgets('getTextNode throws if textNode and path are null',
|
||||
// (tester) async {
|
||||
// final editor = tester.editor;
|
||||
// await editor.startTesting();
|
||||
|
||||
// expect(() => editor.editorState.getTextNode(), throwsA(isA<Exception>()));
|
||||
// });
|
||||
|
||||
// testWidgets('getTextNode by path', (tester) async {
|
||||
// final editor = tester.editor
|
||||
// ..insertTextNode(
|
||||
// 'Welcome',
|
||||
// )
|
||||
// ..insertTextNode(
|
||||
// 'to',
|
||||
// )
|
||||
// ..insertTextNode(
|
||||
// 'Appflowy 😁',
|
||||
// );
|
||||
|
||||
// await editor.startTesting();
|
||||
|
||||
// final node = editor.editorState.getTextNode(path: [1]);
|
||||
|
||||
// expect(node.type, 'text');
|
||||
// expect((node.delta.first as TextInsert).text, 'to');
|
||||
// });
|
||||
|
||||
// testWidgets(
|
||||
// 'getSelection throws if selection and selectionService.currentSelection are null',
|
||||
// (tester) async {
|
||||
// final editor = tester.editor;
|
||||
// await editor.startTesting();
|
||||
|
||||
// expect(
|
||||
// () => editor.editorState.getSelection(null),
|
||||
// throwsA(isA<Exception>()),
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
|
@ -1,218 +0,0 @@
|
|||
// import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
// import 'package:flutter_test/flutter_test.dart';
|
||||
// import '../infra/test_editor.dart';
|
||||
|
||||
// void main() {
|
||||
// group('TextCommands extension tests', () {
|
||||
// testWidgets('insertText', (tester) async {
|
||||
// final editor = tester.editor
|
||||
// ..insertEmptyTextNode()
|
||||
// ..insertTextNode('World');
|
||||
// await editor.startTesting();
|
||||
|
||||
// editor.editorState.insertText(0, 'Hello', path: [0]);
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// expect(
|
||||
// (editor.editorState.getTextNode(path: [0]).delta.first as TextInsert)
|
||||
// .text,
|
||||
// 'Hello',
|
||||
// );
|
||||
// });
|
||||
|
||||
// testWidgets('insertTextAtCurrentSelection', (tester) async {
|
||||
// final editor = tester.editor..insertTextNode('Helrld!');
|
||||
// await editor.startTesting();
|
||||
|
||||
// final selection = Selection(
|
||||
// start: Position(path: [0], offset: 3),
|
||||
// end: Position(path: [0], offset: 3),
|
||||
// );
|
||||
|
||||
// await editor.updateSelection(selection);
|
||||
|
||||
// editor.editorState.insertTextAtCurrentSelection('lo Wo');
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// expect(
|
||||
// (editor.editorState.getTextNode(path: [0]).delta.first as TextInsert)
|
||||
// .text,
|
||||
// 'Hello World!',
|
||||
// );
|
||||
// });
|
||||
|
||||
// testWidgets('formatText', (tester) async {
|
||||
// final editor = tester.editor..insertTextNode('Hello');
|
||||
// await editor.startTesting();
|
||||
|
||||
// final selection = Selection(
|
||||
// start: Position(path: [0]),
|
||||
// end: Position(path: [0], offset: 5),
|
||||
// );
|
||||
|
||||
// await editor.updateSelection(selection);
|
||||
|
||||
// editor.editorState
|
||||
// .formatText(null, {BuiltInAttributeKey.bold: true}, path: [0]);
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// final textNode = editor.editorState.getTextNode(path: [0]);
|
||||
// final textInsert = textNode.delta.first as TextInsert;
|
||||
|
||||
// expect(textInsert.text, 'Hello');
|
||||
// expect(textInsert.attributes?[BuiltInAttributeKey.bold], true);
|
||||
// });
|
||||
|
||||
// testWidgets('formatTextWithBuiltInAttribute w/ Partial Style Key',
|
||||
// (tester) async {
|
||||
// final editor = tester.editor..insertTextNode('Hello');
|
||||
// await editor.startTesting();
|
||||
|
||||
// final selection = Selection(
|
||||
// start: Position(path: [0]),
|
||||
// end: Position(path: [0], offset: 5),
|
||||
// );
|
||||
|
||||
// await editor.updateSelection(selection);
|
||||
|
||||
// editor.editorState.formatTextWithBuiltInAttribute(
|
||||
// BuiltInAttributeKey.underline,
|
||||
// {BuiltInAttributeKey.underline: true},
|
||||
// path: [0],
|
||||
// );
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// final textNode = editor.editorState.getTextNode(path: [0]);
|
||||
// final textInsert = textNode.delta.first as TextInsert;
|
||||
|
||||
// expect(textInsert.text, 'Hello');
|
||||
// expect(textInsert.attributes?[BuiltInAttributeKey.underline], true);
|
||||
// });
|
||||
|
||||
// testWidgets('formatTextWithBuiltInAttribute w/ Global Style Key',
|
||||
// (tester) async {
|
||||
// final editor = tester.editor
|
||||
// ..insertTextNode(
|
||||
// 'Hello',
|
||||
|
||||
// /// Formatting global style over another global style,
|
||||
// /// will remove the existing one before adding the new one
|
||||
// attributes: {BuiltInAttributeKey.checkbox: true},
|
||||
// );
|
||||
// await editor.startTesting();
|
||||
|
||||
// editor.editorState.formatTextWithBuiltInAttribute(
|
||||
// BuiltInAttributeKey.heading,
|
||||
// {BuiltInAttributeKey.heading: BuiltInAttributeKey.h1},
|
||||
// path: [0],
|
||||
// );
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// final textNode = editor.editorState.getTextNode(path: [0]);
|
||||
// final textInsert = textNode.delta.first as TextInsert;
|
||||
|
||||
// expect(textInsert.text, 'Hello');
|
||||
// expect(textNode.attributes.heading, BuiltInAttributeKey.h1);
|
||||
// expect(textNode.attributes['subtype'], BuiltInAttributeKey.heading);
|
||||
// });
|
||||
|
||||
// testWidgets('formatTextToCheckbox', (tester) async {
|
||||
// final editor = tester.editor..insertTextNode('TextNode to Checkbox');
|
||||
// await editor.startTesting();
|
||||
|
||||
// editor.editorState.formatTextToCheckbox(false, path: [0]);
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// final checkboxNode = editor.editorState.getNode(path: [0]);
|
||||
|
||||
// expect(checkboxNode.attributes.check, false);
|
||||
// expect(checkboxNode.attributes['subtype'], BuiltInAttributeKey.checkbox);
|
||||
// });
|
||||
|
||||
// testWidgets('formatLinkInText', (tester) async {
|
||||
// const href = "https://appflowy.io/";
|
||||
|
||||
// final editor = tester.editor..insertTextNode('TextNode to Link');
|
||||
// await editor.startTesting();
|
||||
|
||||
// final selection = Selection(
|
||||
// start: Position(path: [0]),
|
||||
// end: Position(path: [0], offset: 5),
|
||||
// );
|
||||
|
||||
// await editor.updateSelection(selection);
|
||||
|
||||
// editor.editorState.formatLinkInText(href, path: [0]);
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// final textNode = editor.editorState.getTextNode(path: [0]);
|
||||
// final textInsert = textNode.delta.first as TextInsert;
|
||||
|
||||
// expect(textInsert.attributes?[BuiltInAttributeKey.href], href);
|
||||
// });
|
||||
|
||||
// testWidgets('insertNewLine', (tester) async {
|
||||
// final editor = tester.editor;
|
||||
// await editor.startTesting();
|
||||
|
||||
// expect(editor.documentLength, 0);
|
||||
|
||||
// editor.editorState.insertNewLine(path: [0]);
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// expect(editor.documentLength, 1);
|
||||
// });
|
||||
|
||||
// testWidgets('insertNewLine without path', (tester) async {
|
||||
// final editor = tester.editor..insertTextNode('Hello World');
|
||||
// await editor.startTesting();
|
||||
|
||||
// expect(editor.documentLength, 1);
|
||||
|
||||
// final selection = Selection(
|
||||
// start: Position(path: [0], offset: 5),
|
||||
// end: Position(path: [0], offset: 5),
|
||||
// );
|
||||
|
||||
// await editor.updateSelection(selection);
|
||||
|
||||
// editor.editorState.insertNewLine(path: null);
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// expect(editor.documentLength, 2);
|
||||
|
||||
// final textNode = editor.editorState.getTextNode(path: [0]);
|
||||
// final textInsert = textNode.delta.first as TextInsert;
|
||||
|
||||
// expect(textInsert.text, 'Hello World');
|
||||
// });
|
||||
|
||||
// testWidgets('insertNewLineAtCurrentSelection', (tester) async {
|
||||
// final editor = tester.editor..insertTextNode('HelloWorld');
|
||||
// await editor.startTesting();
|
||||
|
||||
// final selection = Selection(
|
||||
// start: Position(path: [0], offset: 5),
|
||||
// end: Position(path: [0], offset: 5),
|
||||
// );
|
||||
|
||||
// await editor.updateSelection(selection);
|
||||
|
||||
// expect(editor.documentLength, 1);
|
||||
|
||||
// editor.editorState.insertNewLineAtCurrentSelection();
|
||||
// await tester.pumpAndSettle();
|
||||
|
||||
// expect(editor.documentLength, 2);
|
||||
|
||||
// final firstTextNode = editor.editorState.getTextNode(path: [0]);
|
||||
// final firstTextInsert = firstTextNode.delta.first as TextInsert;
|
||||
// expect(firstTextInsert.text, 'Hello');
|
||||
|
||||
// final secondTextNode = editor.editorState.getTextNode(path: [1]);
|
||||
// final secondTextInsert = secondTextNode.delta.first as TextInsert;
|
||||
|
||||
// expect(secondTextInsert.text, 'World');
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
Loading…
Reference in a new issue