feat(app): finish native run Changes wiring and scaled form menus
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/changes/changes.dart';
|
||||
import 'package:pipelines_app/features/changes/widgets/change_style.dart';
|
||||
@@ -16,6 +17,64 @@ const _raggedPatch =
|
||||
'-x\n'
|
||||
' tail\n';
|
||||
|
||||
/// Opens the real single-file diff modal from a host, so the test covers the
|
||||
/// dialog's own width and insets rather than the viewer in isolation.
|
||||
Widget _diffDialogOpener(FileChange file) => Builder(
|
||||
builder: (context) => TextButton(
|
||||
onPressed: () => showFileDiffViewer(context, file),
|
||||
child: const Text('Open diff'),
|
||||
),
|
||||
);
|
||||
|
||||
/// Fails when a fixed control label is broken inside a word or clipped by its
|
||||
/// control. A label may wrap only between whole words, which is how a native
|
||||
/// menu keeps an accessibility-size label readable.
|
||||
void _expectWholeLabel(WidgetTester tester, Finder finder, String label) {
|
||||
final paragraph = tester.renderObject<RenderParagraph>(
|
||||
find.descendant(of: finder, matching: find.byType(RichText)),
|
||||
);
|
||||
final span = paragraph.text as TextSpan;
|
||||
expect(span.toPlainText(), label);
|
||||
expect(paragraph.didExceedMaxLines, isFalse);
|
||||
final boxes = paragraph
|
||||
.getBoxesForSelection(
|
||||
TextSelection(baseOffset: 0, extentOffset: label.length),
|
||||
)
|
||||
.toList();
|
||||
expect(boxes, isNotEmpty);
|
||||
// The laid-out paragraph must be tall enough to paint every line it broke.
|
||||
expect(
|
||||
boxes.last.bottom,
|
||||
lessThanOrEqualTo(paragraph.size.height + 0.5),
|
||||
reason: '"$label" must not be clipped vertically',
|
||||
);
|
||||
final widestLine = boxes
|
||||
.map((box) => box.right - box.left)
|
||||
.reduce((a, b) => a > b ? a : b);
|
||||
final style = span.style ?? const TextStyle();
|
||||
var widestWord = 0.0;
|
||||
for (final word in label.split(' ')) {
|
||||
final painter = TextPainter(
|
||||
text: TextSpan(text: word, style: style),
|
||||
textDirection: TextDirection.ltr,
|
||||
textScaler: paragraph.textScaler,
|
||||
)..layout();
|
||||
if (painter.width > widestWord) widestWord = painter.width;
|
||||
}
|
||||
// A line narrower than a whole word means the label broke mid-word.
|
||||
expect(
|
||||
widestLine,
|
||||
greaterThanOrEqualTo(widestWord - 0.5),
|
||||
reason: '"$label" must not break inside a word',
|
||||
);
|
||||
// A clipped line would paint wider than the paragraph's laid-out box.
|
||||
expect(
|
||||
widestLine,
|
||||
lessThanOrEqualTo(paragraph.size.width + 0.5),
|
||||
reason: '"$label" must not be clipped horizontally',
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'patch typography preserves the native host style without overrides',
|
||||
@@ -139,6 +198,49 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the Cupertino raw patch is a native selectable field', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
cupertinoHost(
|
||||
SizedBox(
|
||||
height: 400,
|
||||
child: FileDiffViewer(
|
||||
file: FileChange(
|
||||
path: 'lib/feature.dart',
|
||||
kind: ChangeKind.modified,
|
||||
patch: multiHunkPatch,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Raw patch'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A CupertinoApp has no MaterialLocalizations, so Raw must not use the
|
||||
// Material SelectionArea; it renders the recorded bytes in a native field.
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.byType(SelectionArea), findsNothing);
|
||||
final field = tester.widget<CupertinoTextField>(
|
||||
find.byKey(const ValueKey('raw-patch-field')),
|
||||
);
|
||||
expect(field.readOnly, isTrue);
|
||||
expect(field.maxLines, isNull);
|
||||
expect(field.controller?.text, multiHunkPatch);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.byKey(const ValueKey('raw-patch-field')),
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is SingleChildScrollView &&
|
||||
widget.scrollDirection == Axis.horizontal,
|
||||
),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('a Cupertino row wraps its recorded path instead of clipping it', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -203,4 +305,98 @@ void main() {
|
||||
expect(rect.right, lessThan(382));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
final diffFile = FileChange(
|
||||
path: 'lib/feature.dart',
|
||||
kind: ChangeKind.modified,
|
||||
patch: multiHunkPatch,
|
||||
);
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
|
||||
testWidgets('$host diff labels stay whole at 320x720 with 2x text', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(320, 720);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final opener = _diffDialogOpener(diffFile);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? cupertinoHost(opener, scaler: const TextScaler.linear(2))
|
||||
: materialHost(opener, scaler: const TextScaler.linear(2)),
|
||||
);
|
||||
await tester.tap(find.text('Open diff'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// A segmented control cannot keep both fixed words at this size, so the
|
||||
// host's native menu carries them instead. "Rendered" used to break
|
||||
// mid-word and "Raw patch" used to be clipped to "Raw".
|
||||
expect(find.byType(SegmentedButton<DiffForm>), findsNothing);
|
||||
expect(
|
||||
find.byType(CupertinoSlidingSegmentedControl<DiffForm>),
|
||||
findsNothing,
|
||||
);
|
||||
|
||||
// Copy patch stays a standard action at intrinsic width; it must not
|
||||
// break its two words either.
|
||||
_expectWholeLabel(tester, find.text('Copy patch'), 'Copy patch');
|
||||
|
||||
await tester.tap(
|
||||
cupertino
|
||||
? find.byIcon(CupertinoIcons.ellipsis)
|
||||
: find.byTooltip('Diff form'),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final items = cupertino
|
||||
? find.byType(CupertinoActionSheetAction)
|
||||
: find.byType(ListTile);
|
||||
expect(items, findsNWidgets(2));
|
||||
for (final label in ['Rendered', 'Raw patch']) {
|
||||
_expectWholeLabel(
|
||||
tester,
|
||||
find.descendant(of: items, matching: find.text(label)),
|
||||
label,
|
||||
);
|
||||
}
|
||||
|
||||
await tester.tap(
|
||||
find.descendant(of: items, matching: find.text('Raw patch')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
if (cupertino) {
|
||||
expect(find.byKey(const ValueKey('raw-patch-field')), findsOneWidget);
|
||||
} else {
|
||||
expect(find.text(multiHunkPatch), findsOneWidget);
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'${cupertino ? 'Cupertino' : 'Material'} wide host keeps the native '
|
||||
'segmented control',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? cupertinoHost(_diffDialogOpener(diffFile))
|
||||
: materialHost(_diffDialogOpener(diffFile)),
|
||||
);
|
||||
await tester.tap(find.text('Open diff'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
cupertino
|
||||
? find.byType(CupertinoSlidingSegmentedControl<DiffForm>)
|
||||
: find.byType(SegmentedButton<DiffForm>),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Rendered'), findsOneWidget);
|
||||
expect(find.text('Raw patch'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user