fix: replace matches on the same node (#418)
* test: failing test for expected behavior * test: fix test by removing enter * fix: replace all fixed * chore: remove unused code * test: replace selected called multiple times * chore: remove unused variable
This commit is contained in:
parent
a9af2bbd37
commit
e38b07d13b
2 changed files with 121 additions and 56 deletions
|
|
@ -197,6 +197,44 @@ void main() async {
|
|||
await editor.dispose();
|
||||
});
|
||||
|
||||
testWidgets('replace match on multiple matches in same path',
|
||||
(tester) async {
|
||||
const patternToBeFound = 'a';
|
||||
const replacePattern = 'test';
|
||||
const replaceSelectedBtn = Key('replaceSelectedButton');
|
||||
const multiplier = 5;
|
||||
|
||||
final editor = tester.editor;
|
||||
editor.addParagraph(initialText: patternToBeFound * multiplier);
|
||||
|
||||
await editor.startTesting();
|
||||
await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
|
||||
|
||||
await pressFindAndReplaceCommand(editor, openReplace: true);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FindMenuWidget), findsOneWidget);
|
||||
|
||||
//we put the pattern in the find dialog and press enter
|
||||
await enterInputIntoFindDialog(tester, patternToBeFound);
|
||||
|
||||
//now we input some text into the replace text field and try replace all
|
||||
await enterInputIntoReplaceDialog(
|
||||
tester,
|
||||
replacePattern,
|
||||
);
|
||||
|
||||
for (int i = 0; i < multiplier; i++) {
|
||||
await tester.tap(find.byKey(replaceSelectedBtn));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
//all matches should be replaced
|
||||
final node = editor.nodeAtPath([0]);
|
||||
expect(node!.delta!.toPlainText(), replacePattern * multiplier);
|
||||
await editor.dispose();
|
||||
});
|
||||
|
||||
testWidgets('replace all on found matches', (tester) async {
|
||||
const patternToBeFound = 'Welcome';
|
||||
const replacePattern = 'Salute';
|
||||
|
|
@ -239,5 +277,39 @@ void main() async {
|
|||
}
|
||||
await editor.dispose();
|
||||
});
|
||||
|
||||
testWidgets('replace all on found matches in same path', (tester) async {
|
||||
const patternToBeFound = 'x';
|
||||
const replacePattern = 'Mayur';
|
||||
const replaceAllBtn = Key('replaceAllButton');
|
||||
|
||||
final editor = tester.editor;
|
||||
editor.addParagraph(initialText: patternToBeFound * 5);
|
||||
|
||||
await editor.startTesting();
|
||||
await editor.updateSelection(Selection.single(path: [0], startOffset: 0));
|
||||
|
||||
await pressFindAndReplaceCommand(editor, openReplace: true);
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FindMenuWidget), findsOneWidget);
|
||||
|
||||
//we put the pattern in the find dialog and press enter
|
||||
await enterInputIntoFindDialog(tester, patternToBeFound);
|
||||
|
||||
//now we input some text into the replace text field and try replace all
|
||||
await enterInputIntoReplaceDialog(
|
||||
tester,
|
||||
replacePattern,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(replaceAllBtn));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
//all matches should be replaced
|
||||
final node = editor.nodeAtPath([0]);
|
||||
expect(node!.delta!.toPlainText(), replacePattern * 5);
|
||||
await editor.dispose();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,6 +75,16 @@ Future<void> enterInputIntoFindDialog(
|
|||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> enterInputIntoReplaceDialog(
|
||||
WidgetTester tester,
|
||||
String pattern,
|
||||
) async {
|
||||
const textInputKey = Key('replaceTextField');
|
||||
await tester.tap(find.byKey(textInputKey));
|
||||
await tester.enterText(find.byKey(textInputKey), pattern);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> pressFindAndReplaceCommand(
|
||||
TestableEditor editor, {
|
||||
bool openReplace = false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue