refactor(desktop): reorganize workspace panels and navigation
This commit is contained in:
1 parent
826745b407
commit
1f73765745
92 files changed
+5811
-2650
No files matched your search
+227
-15
@@ -1,7 +1,8 @@
|
||||
import 'package:cutdex/features/media/media_browser_toolbar.dart';
|
||||
import 'package:cutdex/features/media/media_browser_controller.dart';
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/media/media_browser_page.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:ui' as ui;
|
||||
@@ -39,6 +40,182 @@ void main() {
|
||||
null,
|
||||
);
|
||||
});
|
||||
testWidgets('project switching retains media surface and controls', (
|
||||
tester,
|
||||
) async {
|
||||
final projects = _Projects();
|
||||
final container = ProviderContainer(
|
||||
overrides: [projectsProvider.overrideWith(() => projects)],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
await container.read(projectsProvider.future);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Consumer(
|
||||
builder: (context, ref, _) {
|
||||
final id = ref.watch(
|
||||
projectsProvider.select(
|
||||
(value) => value.value?.activeProject?.id,
|
||||
),
|
||||
);
|
||||
return MediaPanel(projectId: id);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final surface = tester.element(
|
||||
find.byKey(const Key('media-panel-surface')),
|
||||
);
|
||||
final header = tester.element(find.byKey(const Key('media-panel-header')));
|
||||
final body = tester.element(find.byKey(const Key('media-panel-body')));
|
||||
final filterRow = tester.widget(find.byKey(const Key('media-filter-row')));
|
||||
final toolbar = tester.widget<MediaBrowserToolbar>(
|
||||
find.byType(MediaBrowserToolbar),
|
||||
);
|
||||
container.read(mediaBrowserProvider('project')).selectedAssetId =
|
||||
'selection';
|
||||
await tester.pump();
|
||||
expect(
|
||||
tester.widget<MediaBrowserToolbar>(find.byType(MediaBrowserToolbar)),
|
||||
same(toolbar),
|
||||
);
|
||||
projects.switchProject('second');
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.element(find.byKey(const Key('media-panel-surface'))),
|
||||
same(surface),
|
||||
);
|
||||
expect(
|
||||
tester.element(find.byKey(const Key('media-panel-header'))),
|
||||
same(header),
|
||||
);
|
||||
expect(
|
||||
tester.element(find.byKey(const Key('media-panel-body'))),
|
||||
same(body),
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<MediaBrowserToolbar>(find.byType(MediaBrowserToolbar))
|
||||
.selectedProjectId,
|
||||
'second',
|
||||
);
|
||||
expect(
|
||||
tester.widget(find.byKey(const Key('media-filter-row'))),
|
||||
same(filterRow),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('media-layout-toggle')));
|
||||
await tester.pump();
|
||||
expect(container.read(mediaBrowserProvider('second')).grid, isFalse);
|
||||
expect(container.read(mediaBrowserProvider('project')).grid, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
for (final locale in const [Locale('zh'), Locale('en'), Locale('de')]) {
|
||||
testWidgets(
|
||||
'sidebar toolbar fits widths and scaled text in ${locale.languageCode}',
|
||||
(tester) async {
|
||||
var imports = 0;
|
||||
var toggles = 0;
|
||||
var projectSelections = 0;
|
||||
for (final width in [120.0, 180.0, 240.0, 360.0]) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
locale: locale,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: EditorTheme.penLight,
|
||||
home: Scaffold(
|
||||
body: MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
textScaler: TextScaler.linear(1.5),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: MediaBrowserToolbar(
|
||||
projects: const [
|
||||
RecentProject(
|
||||
id: 'first',
|
||||
name: 'First project with a long name',
|
||||
path: '/first',
|
||||
),
|
||||
RecentProject(
|
||||
id: 'second',
|
||||
name: 'Second project',
|
||||
path: '/second',
|
||||
),
|
||||
],
|
||||
selectedProjectId: 'first',
|
||||
onProjectSelected: (project) {
|
||||
expect(project.id, 'second');
|
||||
projectSelections++;
|
||||
},
|
||||
canImport: true,
|
||||
onImport: () => imports++,
|
||||
filter: MediaFilter.all,
|
||||
onFilterChanged: (_) {},
|
||||
grid: true,
|
||||
onToggleGrid: () => toggles++,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull);
|
||||
if (width == 240) {
|
||||
expect(find.byKey(const Key('media-header-scroll')), findsNothing);
|
||||
final projectButton = tester.widget<TextButton>(
|
||||
find.byKey(const Key('media-project-button')),
|
||||
);
|
||||
final ink = Theme.of(
|
||||
tester.element(find.byKey(const Key('media-project-button'))),
|
||||
).colorScheme.onSurface;
|
||||
for (final state in [
|
||||
WidgetState.hovered,
|
||||
WidgetState.focused,
|
||||
WidgetState.pressed,
|
||||
]) {
|
||||
expect(
|
||||
projectButton.style!.backgroundColor!.resolve({state}),
|
||||
Colors.transparent,
|
||||
);
|
||||
expect(
|
||||
projectButton.style!.overlayColor!.resolve({state}),
|
||||
ink.withValues(alpha: .05),
|
||||
);
|
||||
}
|
||||
expect(
|
||||
projectButton.style!.overlayColor!.resolve({
|
||||
WidgetState.disabled,
|
||||
WidgetState.hovered,
|
||||
}),
|
||||
Colors.transparent,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('media-project-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('media-project-second')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('media-import-button')));
|
||||
await tester.tap(find.byKey(const Key('media-layout-toggle')));
|
||||
}
|
||||
}
|
||||
expect(imports, 1);
|
||||
expect(toggles, 1);
|
||||
expect(projectSelections, 1);
|
||||
},
|
||||
);
|
||||
}
|
||||
testWidgets(
|
||||
'list and grid share a context menu targeting the clicked asset',
|
||||
(tester) async {
|
||||
@@ -262,7 +439,7 @@ void main() {
|
||||
expect(find.byKey(const Key('media-import-button')), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-panel-header'))).height,
|
||||
AppControlSize.panelToolbar,
|
||||
AppControlSize.panelToolbar * 2,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-import-button'))).height,
|
||||
@@ -282,22 +459,34 @@ void main() {
|
||||
find.byKey(const Key('media-layout-toggle')),
|
||||
);
|
||||
final filter = find.byWidgetPredicate(
|
||||
(widget) => widget is AppSelect && widget.label == '素材分类',
|
||||
(widget) => widget is Semantics && widget.properties.label == '素材分类',
|
||||
);
|
||||
final filterButton = tester.getRect(
|
||||
find.descendant(of: filter, matching: find.byType(TextButton)),
|
||||
);
|
||||
expect(importButton.left - header.left, AppSpacing.gap);
|
||||
expect(header.right - importButton.right, AppSidebarMetrics.outerPadding);
|
||||
expect(importButton.top - header.top, AppSpacing.gap);
|
||||
expect(header.right - layoutButton.right, AppSpacing.gap);
|
||||
expect(layoutButton.left - filterButton.right, AppSpacing.tiny);
|
||||
expect(layoutButton.top - importButton.top, AppControlSize.panelToolbar);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('media-project-button'))).top,
|
||||
importButton.top,
|
||||
);
|
||||
expect(header.right - layoutButton.right, AppSidebarMetrics.outerPadding);
|
||||
expect(
|
||||
layoutButton.left - filterButton.right,
|
||||
greaterThanOrEqualTo(AppSpacing.tiny),
|
||||
);
|
||||
expect(tester.getSize(filter).height, AppControlSize.headerButton);
|
||||
final importStyle = tester
|
||||
.widget<TextButton>(find.byKey(const Key('media-import-button')))
|
||||
.style!
|
||||
.textStyle!
|
||||
.resolve({})!;
|
||||
final filterStyle = tester.widget<AppSelect<Object?>>(filter).textStyle!;
|
||||
final filterStyle = tester
|
||||
.widget<TextButton>(find.byKey(const Key('media-category-button')))
|
||||
.style!
|
||||
.textStyle!
|
||||
.resolve({})!;
|
||||
expect(importStyle.fontSize, 13);
|
||||
expect(importStyle.height, 18 / 13);
|
||||
expect(filterStyle.fontSize, importStyle.fontSize);
|
||||
@@ -311,7 +500,8 @@ void main() {
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(widget) => widget is AppSelect && widget.label == '素材分类',
|
||||
(widget) =>
|
||||
widget is Semantics && widget.properties.label == '素材分类',
|
||||
),
|
||||
matching: find.byType(TextButton),
|
||||
),
|
||||
@@ -330,7 +520,8 @@ void main() {
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(widget) => widget is AppSelect && widget.label == '素材分类',
|
||||
(widget) =>
|
||||
widget is Semantics && widget.properties.label == '素材分类',
|
||||
),
|
||||
matching: find.byType(TextButton),
|
||||
),
|
||||
@@ -360,7 +551,7 @@ void main() {
|
||||
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
||||
as SliverGridDelegateWithFixedCrossAxisCount)
|
||||
.crossAxisCount;
|
||||
expect(columns(), 2);
|
||||
expect(columns(), 3);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.byType(GridView),
|
||||
@@ -407,15 +598,27 @@ void main() {
|
||||
await tester.tap(find.byTooltip('宫格布局'));
|
||||
await tester.pumpAndSettle();
|
||||
for (final (width, count) in [
|
||||
(180.0, 1),
|
||||
(280.0, 2),
|
||||
(520.0, 3),
|
||||
(560.0, 4),
|
||||
(900.0, 6),
|
||||
(180.0, 2),
|
||||
(280.0, 3),
|
||||
(240.0, 2),
|
||||
(360.0, 3),
|
||||
(520.0, 5),
|
||||
(560.0, 5),
|
||||
(900.0, 8),
|
||||
]) {
|
||||
await tester.binding.setSurfaceSize(Size(width, 600));
|
||||
await tester.pumpAndSettle();
|
||||
expect(columns(), count);
|
||||
final grid = tester.widget<GridView>(find.byType(GridView));
|
||||
final padding = grid.padding!.resolve(TextDirection.ltr);
|
||||
final delegate =
|
||||
grid.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
|
||||
final tileWidth =
|
||||
(tester.getSize(find.byType(GridView)).width -
|
||||
padding.horizontal -
|
||||
delegate.crossAxisSpacing * (count - 1)) /
|
||||
count;
|
||||
expect(tileWidth, lessThanOrEqualTo(120));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
expect(
|
||||
@@ -772,6 +975,15 @@ class _Projects extends Projects {
|
||||
),
|
||||
);
|
||||
|
||||
void switchProject(String id) {
|
||||
state = AsyncData(
|
||||
state.requireValue.copyWith(
|
||||
activeProject: RecentProject(id: id, name: id, path: '/$id.cutdex'),
|
||||
assets: const [],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void setBusy(bool busy) {
|
||||
state = AsyncData(state.requireValue.copyWith(projectBusy: busy));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user