Skip to content

Commit 9f5cb70

Browse files
committed
Fix history tests
1 parent 207269a commit 9f5cb70

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

packages/fleather/test/testing.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:fleather/fleather.dart';
6+
import 'package:fleather/src/widgets/editor_input_client_mixin.dart';
67
import 'package:flutter/material.dart';
78
import 'package:flutter_test/flutter_test.dart';
89
import 'package:quill_delta/quill_delta.dart';
@@ -201,3 +202,7 @@ class TestUpdateWidgetState extends State<TestUpdateWidget> {
201202
],
202203
);
203204
}
205+
206+
RawEditorStateTextInputClientMixin getInputClient() =>
207+
(find.byType(RawEditor).evaluate().single as StatefulElement).state
208+
as RawEditorStateTextInputClientMixin;

packages/fleather/test/widgets/history_test.dart

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:fleather/fleather.dart';
2+
import 'package:fleather/src/widgets/editor_input_client_mixin.dart';
23
import 'package:fleather/src/widgets/history.dart';
34
import 'package:flutter/material.dart';
45
import 'package:flutter/services.dart';
6+
import 'package:flutter/widgets.dart';
57
import 'package:flutter_test/flutter_test.dart';
68
import 'package:quill_delta/quill_delta.dart';
79

@@ -137,9 +139,17 @@ void main() {
137139
..delete(5)
138140
..insert('mmmmm,', {'i': true}));
139141
await editor.pump();
140-
await editor.enterText(const TextEditingValue(
141-
text: 'Something in the way mmmmm,\n',
142-
selection: TextSelection.collapsed(offset: 26)));
142+
final inputClient = getInputClient();
143+
inputClient.openConnectionIfNeeded();
144+
inputClient.updateEditingValueWithDeltas([
145+
const TextEditingDeltaInsertion(
146+
oldText: 'Something in the way mmmmm',
147+
textInserted: ',',
148+
insertionOffset: initialLength,
149+
selection: TextSelection.collapsed(offset: 26),
150+
composing: TextRange.collapsed(26))
151+
]);
152+
143153
// Throttle time of 500ms in history
144154
await tester.pump(const Duration(milliseconds: 500));
145155
await tester.pumpAndSettle();
@@ -204,6 +214,16 @@ void main() {
204214
Future<void> enterText(TextEditingValue text) async {
205215
return TestAsyncUtils.guard<void>(() async {
206216
await showKeyboard();
217+
final inputClient = getInputClient();
218+
inputClient.updateEditingValueWithDeltas([
219+
TextEditingDeltaInsertion(
220+
oldText: inputClient.textEditingValue.text,
221+
textInserted: text.text,
222+
insertionOffset: 0,
223+
selection: text.selection,
224+
composing: text.composing,
225+
)
226+
]);
207227
tester.binding.testTextInput.updateEditingValue(text);
208228
await tester.idle();
209229
await tester.pumpAndSettle();
@@ -224,7 +244,7 @@ void main() {
224244
await tester.tap(find.byType(TextButton));
225245

226246
await enterText(const TextEditingValue(
227-
text: 'Something in the way mmmmm\n',
247+
text: 'Something in the way mmmmm',
228248
selection: TextSelection.collapsed(offset: 26)));
229249
// Throttle time of 500ms in history
230250
await tester.pump(const Duration(milliseconds: 500));

0 commit comments

Comments
 (0)