Skip to content

Commit ea96050

Browse files
committed
chore: fix multiline scrolling tests for desktop + mobile
chore: fix desktop test
1 parent f7b2f5a commit ea96050

File tree

1 file changed

+50
-28
lines changed

1 file changed

+50
-28
lines changed

super_editor/test/super_textfield/super_textfield_gesture_scrolling_test.dart

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,11 @@ void main() {
251251
});
252252

253253
testWidgetsOnMobile("multi-line is vertically scrollable when text spans more lines than maxLines", (tester) async {
254+
final initialText = "The first line of text in the field\n"
255+
"The second line of text in the field\n"
256+
"The third line of text in the field";
254257
final controller = AttributedTextEditingController(
255-
text: AttributedText("A\nB\nC"),
258+
text: AttributedText(initialText),
256259
);
257260

258261
// Pump the widget tree with a SuperTextField with a maxHeight of 2 lines
@@ -265,31 +268,38 @@ void main() {
265268
maxHeight: 40,
266269
);
267270

268-
// Move selection to the end of the text
269-
// TODO: change to simulate user input when IME simulation is available
270-
controller.selection = const TextSelection.collapsed(offset: 5);
271+
double getTextBottom() {
272+
return tester.getBottomRight(find.byType(SuperTextField)).dy;
273+
}
274+
275+
double getViewportBottom() {
276+
return tester.getBottomRight(find.byType(SuperText)).dy;
277+
}
278+
279+
// Ensure the text field has not yet scrolled.
280+
expect(getTextBottom(), lessThan(getViewportBottom()));
281+
282+
// Scroll down to reveal the last line of text.
283+
await tester.drag(find.byType(SuperTextField), const Offset(0, -1000.0));
271284
await tester.pumpAndSettle();
272285

273286
// Ensure the text field has scrolled to the bottom.
274-
expect(
275-
SuperTextFieldInspector.findScrollOffset(),
276-
greaterThan(0.0),
277-
);
287+
expect(getTextBottom(), equals(getViewportBottom()));
278288

279-
// Scroll upwards towards the top of the text field.
280-
await tester.drag(find.byType(SuperTextField), const Offset(0, -1000));
289+
// Scroll back up to the top of the text field.
290+
await tester.drag(find.byType(SuperTextField), const Offset(0, 1000.0));
281291
await tester.pumpAndSettle();
282292

283293
// Ensure the text field has scrolled back to the top.
284-
expect(
285-
SuperTextFieldInspector.findScrollOffset(),
286-
0.0,
287-
);
294+
expect(getTextBottom(), lessThan(getViewportBottom()));
288295
});
289296

290297
testWidgetsOnDesktop("multi-line is vertically scrollable when text spans more lines than maxLines", (tester) async {
298+
final initialText = "The first line of text in the field\n"
299+
"The second line of text in the field\n"
300+
"The third line of text in the field";
291301
final controller = AttributedTextEditingController(
292-
text: AttributedText("A\nB\nC"),
302+
text: AttributedText(initialText),
293303
);
294304

295305
// Pump the widget tree with a SuperTextField with a maxHeight of 2 lines
@@ -302,26 +312,38 @@ void main() {
302312
maxHeight: 40,
303313
);
304314

305-
// Move selection to the end of the text
306-
// TODO: change to simulate user input when IME simulation is available
307-
controller.selection = const TextSelection.collapsed(offset: 5);
315+
double getTextBottom() {
316+
return tester.getBottomRight(find.byType(SuperTextField)).dy;
317+
}
318+
319+
double getViewportBottom() {
320+
return tester.getBottomRight(find.byType(SuperText)).dy;
321+
}
322+
323+
// Ensure the text field has not yet scrolled.
324+
expect(getTextBottom(), lessThan(getViewportBottom()));
325+
326+
// Scroll down to reveal the last line of text.
327+
await tester.drag(
328+
find.byType(SuperTextField),
329+
const Offset(0, -1000.0),
330+
kind: PointerDeviceKind.trackpad,
331+
);
308332
await tester.pumpAndSettle();
309333

310334
// Ensure the text field has scrolled to the bottom.
311-
expect(
312-
SuperTextFieldInspector.findScrollOffset(),
313-
greaterThan(0.0),
314-
);
335+
expect(getTextBottom(), equals(getViewportBottom()));
315336

316-
// Scroll upwards towards the top of the text field.
317-
await tester.drag(find.byType(SuperTextField), const Offset(0, -1000));
337+
// Scroll back up to the top of the text field.
338+
await tester.drag(
339+
find.byType(SuperTextField),
340+
const Offset(0, 1000.0),
341+
kind: PointerDeviceKind.trackpad,
342+
);
318343
await tester.pumpAndSettle();
319344

320345
// Ensure the text field has scrolled back to the top.
321-
expect(
322-
SuperTextFieldInspector.findScrollOffset(),
323-
0.0,
324-
);
346+
expect(getTextBottom(), lessThan(getViewportBottom()));
325347
});
326348
});
327349
}

0 commit comments

Comments
 (0)