Merge: narrow list panes keep a readable title and row status
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:pipelines_app/features/settings/settings_screen.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../bar_action.dart';
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../features/pipelines/fixtures.dart';
|
||||
import 'pipelines_app_test.dart' show webServer;
|
||||
@@ -77,7 +78,11 @@ void main() {
|
||||
);
|
||||
expect(find.byKey(const ValueKey('shell.back')), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipelines-open-settings')));
|
||||
await tapBarAction(
|
||||
tester,
|
||||
find.byKey(const Key('pipelines-open-settings')),
|
||||
'Settings',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/settings');
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:pipelines_app/application/pipelines_app.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../bar_action.dart';
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../features/pipelines/fixtures.dart';
|
||||
import 'pipelines_app_test.dart' show webServer, requestOf;
|
||||
@@ -51,7 +52,11 @@ void main() {
|
||||
);
|
||||
await replyPipelines(tester, channel, PipelineFixture());
|
||||
|
||||
await tester.tap(find.byKey(const Key('pipelines-open-settings')));
|
||||
await tapBarAction(
|
||||
tester,
|
||||
find.byKey(const Key('pipelines-open-settings')),
|
||||
'Settings',
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(provider.value.uri.path, '/settings');
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/adaptive/segmented_bar.dart';
|
||||
|
||||
/// Taps a top-bar action: in the bar while it fits, or through the bar's
|
||||
/// More menu (by its [label]) when a narrow bar moved it there.
|
||||
Future<void> tapBarAction(
|
||||
WidgetTester tester,
|
||||
Finder action,
|
||||
String label,
|
||||
) async {
|
||||
if (action.hitTestable().evaluate().isNotEmpty) {
|
||||
await tester.tap(action);
|
||||
return;
|
||||
}
|
||||
await tester.tap(find.byKey(segmentedMoreKey).hitTestable());
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(label).last);
|
||||
}
|
||||
@@ -4,6 +4,8 @@ import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/domain/run_models.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/run_more_menu.dart';
|
||||
import 'package:pipelines_app/features/runs/ui/runs_list.dart';
|
||||
import 'package:pipelines_app/ui/status/run_status_icon.dart';
|
||||
import 'package:pipelines_app/ui/text/relative_time_label.dart';
|
||||
|
||||
final _finished = {
|
||||
'id': 42,
|
||||
@@ -108,29 +110,39 @@ void main() {
|
||||
expect(find.byKey(runMoreMenuKey), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('compact rows keep a title and one metadata line', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(240, 400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunListRow(
|
||||
run: _finished,
|
||||
now: DateTime.utc(2026, 10, 22),
|
||||
gateway: _FakeGateway(),
|
||||
onRunChanged: (_) {},
|
||||
for (final status in ['succeeded', 'failed']) {
|
||||
testWidgets('a compact $status row keeps its status, menu and time', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(240, 400);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunListRow(
|
||||
run: {..._finished, 'status': status},
|
||||
now: DateTime.utc(2026, 10, 22),
|
||||
gateway: _FakeGateway(),
|
||||
onRunChanged: (_) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
|
||||
expect(find.text('Ship the release notes'), findsOneWidget);
|
||||
expect(find.text('release'), findsOneWidget);
|
||||
expect(find.text('2m 5s'), findsNothing);
|
||||
expect(find.byKey(const ValueKey('run-list-more-menu-42')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
expect(find.text('Ship the release notes'), findsOneWidget);
|
||||
expect(find.text('release'), findsOneWidget);
|
||||
expect(find.text('2m 5s'), findsNothing);
|
||||
// The status tells a failed run from a succeeded one at any width.
|
||||
final icon = find.byType(RunStatusIcon);
|
||||
expect(icon, findsOneWidget);
|
||||
expect(tester.widget<RunStatusIcon>(icon).state, status);
|
||||
final menu = find.byKey(const ValueKey('run-list-more-menu-42'));
|
||||
expect(menu, findsOneWidget);
|
||||
expect(tester.getRect(menu).right, lessThanOrEqualTo(240));
|
||||
expect(tester.getSize(menu).width, greaterThanOrEqualTo(44));
|
||||
expect(find.byType(RelativeTimeLabel), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
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/ui/adaptive/segmented_bar.dart';
|
||||
|
||||
void _size(WidgetTester tester, double width) {
|
||||
tester.view.physicalSize = Size(width, 700);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
}
|
||||
|
||||
const _names = ['Needs you', 'Usage', 'Filter', 'Sort', 'Select'];
|
||||
|
||||
Key _key(String name) => ValueKey('action.$name');
|
||||
|
||||
/// An icon action like the list bars' own, at the host's touch target.
|
||||
Widget _icon(bool cupertino, String name, VoidCallback onPressed) => cupertino
|
||||
? Semantics(
|
||||
button: true,
|
||||
label: name,
|
||||
excludeSemantics: true,
|
||||
child: CupertinoButton(
|
||||
key: _key(name),
|
||||
padding: EdgeInsets.zero,
|
||||
minimumSize: const Size.square(kMinInteractiveDimensionCupertino),
|
||||
onPressed: onPressed,
|
||||
child: const Icon(CupertinoIcons.circle),
|
||||
),
|
||||
)
|
||||
: IconButton(
|
||||
key: _key(name),
|
||||
tooltip: name,
|
||||
onPressed: onPressed,
|
||||
icon: const Icon(Icons.circle_outlined),
|
||||
);
|
||||
|
||||
/// The Runs bar's shape: a bell that always stays, then four that may move.
|
||||
List<Widget> _actions(bool cupertino, List<String> pressed) => [
|
||||
for (final name in _names)
|
||||
if (name == 'Needs you')
|
||||
_icon(cupertino, name, () => pressed.add(name))
|
||||
else
|
||||
SegmentedOverflowAction(
|
||||
overflowEntry: SegmentedOverflowEntry(
|
||||
label: name,
|
||||
icon: Icons.circle_outlined,
|
||||
onPressed: () => pressed.add(name),
|
||||
),
|
||||
child: _icon(cupertino, name, () => pressed.add(name)),
|
||||
),
|
||||
];
|
||||
|
||||
Widget _app(bool cupertino, SegmentedBar bar, {Brightness? brightness}) =>
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
theme: CupertinoThemeData(brightness: brightness),
|
||||
home: CupertinoPageScaffold(
|
||||
navigationBar: bar,
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
)
|
||||
: MaterialApp(
|
||||
theme: ThemeData(brightness: brightness ?? Brightness.light),
|
||||
home: Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: bar,
|
||||
body: const SizedBox.expand(),
|
||||
),
|
||||
);
|
||||
|
||||
/// Pumps the bar and the frame its More menu settles in.
|
||||
Future<void> _pump(WidgetTester tester, Widget app) async {
|
||||
await tester.pumpWidget(app);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
}
|
||||
|
||||
bool _whole(WidgetTester tester, String text) {
|
||||
final paragraph = tester.renderObject<RenderParagraph>(find.text(text));
|
||||
final natural = (TextPainter(
|
||||
text: TextSpan(text: text, style: paragraph.text.style),
|
||||
textDirection: TextDirection.ltr,
|
||||
textScaler: paragraph.textScaler,
|
||||
)..layout()).width;
|
||||
return !paragraph.didExceedMaxLines && paragraph.size.width >= natural - 0.5;
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
final host = cupertino ? 'Cupertino' : 'Material';
|
||||
for (final width in [240.0, 270.0, 320.0]) {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('$host ${brightness.name} ${width.toInt()}px: the title '
|
||||
'shows whole, actions keep their targets, the rest are in More', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, width);
|
||||
final pressed = <String>[];
|
||||
await _pump(
|
||||
tester,
|
||||
_app(
|
||||
cupertino,
|
||||
brightness: brightness,
|
||||
SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
title: 'Runs',
|
||||
actions: _actions(cupertino, pressed),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(_whole(tester, 'Runs'), isTrue);
|
||||
final title = tester.getRect(find.text('Runs'));
|
||||
final shown = [
|
||||
for (final name in _names)
|
||||
if (find.byKey(_key(name)).hitTestable().evaluate().isNotEmpty)
|
||||
name,
|
||||
];
|
||||
// The bell cannot move; at these widths the others do not all fit.
|
||||
expect(shown, contains('Needs you'));
|
||||
expect(shown.length, lessThan(_names.length));
|
||||
final more = find.byKey(segmentedMoreKey).hitTestable();
|
||||
expect(more, findsOneWidget);
|
||||
final rects = [
|
||||
for (final name in shown) tester.getRect(find.byKey(_key(name))),
|
||||
tester.getRect(more),
|
||||
];
|
||||
final target = cupertino ? 44.0 : 48.0;
|
||||
for (final (index, rect) in rects.indexed) {
|
||||
expect(rect.width, greaterThanOrEqualTo(target));
|
||||
expect(rect.height, greaterThanOrEqualTo(target));
|
||||
// Clear of the title and inside the bar's edge padding.
|
||||
expect(rect.left, greaterThan(title.right));
|
||||
expect(rect.right, lessThanOrEqualTo(width - 12));
|
||||
if (index > 0) {
|
||||
expect(rect.left, greaterThanOrEqualTo(rects[index - 1].right));
|
||||
}
|
||||
}
|
||||
// Each moved action is in the More menu and runs from there.
|
||||
await tester.tap(more);
|
||||
await tester.pumpAndSettle();
|
||||
final moved = [
|
||||
for (final name in _names)
|
||||
if (!shown.contains(name)) name,
|
||||
];
|
||||
for (final name in moved) {
|
||||
expect(find.text(name), findsOneWidget, reason: name);
|
||||
}
|
||||
await tester.tap(find.text(moved.last));
|
||||
await tester.pumpAndSettle();
|
||||
expect(pressed, [moved.last]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
testWidgets('$host: a wide bar shows every action and no More', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, 800);
|
||||
await _pump(
|
||||
tester,
|
||||
_app(
|
||||
cupertino,
|
||||
SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
title: 'Runs',
|
||||
actions: _actions(cupertino, []),
|
||||
),
|
||||
),
|
||||
);
|
||||
for (final name in _names) {
|
||||
expect(find.byKey(_key(name)).hitTestable(), findsOneWidget);
|
||||
}
|
||||
expect(find.byKey(segmentedMoreKey).hitTestable(), findsNothing);
|
||||
// A hidden More is out of the semantics tree too.
|
||||
expect(find.bySemanticsLabel('More actions'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('$host: a longer title keeps a readable share at 240px', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, 240);
|
||||
await _pump(
|
||||
tester,
|
||||
_app(
|
||||
cupertino,
|
||||
SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
title: 'Pipelines',
|
||||
actions: _actions(cupertino, []),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
// The test font's glyphs are squares, wider than a real font's, so
|
||||
// the name may ellipsise here, but never to nothing.
|
||||
final paragraph = tester.renderObject<RenderParagraph>(
|
||||
find.text('Pipelines'),
|
||||
);
|
||||
expect(paragraph.size.width, greaterThan(3 * 14));
|
||||
expect(find.byKey(segmentedMoreKey).hitTestable(), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('$host: a choice entry offers its choices from More', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, 240);
|
||||
String? picked;
|
||||
await _pump(
|
||||
tester,
|
||||
_app(
|
||||
cupertino,
|
||||
SegmentedBar(
|
||||
cupertino: cupertino,
|
||||
title: 'Runs',
|
||||
actions: [
|
||||
for (final name in ['A', 'B', 'C'])
|
||||
SegmentedOverflowAction(
|
||||
overflowEntry: SegmentedOverflowEntry(
|
||||
label: 'Sort $name',
|
||||
icon: Icons.sort,
|
||||
choices: [
|
||||
for (final order in ['Newest', 'Oldest'])
|
||||
SegmentedMenuChoice(
|
||||
label: order,
|
||||
selected: order == 'Newest',
|
||||
onSelected: () => picked = '$name $order',
|
||||
),
|
||||
],
|
||||
),
|
||||
child: _icon(cupertino, name, () {}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(segmentedMoreKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sort C'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Oldest'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(picked, 'C Oldest');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -182,37 +182,40 @@ void main() {
|
||||
expect(_paint(tester, '9d ago').color, isNot(accent));
|
||||
});
|
||||
|
||||
testWidgets('$host: a narrow pane drops the avatar, time and menu', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, 240);
|
||||
await tester.pumpWidget(_host(cupertino, _row()));
|
||||
expect(find.byKey(const Key('avatar')), findsNothing);
|
||||
expect(find.text('9d ago'), findsNothing);
|
||||
expect(find.byKey(const Key('menu')), findsNothing);
|
||||
expect(find.text('Running'), findsOneWidget);
|
||||
expect(find.text('pipeline · 2 stages'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('$host: keepMenuWhenCompact keeps the menu', (tester) async {
|
||||
_size(tester, 240);
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
cupertino,
|
||||
AppListRow(
|
||||
keepMenuWhenCompact: true,
|
||||
title: const Text('Chat'),
|
||||
menu: AppOverflowMenu<int>(
|
||||
key: const Key('menu'),
|
||||
actions: const [AppMenuAction(value: 1, label: 'Star')],
|
||||
onSelected: (_, _) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const Key('menu')), findsOneWidget);
|
||||
});
|
||||
for (final width in [240.0, 270.0]) {
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('$host ${brightness.name}: a ${width.toInt()}px pane keeps '
|
||||
'the status avatar and the menu, and the time under the subtitle', (
|
||||
tester,
|
||||
) async {
|
||||
_size(tester, width);
|
||||
await tester.pumpWidget(
|
||||
_host(cupertino, brightness: brightness, _row(title: _longTitle)),
|
||||
);
|
||||
final row = tester.getRect(find.byKey(const Key('row')));
|
||||
final avatar = tester.getRect(find.byKey(const Key('avatar')));
|
||||
final menu = tester.getRect(find.byKey(const Key('menu')));
|
||||
// Both inside the row, at the leading and trailing edges.
|
||||
expect(avatar.left, greaterThanOrEqualTo(row.left));
|
||||
expect(menu.right, lessThanOrEqualTo(row.right));
|
||||
expect(menu.width, greaterThanOrEqualTo(44));
|
||||
expect(menu.height, greaterThanOrEqualTo(44));
|
||||
expect(find.text('Running'), findsOneWidget);
|
||||
expect(find.text('pipeline · 2 stages'), findsNothing);
|
||||
// The time sits on its own line, under the subtitle.
|
||||
final time = tester.getRect(find.text('9d ago'));
|
||||
final subtitle = tester.getRect(find.text('Running'));
|
||||
expect(time.top, greaterThanOrEqualTo(subtitle.bottom));
|
||||
expect(time.left, greaterThan(avatar.right));
|
||||
expect(time.right, lessThan(menu.left));
|
||||
// The title ellipsises between them.
|
||||
final title = tester.getRect(find.text(_longTitle));
|
||||
expect(title.left, greaterThan(avatar.right));
|
||||
expect(title.right, lessThanOrEqualTo(menu.left));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (final brightness in Brightness.values) {
|
||||
testWidgets('$host ${brightness.name}: 320px at 2x text ellipsises '
|
||||
|
||||
Reference in New Issue
Block a user