Files
pipelines/app/test/ui/adaptive/app_action_sheet_test.dart
T
alan 046de9db4d Use proper phone sheets for chat and Files menus
On phones the chat's More menu, chat list rows and Files entries open a
Material bottom sheet headed by the chat or file, with full-width icon
rows and destructive actions last in the error colour; desktop menus
show icons, a minimum width and destructive actions after a divider.
The chat menu drops Run command and Open chats, keeps a single terminal
entry and lists Close pane last.
2026-11-13 01:14:12 +00:00

178 lines
5.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/ui/adaptive/segmented_bar_overflow.dart';
import 'package:pipelines_app/ui/layout/app_overflow_menu.dart';
void _size(WidgetTester tester, double width) {
tester.view.physicalSize = Size(width, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
}
Widget _menu(void Function(String) picked) => MaterialApp(
home: Scaffold(
body: Center(
child: AppOverflowMenu<String>(
key: const Key('menu'),
sheetTitle: 'notes.md',
sheetSubtitle: 'Markdown · 2 KB',
onSelected: (_, value) => picked(value),
actions: const [
AppMenuAction(
value: 'delete',
label: 'Delete…',
icon: Icons.delete_outline,
destructive: true,
),
AppMenuAction(value: 'open', label: 'Open', icon: Icons.open_in_new),
AppMenuAction(
value: 'rename',
label: 'Rename…',
icon: Icons.edit_outlined,
),
],
),
),
),
);
void main() {
testWidgets('a phone opens a headed sheet with icon rows and destructive '
'actions last', (tester) async {
_size(tester, 430);
String? picked;
await tester.pumpWidget(_menu((value) => picked = value));
await tester.tap(find.byKey(const Key('menu')));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsOneWidget);
expect(find.text('notes.md'), findsOneWidget);
expect(find.text('Markdown · 2 KB'), findsOneWidget);
final rows = find.descendant(
of: find.byType(BottomSheet),
matching: find.byType(ListTile),
);
expect(rows, findsNWidgets(3));
final labels = [
for (final tile in tester.widgetList<ListTile>(rows))
(tile.title! as Text).data,
];
expect(labels, ['Open', 'Rename…', 'Delete…']);
for (final icon in [
Icons.open_in_new,
Icons.edit_outlined,
Icons.delete_outline,
]) {
expect(
find.descendant(of: rows, matching: find.byIcon(icon)),
findsOneWidget,
);
}
// Rows are full width and at least 56 px tall.
final open = tester.getRect(find.widgetWithText(ListTile, 'Open'));
expect(open.height, greaterThanOrEqualTo(56));
expect(open.width, closeTo(430, 1));
// The destructive row reads in the error colour.
final scheme = Theme.of(tester.element(rows.first)).colorScheme;
final deleteText = tester.widget<Text>(find.text('Delete…'));
expect(deleteText.style?.color, scheme.error);
await tester.tap(find.text('Rename…'));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsNothing);
expect(picked, 'rename');
});
testWidgets(
'a wide app keeps an anchored menu with icons, destructive last',
(tester) async {
_size(tester, 1200);
String? picked;
await tester.pumpWidget(_menu((value) => picked = value));
await tester.tap(find.byKey(const Key('menu')));
await tester.pumpAndSettle();
expect(find.byType(BottomSheet), findsNothing);
final items = find.byType(PopupMenuItem<String>);
expect(items, findsNWidgets(3));
expect(
[
for (final item in tester.widgetList<PopupMenuItem<String>>(items))
item.value,
],
['open', 'rename', 'delete'],
);
expect(find.byType(PopupMenuDivider), findsOneWidget);
expect(find.byIcon(Icons.edit_outlined), findsOneWidget);
expect(tester.getSize(items.first).width, greaterThanOrEqualTo(220));
await tester.tap(find.text('Open'));
await tester.pumpAndSettle();
expect(picked, 'open');
},
);
testWidgets('a bar More button opens the same sheet on a phone, with '
'submenu choices on a second sheet', (tester) async {
_size(tester, 430);
var closed = 0;
String? sort;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: SegmentedMoreButton(
sheetTitle: 'Chat a',
sheetSubtitle: 'demo',
entries: [
SegmentedOverflowEntry(
label: 'Close pane',
icon: Icons.close,
destructive: true,
onPressed: () => closed++,
),
SegmentedOverflowEntry(
label: 'Sort',
icon: Icons.sort,
choices: [
SegmentedMenuChoice(
label: 'Name',
selected: true,
onSelected: () => sort = 'name',
),
SegmentedMenuChoice(
label: 'Size',
onSelected: () => sort = 'size',
),
],
),
],
),
),
),
),
);
await tester.tap(find.byKey(segmentedMoreKey));
await tester.pumpAndSettle();
expect(find.text('Chat a'), findsOneWidget);
final labels = [
for (final tile in tester.widgetList<ListTile>(find.byType(ListTile)))
(tile.title! as Text).data,
];
expect(labels, ['Sort', 'Close pane']);
await tester.tap(find.text('Sort'));
await tester.pumpAndSettle();
expect(find.text('Name'), findsOneWidget);
expect(find.byIcon(Icons.check), findsOneWidget);
await tester.tap(find.text('Size'));
await tester.pumpAndSettle();
expect(sort, 'size');
await tester.tap(find.byKey(segmentedMoreKey));
await tester.pumpAndSettle();
await tester.tap(find.text('Close pane'));
await tester.pumpAndSettle();
expect(closed, 1);
});
}