Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c6fe412

Browse files
Renzo-OlivaresRenzo Olivares
andauthored
Re-enable SelectableRegion web tests (#169541)
This change re-enables some `SelectableRegion` tests now that flutter/flutter#125582 has been closed. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Renzo Olivares <[email protected]>
1 parent 0d349d7 commit c6fe412

2 files changed

Lines changed: 87 additions & 8 deletions

File tree

packages/flutter/test/widgets/scrollable_selection_test.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import 'dart:ui' as ui;
66

7-
import 'package:flutter/foundation.dart';
87
import 'package:flutter/material.dart';
98
import 'package:flutter/rendering.dart';
109
import 'package:flutter/services.dart';
@@ -188,7 +187,7 @@ void main() {
188187
expect(paragraph3.selections[0], const TextSelection(baseOffset: 0, extentOffset: 4));
189188

190189
await gesture.up();
191-
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/125582.
190+
});
192191

193192
testWidgets('mouse can select multiple widgets on double-click drag - horizontal', (
194193
WidgetTester tester,
@@ -238,7 +237,7 @@ void main() {
238237
expect(paragraph2.selections[0], const TextSelection(baseOffset: 0, extentOffset: 6));
239238

240239
await gesture.up();
241-
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/125582.
240+
});
242241

243242
testWidgets('mouse can select multiple widgets on triple-click drag', (
244243
WidgetTester tester,
@@ -310,7 +309,7 @@ void main() {
310309
expect(paragraph4.selections[0], const TextSelection(baseOffset: 0, extentOffset: 6));
311310

312311
await gesture.up();
313-
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/125582.
312+
});
314313

315314
testWidgets('mouse can select multiple widgets on triple-click drag - horizontal', (
316315
WidgetTester tester,
@@ -372,7 +371,7 @@ void main() {
372371
expect(paragraph3.selections[0], const TextSelection(baseOffset: 0, extentOffset: 6));
373372

374373
await gesture.up();
375-
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/125582.
374+
});
376375

377376
testWidgets('select to scroll forward', (WidgetTester tester) async {
378377
final ScrollController controller = ScrollController();

packages/flutter/test/widgets/selectable_region_test.dart

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,88 @@ void main() {
443443
expect(pageController.page, isNotNull);
444444
expect(pageController.page, 1.0);
445445
},
446-
variant: TargetPlatformVariant.mobile(),
447-
skip: kIsWeb, // https://github.com/flutter/flutter/issues/125582.
446+
variant: const TargetPlatformVariant(<TargetPlatform>{
447+
TargetPlatform.android,
448+
TargetPlatform.fuchsia,
449+
}),
450+
// [intended] Web does not support double tap + drag gestures on the tested platforms.
451+
skip: kIsWeb,
452+
);
453+
454+
testWidgets(
455+
'Vertical PageView beats SelectionArea child touch drag gestures on iOS',
456+
(WidgetTester tester) async {
457+
// Regression test for https://github.com/flutter/flutter/issues/150897.
458+
final PageController pageController = PageController();
459+
const String testValue = 'abc def ghi jkl mno pqr stu vwx yz';
460+
addTearDown(pageController.dispose);
461+
462+
await tester.pumpWidget(
463+
MaterialApp(
464+
home: PageView(
465+
scrollDirection: Axis.vertical,
466+
controller: pageController,
467+
children: <Widget>[
468+
Center(
469+
child: SelectableRegion(
470+
selectionControls: materialTextSelectionControls,
471+
child: const Text(testValue),
472+
),
473+
),
474+
const SizedBox(height: 200.0, child: Center(child: Text('Page 2'))),
475+
],
476+
),
477+
),
478+
);
479+
480+
final RenderParagraph paragraph = tester.renderObject<RenderParagraph>(
481+
find.descendant(of: find.text(testValue), matching: find.byType(RichText)),
482+
);
483+
final Offset gPos = textOffsetToPosition(paragraph, testValue.indexOf('g'));
484+
final Offset pPos = textOffsetToPosition(paragraph, testValue.indexOf('p'));
485+
486+
// A double tap + drag should take precedence over parent drags.
487+
final TestGesture gesture = await tester.startGesture(gPos);
488+
addTearDown(gesture.removePointer);
489+
await tester.pump();
490+
await gesture.up();
491+
await tester.pump();
492+
await gesture.down(gPos);
493+
await tester.pumpAndSettle();
494+
await gesture.moveTo(pPos);
495+
await tester.pump();
496+
await gesture.up();
497+
await tester.pumpAndSettle();
498+
expect(paragraph.selections, isNotEmpty);
499+
expect(
500+
paragraph.selections[0],
501+
TextSelection(
502+
baseOffset: testValue.indexOf('g'),
503+
extentOffset: testValue.indexOf('p') + 3,
504+
),
505+
);
506+
507+
expect(pageController.page, isNotNull);
508+
expect(pageController.page, 0.0);
509+
// A vertical drag directly on the SelectableRegion should move the page
510+
// view to the next page.
511+
final Rect selectableTextRect = tester.getRect(find.byType(SelectableRegion));
512+
// Simulate a pan by drag vertically first.
513+
await gesture.down(selectableTextRect.center);
514+
await tester.pump();
515+
await gesture.moveTo(selectableTextRect.center + const Offset(0.0, -200.0));
516+
// Introduce horizontal movement.
517+
await gesture.moveTo(selectableTextRect.center + const Offset(5.0, -300.0));
518+
await gesture.moveTo(selectableTextRect.center + const Offset(-10.0, -400.0));
519+
// Continue dragging vertically.
520+
await gesture.moveTo(selectableTextRect.center + const Offset(0.0, -500.0));
521+
await tester.pump();
522+
await gesture.up();
523+
await tester.pumpAndSettle();
524+
expect(pageController.page, isNotNull);
525+
expect(pageController.page, 1.0);
526+
},
527+
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
448528
);
449529

450530
testWidgets('mouse single-click selection collapses the selection', (
@@ -6261,7 +6341,7 @@ void main() {
62616341
await tester.pumpAndSettle();
62626342
expect(find.text('Copy'), findsNothing);
62636343
},
6264-
skip: !kIsWeb, // [intended]
6344+
skip: !kIsWeb, // [intended] This test verifies web behavior.
62656345
);
62666346
});
62676347

0 commit comments

Comments
 (0)