Merge branch 'main' into pipelines/run-20261111-0323-cupertino-out-shell-eacf
# Conflicts: # app/test/application/search_artifact_open_test.dart # app/test/application/search_chat_open_test.dart
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
@@ -23,21 +22,18 @@ import '../../features/artifacts/ui/artifact_visit_list_fixture.dart';
|
||||
import '../../features/chat/conversation/chat_composer_bar_fixtures.dart';
|
||||
|
||||
/// Every glass control bar keeps its first and last controls as far from the
|
||||
/// pill's sides as from its top and bottom, and spaces neighbours evenly, on
|
||||
/// both hosts, at phone width and at a larger text size.
|
||||
/// pill's sides as from its top and bottom, and spaces neighbours evenly, at
|
||||
/// phone width and at a larger text size.
|
||||
|
||||
const _phone = Size(390, 844);
|
||||
const _scales = [1.0, 1.3];
|
||||
const _hosts = [false, true];
|
||||
|
||||
final Uint8List _png = base64Decode(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAE'
|
||||
'hQGAhKmMIQAAAABJRU5ErkJggg==',
|
||||
);
|
||||
|
||||
Widget _host(bool cupertino, Widget child) => cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: child))
|
||||
: MaterialApp(home: Scaffold(body: child));
|
||||
Widget _host(Widget child) => MaterialApp(home: Scaffold(body: child));
|
||||
|
||||
Future<void> _setUp(WidgetTester tester, double scale) async {
|
||||
tester.view.physicalSize = _phone * tester.view.devicePixelRatio;
|
||||
@@ -50,9 +46,7 @@ Future<void> _setUp(WidgetTester tester, double scale) async {
|
||||
List<Rect> _controls(WidgetTester tester, Finder pill) {
|
||||
final found = find.descendant(
|
||||
of: pill,
|
||||
matching: find.byWidgetPredicate(
|
||||
(widget) => widget is IconButton || widget is CupertinoButton,
|
||||
),
|
||||
matching: find.byWidgetPredicate((widget) => widget is IconButton),
|
||||
);
|
||||
final rects = [
|
||||
for (var i = 0; i < found.evaluate().length; i++)
|
||||
@@ -101,248 +95,210 @@ Rect _pillOf(WidgetTester tester, Finder inside) => tester.getRect(
|
||||
);
|
||||
|
||||
void main() {
|
||||
for (final cupertino in _hosts) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
for (final scale in _scales) {
|
||||
final when = '$host, text x$scale';
|
||||
for (final scale in _scales) {
|
||||
final when = 'text x$scale';
|
||||
|
||||
testWidgets('artifact viewer bar: equal end gaps ($when)', (
|
||||
tester,
|
||||
) async {
|
||||
await _setUp(tester, scale);
|
||||
for (final count in [1, 3]) {
|
||||
final artifacts = [
|
||||
for (var i = 0; i < count; i++)
|
||||
recordedArtifact(
|
||||
'shot-$i.png',
|
||||
url: '/artifacts/1/1/shot-$i.png',
|
||||
contentType: 'image/png',
|
||||
),
|
||||
];
|
||||
final group = ArtifactGroup(
|
||||
stageKey: 'review',
|
||||
visit: 1,
|
||||
artifacts: artifacts,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino,
|
||||
ArtifactViewerPage(
|
||||
key: ValueKey(count),
|
||||
groups: [group],
|
||||
selectedIdentity: artifactVisitIdentity(group, artifacts.first),
|
||||
configuredEndpoint: 'ws://127.0.0.1:8081/connect',
|
||||
fetch: (_) async =>
|
||||
ArtifactFetchResult(status: 200, bytes: _png),
|
||||
markdownBuilder: (context, value) => Text(value),
|
||||
openExternal: (_) async => true,
|
||||
),
|
||||
testWidgets('artifact viewer bar: equal end gaps ($when)', (tester) async {
|
||||
await _setUp(tester, scale);
|
||||
for (final count in [1, 3]) {
|
||||
final artifacts = [
|
||||
for (var i = 0; i < count; i++)
|
||||
recordedArtifact(
|
||||
'shot-$i.png',
|
||||
url: '/artifacts/1/1/shot-$i.png',
|
||||
contentType: 'image/png',
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final row = find.byKey(const Key('artifact-viewer-actions'));
|
||||
final pill = _pillOf(tester, row);
|
||||
final controls = _controls(tester, row);
|
||||
expect(controls.length, greaterThanOrEqualTo(2));
|
||||
_expectEqualEnds(pill, controls.first, controls.last);
|
||||
_expectEvenNeighbours(
|
||||
count > 1 ? controls.sublist(0, controls.length - 2) : controls,
|
||||
);
|
||||
if (count > 1) {
|
||||
_expectEvenNeighbours(controls.sublist(controls.length - 2));
|
||||
}
|
||||
expect(pill.height, closeTo(GlassBarMetrics.height(cupertino), 1));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('diff page pager: position and chevrons inset ($when)', (
|
||||
tester,
|
||||
) async {
|
||||
await _setUp(tester, scale);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino,
|
||||
FileDiffPage(
|
||||
files: [
|
||||
for (final name in ['a', 'b', 'c'])
|
||||
FileChange(
|
||||
path: 'lib/$name.dart',
|
||||
kind: ChangeKind.modified,
|
||||
patch:
|
||||
'--- a/lib/$name.dart\n+++ b/lib/$name.dart\n'
|
||||
'@@ -1 +1 @@\n-x\n+y\n',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final pager = find.byKey(const ValueKey('file-diff-pager'));
|
||||
_expectPager(tester, pager, cupertino, find.text('1 of 3'));
|
||||
});
|
||||
|
||||
testWidgets('changes visit pager: equal end gaps ($when)', (
|
||||
tester,
|
||||
) async {
|
||||
await _setUp(tester, scale);
|
||||
Map<String, dynamic> visit(String stage, int sequence) => {
|
||||
'stage': stage,
|
||||
'sequence': sequence,
|
||||
'status': 'completed',
|
||||
'file_changes': {
|
||||
'status': 'complete',
|
||||
'scope': 'Git tracked files',
|
||||
'skipped': 0,
|
||||
'omitted': 0,
|
||||
'diagnostic': '',
|
||||
'files': [
|
||||
{'path': 'lib/$stage.dart', 'kind': 'added'},
|
||||
],
|
||||
},
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino,
|
||||
ChangesViewer(
|
||||
steps: [visit('build', 1), visit('review', 2)],
|
||||
showSummary: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final position = find.byKey(
|
||||
const ValueKey<String>('changes-visit-position'),
|
||||
);
|
||||
_expectPager(
|
||||
tester,
|
||||
find.ancestor(of: position, matching: find.byType(Row)).first,
|
||||
cupertino,
|
||||
position,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('chat composer: + and Send keep the pill gap ($when)', (
|
||||
tester,
|
||||
) async {
|
||||
await _setUp(tester, scale);
|
||||
final gateway = ComposerBarGateway();
|
||||
addTearDown(gateway.close);
|
||||
final composer = ChatComposerController(
|
||||
gateway,
|
||||
's',
|
||||
drafts: MemoryChatDraftStore(),
|
||||
);
|
||||
addTearDown(composer.dispose);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino,
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: ChatComposerBar(
|
||||
composer: composer,
|
||||
running: false,
|
||||
placeholder: 'Message',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final pill = tester.getRect(
|
||||
find.byKey(const Key('chat-composer-pill')),
|
||||
);
|
||||
final attach = tester.getRect(
|
||||
find.byKey(const Key('chat-composer-attach')),
|
||||
);
|
||||
final send = tester.getRect(
|
||||
find.byKey(const Key('chat-composer-primary')),
|
||||
);
|
||||
// The controls keep to the field's last line: each end control is as
|
||||
// far from the pill's side as from its bottom, and while the field is
|
||||
// one line (no taller than a control) as far from its top.
|
||||
final row = GlassBarMetrics.controlExtent(cupertino);
|
||||
final oneLine =
|
||||
pill.height <= row + 2 * GlassBarMetrics.fieldEdgeGap + 0.5;
|
||||
for (final (control, start) in [(attach, true), (send, false)]) {
|
||||
final bottom = pill.bottom - control.bottom;
|
||||
final side = start
|
||||
? control.left - pill.left
|
||||
: pill.right - control.right;
|
||||
expect(side, closeTo(bottom, 1), reason: 'side vs bottom');
|
||||
if (oneLine) {
|
||||
expect(control.top - pill.top, closeTo(bottom, 1), reason: 'top');
|
||||
expect(bottom, closeTo((pill.height - control.height) / 2, 1));
|
||||
}
|
||||
}
|
||||
if (scale == 1.0) expect(oneLine, isTrue, reason: 'pill $pill');
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('top bar actions pill: controls fill it evenly ($when)', (
|
||||
tester,
|
||||
) async {
|
||||
await _setUp(tester, scale);
|
||||
final actions = [
|
||||
for (final name in ['a', 'b', 'c'])
|
||||
cupertino
|
||||
? CupertinoButton(
|
||||
key: Key('action-$name'),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: () {},
|
||||
child: const Icon(CupertinoIcons.info),
|
||||
)
|
||||
: IconButton(
|
||||
key: Key('action-$name'),
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.info_outline),
|
||||
),
|
||||
];
|
||||
final group = ArtifactGroup(
|
||||
stageKey: 'review',
|
||||
visit: 1,
|
||||
artifacts: artifacts,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
navigationBar: SegmentedBar(
|
||||
cupertino: true,
|
||||
title: 'Title',
|
||||
actions: actions,
|
||||
),
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
)
|
||||
: MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: SegmentedBar(
|
||||
cupertino: false,
|
||||
title: 'Title',
|
||||
actions: actions,
|
||||
),
|
||||
),
|
||||
),
|
||||
_host(
|
||||
ArtifactViewerPage(
|
||||
key: ValueKey(count),
|
||||
groups: [group],
|
||||
selectedIdentity: artifactVisitIdentity(group, artifacts.first),
|
||||
configuredEndpoint: 'ws://127.0.0.1:8081/connect',
|
||||
fetch: (_) async => ArtifactFetchResult(status: 200, bytes: _png),
|
||||
markdownBuilder: (context, value) => Text(value),
|
||||
openExternal: (_) async => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final first = find.byKey(const Key('action-a'));
|
||||
final pill = _pillOf(tester, first);
|
||||
final controls = [
|
||||
for (final name in ['a', 'b', 'c'])
|
||||
tester.getRect(find.byKey(Key('action-$name'))),
|
||||
];
|
||||
final row = find.byKey(const Key('artifact-viewer-actions'));
|
||||
final pill = _pillOf(tester, row);
|
||||
final controls = _controls(tester, row);
|
||||
expect(controls.length, greaterThanOrEqualTo(2));
|
||||
_expectEqualEnds(pill, controls.first, controls.last);
|
||||
_expectEvenNeighbours(controls);
|
||||
_expectEvenNeighbours(
|
||||
count > 1 ? controls.sublist(0, controls.length - 2) : controls,
|
||||
);
|
||||
if (count > 1) {
|
||||
_expectEvenNeighbours(controls.sublist(controls.length - 2));
|
||||
}
|
||||
expect(pill.height, closeTo(GlassBarMetrics.height(false), 1));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('diff page pager: position and chevrons inset ($when)', (
|
||||
tester,
|
||||
) async {
|
||||
await _setUp(tester, scale);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
FileDiffPage(
|
||||
files: [
|
||||
for (final name in ['a', 'b', 'c'])
|
||||
FileChange(
|
||||
path: 'lib/$name.dart',
|
||||
kind: ChangeKind.modified,
|
||||
patch:
|
||||
'--- a/lib/$name.dart\n+++ b/lib/$name.dart\n'
|
||||
'@@ -1 +1 @@\n-x\n+y\n',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final pager = find.byKey(const ValueKey('file-diff-pager'));
|
||||
_expectPager(tester, pager, find.text('1 of 3'));
|
||||
});
|
||||
|
||||
testWidgets('changes visit pager: equal end gaps ($when)', (tester) async {
|
||||
await _setUp(tester, scale);
|
||||
Map<String, dynamic> visit(String stage, int sequence) => {
|
||||
'stage': stage,
|
||||
'sequence': sequence,
|
||||
'status': 'completed',
|
||||
'file_changes': {
|
||||
'status': 'complete',
|
||||
'scope': 'Git tracked files',
|
||||
'skipped': 0,
|
||||
'omitted': 0,
|
||||
'diagnostic': '',
|
||||
'files': [
|
||||
{'path': 'lib/$stage.dart', 'kind': 'added'},
|
||||
],
|
||||
},
|
||||
};
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ChangesViewer(
|
||||
steps: [visit('build', 1), visit('review', 2)],
|
||||
showSummary: false,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final position = find.byKey(
|
||||
const ValueKey<String>('changes-visit-position'),
|
||||
);
|
||||
_expectPager(
|
||||
tester,
|
||||
find.ancestor(of: position, matching: find.byType(Row)).first,
|
||||
position,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('chat composer: + and Send keep the pill gap ($when)', (
|
||||
tester,
|
||||
) async {
|
||||
await _setUp(tester, scale);
|
||||
final gateway = ComposerBarGateway();
|
||||
addTearDown(gateway.close);
|
||||
final composer = ChatComposerController(
|
||||
gateway,
|
||||
's',
|
||||
drafts: MemoryChatDraftStore(),
|
||||
);
|
||||
addTearDown(composer.dispose);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: ChatComposerBar(
|
||||
composer: composer,
|
||||
running: false,
|
||||
placeholder: 'Message',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final pill = tester.getRect(find.byKey(const Key('chat-composer-pill')));
|
||||
final attach = tester.getRect(
|
||||
find.byKey(const Key('chat-composer-attach')),
|
||||
);
|
||||
final send = tester.getRect(
|
||||
find.byKey(const Key('chat-composer-primary')),
|
||||
);
|
||||
// The controls keep to the field's last line: each end control is as
|
||||
// far from the pill's side as from its bottom, and while the field is
|
||||
// one line (no taller than a control) as far from its top.
|
||||
final row = GlassBarMetrics.controlExtent(false);
|
||||
final oneLine =
|
||||
pill.height <= row + 2 * GlassBarMetrics.fieldEdgeGap + 0.5;
|
||||
for (final (control, start) in [(attach, true), (send, false)]) {
|
||||
final bottom = pill.bottom - control.bottom;
|
||||
final side = start
|
||||
? control.left - pill.left
|
||||
: pill.right - control.right;
|
||||
expect(side, closeTo(bottom, 1), reason: 'side vs bottom');
|
||||
if (oneLine) {
|
||||
expect(control.top - pill.top, closeTo(bottom, 1), reason: 'top');
|
||||
expect(bottom, closeTo((pill.height - control.height) / 2, 1));
|
||||
}
|
||||
}
|
||||
if (scale == 1.0) expect(oneLine, isTrue, reason: 'pill $pill');
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('top bar actions pill: controls fill it evenly ($when)', (
|
||||
tester,
|
||||
) async {
|
||||
await _setUp(tester, scale);
|
||||
final actions = [
|
||||
for (final name in ['a', 'b', 'c'])
|
||||
IconButton(
|
||||
key: Key('action-$name'),
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.info_outline),
|
||||
),
|
||||
];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: SegmentedBar(
|
||||
cupertino: false,
|
||||
title: 'Title',
|
||||
actions: actions,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final first = find.byKey(const Key('action-a'));
|
||||
final pill = _pillOf(tester, first);
|
||||
final controls = [
|
||||
for (final name in ['a', 'b', 'c'])
|
||||
tester.getRect(find.byKey(Key('action-$name'))),
|
||||
];
|
||||
_expectEqualEnds(pill, controls.first, controls.last);
|
||||
_expectEvenNeighbours(controls);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// A pager row: its position text starts an icon's inset in from the pill's
|
||||
/// edge (where an icon at that end would be drawn), and its chevrons keep the
|
||||
/// rule's equal gaps at the other end.
|
||||
void _expectPager(
|
||||
WidgetTester tester,
|
||||
Finder inside,
|
||||
bool cupertino,
|
||||
Finder position,
|
||||
) {
|
||||
void _expectPager(WidgetTester tester, Finder inside, Finder position) {
|
||||
final pill = _pillOf(tester, inside);
|
||||
final controls = _controls(tester, inside);
|
||||
expect(controls, hasLength(2));
|
||||
@@ -353,14 +309,14 @@ void _expectPager(
|
||||
final gap = (pill.height - last.height) / 2;
|
||||
expect(
|
||||
text.left - pill.left,
|
||||
closeTo(gap + GlassBarMetrics.iconInset(cupertino), 1),
|
||||
closeTo(gap + GlassBarMetrics.iconInset(false), 1),
|
||||
);
|
||||
// The chevrons keep the same gap from the position as from each other's
|
||||
// icons: one icon inset on each side.
|
||||
expect(
|
||||
controls.first.left - text.right,
|
||||
greaterThanOrEqualTo(GlassBarMetrics.iconInset(cupertino) - 1),
|
||||
greaterThanOrEqualTo(GlassBarMetrics.iconInset(false) - 1),
|
||||
);
|
||||
expect(pill.height, closeTo(GlassBarMetrics.height(cupertino), 1));
|
||||
expect(pill.height, closeTo(GlassBarMetrics.height(false), 1));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import 'dart:ui' show Tristate;
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/input/cupertino_web_search_field.dart';
|
||||
|
||||
void main() {
|
||||
for (final provided in [false, true]) {
|
||||
testWidgets(
|
||||
'native clear preserves semantics and focus (provided node: $provided)',
|
||||
(tester) async {
|
||||
final semantics = tester.ensureSemantics();
|
||||
|
||||
try {
|
||||
final text = TextEditingController();
|
||||
final focus = FocusNode();
|
||||
addTearDown(text.dispose);
|
||||
addTearDown(focus.dispose);
|
||||
var clears = 0;
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
child: Center(
|
||||
child: CupertinoWebSearchField(
|
||||
controller: text,
|
||||
placeholder: 'Search',
|
||||
focusNode: provided ? focus : null,
|
||||
onCleared: () {
|
||||
clears++;
|
||||
text.clear();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final field = find.byType(EditableText);
|
||||
final effective = tester.widget<EditableText>(field).focusNode;
|
||||
effective.requestFocus();
|
||||
await tester.pumpAndSettle();
|
||||
final height = tester
|
||||
.getSize(find.byType(CupertinoWebSearchField))
|
||||
.height;
|
||||
final before = tester.getSemantics(field);
|
||||
final identity = before.id;
|
||||
expect(
|
||||
before.getSemanticsData().flagsCollection.isEnabled,
|
||||
Tristate.isTrue,
|
||||
);
|
||||
await tester.enterText(
|
||||
find.byType(CupertinoSearchTextField),
|
||||
'release',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final after = tester.getSemantics(field);
|
||||
expect(after.id, identity);
|
||||
expect(
|
||||
tester.getSize(find.byType(CupertinoWebSearchField)).height,
|
||||
height,
|
||||
);
|
||||
expect(
|
||||
after.getSemanticsData().flagsCollection.isEnabled,
|
||||
Tristate.isTrue,
|
||||
);
|
||||
expect(effective.hasPrimaryFocus, isTrue);
|
||||
await tester.tap(find.byType(CupertinoButton));
|
||||
await tester.pumpAndSettle();
|
||||
expect(text.text, isEmpty);
|
||||
expect(clears, 1);
|
||||
expect(
|
||||
tester.getSize(find.byType(CupertinoWebSearchField)).height,
|
||||
height,
|
||||
);
|
||||
expect(effective.hasPrimaryFocus, isTrue);
|
||||
expect(tester.getSemantics(field).id, identity);
|
||||
await tester.enterText(
|
||||
find.byType(CupertinoSearchTextField),
|
||||
'again',
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(text.text, 'again');
|
||||
expect(effective.hasPrimaryFocus, isTrue);
|
||||
} finally {
|
||||
semantics.dispose();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
@@ -11,10 +10,9 @@ const _rowColor = Color(0xFFE3F2FD);
|
||||
|
||||
/// A list of three rows; tapping one pushes its page, grown from that row.
|
||||
class _List extends StatelessWidget {
|
||||
const _List({required this.sources, required this.cupertino});
|
||||
const _List({required this.sources});
|
||||
|
||||
final ContainerTransformSources sources;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ContainerTransformScope(
|
||||
@@ -33,8 +31,8 @@ class _List extends StatelessWidget {
|
||||
onTap: () => Navigator.of(context).push(
|
||||
ContainerTransformPageRoute<void>(
|
||||
link: sources.link(() => id),
|
||||
cupertino: cupertino,
|
||||
builder: (_) => _Page(id: id, cupertino: cupertino),
|
||||
cupertino: false,
|
||||
builder: (_) => _Page(id: id),
|
||||
),
|
||||
),
|
||||
child: SizedBox(height: 72, child: Text('row $id')),
|
||||
@@ -46,42 +44,31 @@ class _List extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _Page extends StatelessWidget {
|
||||
const _Page({required this.id, required this.cupertino});
|
||||
const _Page({required this.id});
|
||||
|
||||
final String id;
|
||||
final bool cupertino;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => cupertino
|
||||
? CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(),
|
||||
child: Center(child: Text('page $id')),
|
||||
)
|
||||
: Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(child: Text('page $id')),
|
||||
);
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(child: Text('page $id')),
|
||||
);
|
||||
}
|
||||
|
||||
Future<ContainerTransformSources> _pump(
|
||||
WidgetTester tester, {
|
||||
bool cupertino = false,
|
||||
bool reduced = false,
|
||||
}) async {
|
||||
tester.view.physicalSize = _screen;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final sources = ContainerTransformSources();
|
||||
final home = _List(sources: sources, cupertino: cupertino);
|
||||
final home = _List(sources: sources);
|
||||
Widget media(BuildContext context, Widget? child) => MediaQuery(
|
||||
data: MediaQuery.of(context).copyWith(disableAnimations: reduced),
|
||||
child: child!,
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(builder: media, home: home)
|
||||
: MaterialApp(builder: media, home: home),
|
||||
);
|
||||
await tester.pumpWidget(MaterialApp(builder: media, home: home));
|
||||
return sources;
|
||||
}
|
||||
|
||||
@@ -186,7 +173,7 @@ void main() {
|
||||
ContainerTransformPageRoute<void>(
|
||||
link: sources.link(() => 'missing'),
|
||||
cupertino: false,
|
||||
builder: (_) => const _Page(id: 'x', cupertino: false),
|
||||
builder: (_) => const _Page(id: 'x'),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
@@ -196,54 +183,6 @@ void main() {
|
||||
expect(find.text('page x'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a Cupertino swipe back shrinks the page with the finger', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, cupertino: true);
|
||||
final row = tester.getRect(find.byKey(const Key('row-b')));
|
||||
await tester.tap(find.byKey(const Key('row-b')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_surface(tester), Offset.zero & _screen);
|
||||
|
||||
final gesture = await tester.startGesture(const Offset(5, 400));
|
||||
await gesture.moveBy(const Offset(20, 0));
|
||||
await gesture.moveBy(const Offset(100, 0));
|
||||
await tester.pump();
|
||||
final early = _surface(tester);
|
||||
_expectBetween(early, row);
|
||||
await gesture.moveBy(const Offset(100, 0));
|
||||
await tester.pump();
|
||||
final later = _surface(tester);
|
||||
expect(later.height, lessThan(early.height), reason: 'follows the finger');
|
||||
|
||||
// Back toward the start edge, the page grows again.
|
||||
await gesture.moveBy(const Offset(-150, 0));
|
||||
await tester.pump();
|
||||
expect(_surface(tester).height, greaterThan(later.height));
|
||||
|
||||
await gesture.moveBy(const Offset(200, 0));
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('page b'), findsNothing);
|
||||
expect(find.byKey(const Key('row-b')), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a short Cupertino swipe released early stays on the page', (
|
||||
tester,
|
||||
) async {
|
||||
await _pump(tester, cupertino: true);
|
||||
await tester.tap(find.byKey(const Key('row-b')));
|
||||
await tester.pumpAndSettle();
|
||||
final gesture = await tester.startGesture(const Offset(5, 400));
|
||||
await gesture.moveBy(const Offset(20, 0));
|
||||
await gesture.moveBy(const Offset(40, 0));
|
||||
await tester.pump();
|
||||
await gesture.up();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('page b'), findsOneWidget);
|
||||
expect(_surface(tester), Offset.zero & _screen);
|
||||
});
|
||||
|
||||
testWidgets('Android predictive back drives the shrink, then commits', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -4,13 +4,11 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/input/app_search_field.dart';
|
||||
import 'package:pipelines_app/ui/navigation/bar_icon_button.dart';
|
||||
|
||||
Widget _row(bool cupertino, List<Widget> children) {
|
||||
Widget _row(List<Widget> children) {
|
||||
final row = Center(
|
||||
child: Row(mainAxisSize: MainAxisSize.min, children: children),
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(home: CupertinoPageScaffold(child: row))
|
||||
: MaterialApp(home: Scaffold(body: row));
|
||||
return MaterialApp(home: Scaffold(body: row));
|
||||
}
|
||||
|
||||
BarIconButton _action(Key key, {bool busy = false}) => BarIconButton(
|
||||
@@ -23,73 +21,58 @@ BarIconButton _action(Key key, {bool busy = false}) => BarIconButton(
|
||||
);
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
final side = cupertino
|
||||
? kMinInteractiveDimensionCupertino
|
||||
: kMinInteractiveDimension;
|
||||
const side = kMinInteractiveDimension;
|
||||
|
||||
testWidgets('$host bar actions are whole, evenly sized touch targets', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
_row(cupertino, [
|
||||
_action(const ValueKey('a')),
|
||||
_action(const ValueKey('b')),
|
||||
_action(const ValueKey('c'), busy: true),
|
||||
]),
|
||||
);
|
||||
for (final key in const ['a', 'b', 'c']) {
|
||||
expect(tester.getSize(find.byKey(ValueKey(key))), Size(side, side));
|
||||
}
|
||||
// Adjacent actions abut: the spacing is the targets', not padding.
|
||||
expect(
|
||||
tester.getTopLeft(find.byKey(const ValueKey('b'))).dx -
|
||||
tester.getTopLeft(find.byKey(const ValueKey('a'))).dx,
|
||||
side,
|
||||
);
|
||||
if (cupertino) expect(find.byType(Material), findsNothing);
|
||||
expect(find.bySemanticsLabel('Refresh'), findsWidgets);
|
||||
});
|
||||
testWidgets('bar actions are whole, evenly sized touch targets', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
_row([
|
||||
_action(const ValueKey('a')),
|
||||
_action(const ValueKey('b')),
|
||||
_action(const ValueKey('c'), busy: true),
|
||||
]),
|
||||
);
|
||||
for (final key in const ['a', 'b', 'c']) {
|
||||
expect(tester.getSize(find.byKey(ValueKey(key))), Size(side, side));
|
||||
}
|
||||
// Adjacent actions abut: the spacing is the targets', not padding.
|
||||
expect(
|
||||
tester.getTopLeft(find.byKey(const ValueKey('b'))).dx -
|
||||
tester.getTopLeft(find.byKey(const ValueKey('a'))).dx,
|
||||
side,
|
||||
);
|
||||
expect(find.bySemanticsLabel('Refresh'), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('$host search field is one stadium field with a clear', (
|
||||
tester,
|
||||
) async {
|
||||
final text = TextEditingController();
|
||||
addTearDown(text.dispose);
|
||||
var cleared = false;
|
||||
await tester.pumpWidget(
|
||||
_row(cupertino, [
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: AppSearchField(
|
||||
fieldKey: const ValueKey('field'),
|
||||
controller: text,
|
||||
placeholder: 'Search',
|
||||
onCleared: () => cleared = true,
|
||||
),
|
||||
testWidgets('search field is one stadium field with a clear', (tester) async {
|
||||
final text = TextEditingController();
|
||||
addTearDown(text.dispose);
|
||||
var cleared = false;
|
||||
await tester.pumpWidget(
|
||||
_row([
|
||||
SizedBox(
|
||||
width: 300,
|
||||
child: AppSearchField(
|
||||
fieldKey: const ValueKey('field'),
|
||||
controller: text,
|
||||
placeholder: 'Search',
|
||||
onCleared: () => cleared = true,
|
||||
),
|
||||
]),
|
||||
);
|
||||
if (cupertino) {
|
||||
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
|
||||
expect(find.byType(Material), findsNothing);
|
||||
return;
|
||||
}
|
||||
final field = tester.widget<TextField>(
|
||||
find.byKey(const ValueKey('field')),
|
||||
);
|
||||
final border = field.decoration!.enabledBorder! as OutlineInputBorder;
|
||||
expect(border.borderSide, BorderSide.none);
|
||||
expect(field.decoration!.filled, isTrue);
|
||||
expect(find.byTooltip('Clear search'), findsNothing);
|
||||
),
|
||||
]),
|
||||
);
|
||||
final field = tester.widget<TextField>(find.byKey(const ValueKey('field')));
|
||||
final border = field.decoration!.enabledBorder! as OutlineInputBorder;
|
||||
expect(border.borderSide, BorderSide.none);
|
||||
expect(field.decoration!.filled, isTrue);
|
||||
expect(find.byTooltip('Clear search'), findsNothing);
|
||||
|
||||
await tester.enterText(find.byKey(const ValueKey('field')), 'abc');
|
||||
await tester.pump();
|
||||
await tester.tap(find.byTooltip('Clear search'));
|
||||
await tester.pump();
|
||||
expect(text.text, isEmpty);
|
||||
expect(cleared, isTrue);
|
||||
});
|
||||
}
|
||||
await tester.enterText(find.byKey(const ValueKey('field')), 'abc');
|
||||
await tester.pump();
|
||||
await tester.tap(find.byTooltip('Clear search'));
|
||||
await tester.pump();
|
||||
expect(text.text, isEmpty);
|
||||
expect(cleared, isTrue);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app.dart';
|
||||
@@ -27,69 +26,38 @@ void main() {
|
||||
expect(b?.fontSize, a?.fontSize);
|
||||
expect(b?.fontWeight, a?.fontWeight);
|
||||
}
|
||||
expect(
|
||||
build(
|
||||
fontFamily: 'Inter',
|
||||
).cupertinoOverrideTheme?.textTheme?.textStyle.fontFamily,
|
||||
'Inter',
|
||||
);
|
||||
expect(build().cupertinoOverrideTheme, isNull);
|
||||
}
|
||||
});
|
||||
|
||||
test('the Cupertino theme takes the family in every text role', () {
|
||||
expect(appCupertinoThemeWith(), same(appCupertinoTheme));
|
||||
final text = appCupertinoThemeWith(fontFamily: 'Inter').textTheme;
|
||||
const stock = CupertinoTextThemeData();
|
||||
for (final (a, b) in <(TextStyle, TextStyle)>[
|
||||
(stock.textStyle, text.textStyle),
|
||||
(stock.navTitleTextStyle, text.navTitleTextStyle),
|
||||
(stock.navLargeTitleTextStyle, text.navLargeTitleTextStyle),
|
||||
(stock.tabLabelTextStyle, text.tabLabelTextStyle),
|
||||
(stock.actionTextStyle, text.actionTextStyle),
|
||||
(stock.pickerTextStyle, text.pickerTextStyle),
|
||||
]) {
|
||||
expect(b.fontFamily, 'Inter');
|
||||
expect(b.fontSize, a.fontSize);
|
||||
expect(b.fontWeight, a.fontWeight);
|
||||
}
|
||||
expect(
|
||||
appCupertinoThemeWith(fontFamily: 'Inter').scaffoldBackgroundColor,
|
||||
AppColors.background,
|
||||
testWidgets('the Material host switches font live, without a restart', (
|
||||
tester,
|
||||
) async {
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(),
|
||||
loader: (family, assets) async {},
|
||||
);
|
||||
String? family;
|
||||
await tester.pumpWidget(
|
||||
MyApp(
|
||||
fonts: fonts,
|
||||
destination: AppDestination.settings,
|
||||
destinationBodies: <AppDestination, WidgetBuilder>{
|
||||
AppDestination.settings: (context) => Builder(
|
||||
builder: (context) {
|
||||
family = DefaultTextStyle.of(context).style.fontFamily;
|
||||
return const Text('body');
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
final before = family;
|
||||
expect(before, isNot('IBM Plex Sans'));
|
||||
await fonts.select(AppFont.ibmPlexSans);
|
||||
await tester.pumpAndSettle();
|
||||
expect(family, 'IBM Plex Sans');
|
||||
await fonts.select(AppFont.system);
|
||||
await tester.pumpAndSettle();
|
||||
expect(family, before);
|
||||
});
|
||||
|
||||
for (final cupertino in <bool>[false, true]) {
|
||||
testWidgets('the ${cupertino ? 'Cupertino' : 'Material'} host switches '
|
||||
'font live, without a restart', (tester) async {
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(),
|
||||
loader: (family, assets) async {},
|
||||
);
|
||||
String? family;
|
||||
await tester.pumpWidget(
|
||||
MyApp(
|
||||
cupertino: cupertino,
|
||||
fonts: fonts,
|
||||
destination: AppDestination.settings,
|
||||
destinationBodies: <AppDestination, WidgetBuilder>{
|
||||
AppDestination.settings: (context) => Builder(
|
||||
builder: (context) {
|
||||
family = DefaultTextStyle.of(context).style.fontFamily;
|
||||
return const Text('body');
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
final before = family;
|
||||
expect(before, isNot('IBM Plex Sans'));
|
||||
await fonts.select(AppFont.ibmPlexSans);
|
||||
await tester.pumpAndSettle();
|
||||
expect(family, 'IBM Plex Sans');
|
||||
await fonts.select(AppFont.system);
|
||||
await tester.pumpAndSettle();
|
||||
expect(family, before);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
@@ -20,11 +19,13 @@ void main() {
|
||||
}
|
||||
});
|
||||
|
||||
test('the Cupertino page is gray in dark mode and unchanged in light', () {
|
||||
test('page backgrounds are gray in dark mode and unchanged in light', () {
|
||||
expect(AppColors.background.darkColor, const Color(0xFF141416));
|
||||
expect(AppColors.background.color, const Color(0xFFFFFFFF));
|
||||
expect(appCupertinoTheme.scaffoldBackgroundColor, AppColors.background);
|
||||
expect(AppColors.groupedBackground.darkColor, isNot(CupertinoColors.black));
|
||||
expect(
|
||||
AppColors.groupedBackground.darkColor,
|
||||
isNot(const Color(0xFF000000)),
|
||||
);
|
||||
});
|
||||
|
||||
test('Android pages retain native predictive Back in both themes', () {
|
||||
|
||||
Reference in New Issue
Block a user