feat(garage_ui): an item view in four layouts, a breadcrumb and a file drop target
ItemView draws a set of named things as a list, a two line list, a table with sortable headers or a grid, and ItemViewModeSwitch lets whoever is looking pick. Columns drop from the end on a narrow pane before the name gets squeezed. Breadcrumb is ghost buttons with chevrons. FileDropTarget takes files dragged in from outside and shows the focus ring while one is held over it; it sits on desktop_drop, which is a new dependency. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KHotisA4hV2xmuZsHTksFX
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
cc2fe99d02
commit
444933b004
@@ -0,0 +1,134 @@
|
||||
import "package:flutter/widgets.dart";
|
||||
import "package:flutter_test/flutter_test.dart";
|
||||
import "package:garage_ui/garage_ui.dart";
|
||||
|
||||
import "support/test_scheme.dart";
|
||||
|
||||
Widget _host(Widget child, {double width = 700}) => Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: GarageTheme(
|
||||
data: ThemeData(colorScheme: testScheme, density: const Density()),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(width: width, child: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
const _columns = [
|
||||
ItemColumn(id: "size", label: "Size"),
|
||||
ItemColumn(id: "modified", label: "Modified"),
|
||||
];
|
||||
|
||||
List<ItemEntry> _entries({void Function(String id)? opened}) => [
|
||||
for (final (id, name, size) in [
|
||||
("a", "Holiday photos", ""),
|
||||
("b", "invoice-0412.pdf", "212 KB"),
|
||||
("c", "clip.mov", "1.4 GB"),
|
||||
])
|
||||
ItemEntry(
|
||||
id: id,
|
||||
title: name,
|
||||
leading: (context, extent) => SizedBox.square(dimension: extent),
|
||||
cells: {"size": size, "modified": "3 Oct"},
|
||||
onOpen: () => opened?.call(id),
|
||||
),
|
||||
];
|
||||
|
||||
void main() {
|
||||
testWidgets("a list is ruled between rows and has no header", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(ItemView(mode: ItemViewMode.list, entries: _entries(), columns: _columns)),
|
||||
);
|
||||
expect(find.byType(Divider), findsNWidgets(2));
|
||||
expect(find.text("Size"), findsNothing);
|
||||
expect(find.text("212 KB"), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("a table has headers, and pressing one says which", (tester) async {
|
||||
final pressed = <String>[];
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ItemView(
|
||||
mode: ItemViewMode.table,
|
||||
entries: _entries(),
|
||||
columns: _columns,
|
||||
sortColumn: "size",
|
||||
onSort: pressed.add,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text("Modified"));
|
||||
await tester.tap(find.text("Name"));
|
||||
expect(pressed, ["modified", kItemTitleColumn]);
|
||||
});
|
||||
|
||||
testWidgets("too narrow, and columns go from the end before the name does", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
ItemView(mode: ItemViewMode.table, entries: _entries(), columns: _columns),
|
||||
width: 260,
|
||||
),
|
||||
);
|
||||
expect(find.text("Modified"), findsNothing);
|
||||
expect(find.text("Size"), findsOneWidget);
|
||||
expect(find.text("invoice-0412.pdf"), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets("two lines puts the cells under the name, skipping empty ones", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(ItemView(mode: ItemViewMode.twoLine, entries: _entries(), columns: _columns)),
|
||||
);
|
||||
expect(find.text("212 KB · 3 Oct"), findsOneWidget);
|
||||
// the folder has no size, and doesnt get a stray separator for it
|
||||
expect(find.text("3 Oct"), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets("the grid lays tiles out and a tile opens", (tester) async {
|
||||
final opened = <String>[];
|
||||
await tester.pumpWidget(
|
||||
_host(ItemView(mode: ItemViewMode.grid, entries: _entries(opened: opened.add), columns: _columns)),
|
||||
);
|
||||
final first = tester.getTopLeft(find.text("Holiday photos"));
|
||||
final second = tester.getTopLeft(find.text("invoice-0412.pdf"));
|
||||
expect(first.dy, second.dy, reason: "side by side at this width");
|
||||
await tester.tap(find.text("clip.mov"));
|
||||
expect(opened, ["c"]);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets("the grid survives a phone", (tester) async {
|
||||
await tester.pumpWidget(
|
||||
_host(ItemView(mode: ItemViewMode.grid, entries: _entries(), columns: _columns), width: 150),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets("the switch reports the mode that was pressed", (tester) async {
|
||||
ItemViewMode? got;
|
||||
await tester.pumpWidget(
|
||||
_host(ItemViewModeSwitch(mode: ItemViewMode.list, onChanged: (m) => got = m)),
|
||||
);
|
||||
await tester.tap(find.bySemanticsLabel("Grid view"));
|
||||
expect(got, ItemViewMode.grid);
|
||||
});
|
||||
|
||||
testWidgets("the last crumb is where you are, and doesnt go anywhere", (tester) async {
|
||||
final went = <String>[];
|
||||
await tester.pumpWidget(
|
||||
_host(
|
||||
Breadcrumb(
|
||||
items: [
|
||||
BreadcrumbItem(label: "Files", onPressed: () => went.add("files")),
|
||||
BreadcrumbItem(label: "Work", onPressed: () => went.add("work")),
|
||||
BreadcrumbItem(label: "Invoices", onPressed: () => went.add("invoices")),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text("Work"));
|
||||
await tester.tap(find.text("Invoices"));
|
||||
expect(went, ["work"]);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user