Skip to content

Commit

Permalink
Use the right platform test runner for golden selection tests (Resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-carroll authored Oct 25, 2023
1 parent 2e02167 commit e622022
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,11 @@ class IosControlsDocumentLayerState extends DocumentLayoutLayerState<IosHandlesD
/// );
/// }
/// ```
typedef DocumentFloatingToolbarBuilder = Widget Function(BuildContext, Key mobileToolbarKey, LeaderLink focalPoint);
typedef DocumentFloatingToolbarBuilder = Widget Function(
BuildContext context,
Key mobileToolbarKey,
LeaderLink focalPoint,
);

/// Builds a full-screen magnifier display, with the magnifier following the given [focalPoint],
/// and with the magnifier attached to the given [magnifierKey].
Expand Down
122 changes: 83 additions & 39 deletions super_editor/test_goldens/editor/mobile/mobile_selection_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -793,48 +793,92 @@ void _testParagraphSelection(
Future<void> Function(WidgetTester, GlobalKey docKey, ValueNotifier<_Line?> dragLine) test, {
int maxPixelMismatchCount = 0,
}) {
final docKey = GlobalKey();

testGoldensOnAndroid(description, (tester) async {
tester.view
..physicalSize = const Size(800, 200)
..devicePixelRatio = 1.0;
tester.binding.platformDispatcher.textScaleFactorTestValue = 1.0;

final dragLine = ValueNotifier<_Line?>(null);

await tester //
.createDocument()
.withCustomContent(_createSingleParagraphDoc())
.withLayoutKey(docKey)
.withGestureMode(platform)
.useStylesheet(Stylesheet(
documentPadding: const EdgeInsets.all(16),
rules: defaultStylesheet.rules,
inlineTextStyler: (attributions, style) => _textStyleBuilder(attributions),
))
.withCustomWidgetTreeBuilder(
(superEditor) {
return _buildScaffold(
dragLine: dragLine,
child: superEditor,
);
},
) //
.pump();
switch (platform) {
case DocumentGestureMode.mouse:
testGoldensOnMac(
description,
(tester) => _runParagraphSelectionTest(
tester,
platform,
goldenName,
test,
maxPixelMismatchCount: maxPixelMismatchCount,
),
);
case DocumentGestureMode.android:
testGoldensOnAndroid(
description,
(tester) => _runParagraphSelectionTest(
tester,
platform,
goldenName,
test,
maxPixelMismatchCount: maxPixelMismatchCount,
),
);
case DocumentGestureMode.iOS:
testGoldensOniOS(
description,
(tester) => _runParagraphSelectionTest(
tester,
platform,
goldenName,
test,
maxPixelMismatchCount: maxPixelMismatchCount,
),
);
}
}

// Run the test
await test(tester, docKey, dragLine);
Future<void> _runParagraphSelectionTest(
WidgetTester tester,
DocumentGestureMode platform,
String goldenName,
Future<void> Function(WidgetTester, GlobalKey docKey, ValueNotifier<_Line?> dragLine) test, {
int maxPixelMismatchCount = 0,
}) async {
final docKey = GlobalKey();

// Compare the golden
await tester.pumpAndSettle();
await expectLater(
find.byType(_DragLinePaint),
matchesGoldenFileWithPixelAllowance("goldens/$goldenName.png", maxPixelMismatchCount),
);
tester.view
..physicalSize = const Size(800, 200)
..devicePixelRatio = 1.0;
tester.binding.platformDispatcher.textScaleFactorTestValue = 1.0;

final dragLine = ValueNotifier<_Line?>(null);

await tester //
.createDocument()
.withCustomContent(_createSingleParagraphDoc())
.withLayoutKey(docKey)
.withGestureMode(platform)
.useStylesheet(Stylesheet(
documentPadding: const EdgeInsets.all(16),
rules: defaultStylesheet.rules,
inlineTextStyler: (attributions, style) => _textStyleBuilder(attributions),
))
// Don't build a floating toolbar. It's a distraction for the details we care to verify.
.withiOSToolbarBuilder((context, mobileToolbarKey, focalPoint) => const SizedBox())
.withCustomWidgetTreeBuilder(
(superEditor) {
return _buildScaffold(
dragLine: dragLine,
child: superEditor,
);
},
) //
.pump();

// Run the test
await test(tester, docKey, dragLine);

// Compare the golden
await tester.pumpAndSettle();
await expectLater(
find.byType(_DragLinePaint),
matchesGoldenFileWithPixelAllowance("goldens/$goldenName.png", maxPixelMismatchCount),
);

tester.view.resetPhysicalSize();
});
tester.view.resetPhysicalSize();
}

Widget _buildScaffold({
Expand Down

0 comments on commit e622022

Please sign in to comment.