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.
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -106,7 +106,7 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(taps, 1);
|
||||
|
||||
// The overflow control is a Material menu.
|
||||
// The overflow control opens a phone's bottom sheet at this width.
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('menu')),
|
||||
@@ -117,7 +117,13 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('menu')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(taps, 1, reason: 'the menu is its own control');
|
||||
expect(find.byType(PopupMenuItem<String>), findsNWidgets(2));
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byType(BottomSheet),
|
||||
matching: find.byType(ListTile),
|
||||
),
|
||||
findsNWidgets(2),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('menu-delete')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(picked, 'delete');
|
||||
|
||||
Reference in New Issue
Block a user