feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
+598
-133
@@ -8,7 +8,7 @@ import 'dart:async';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:cutdex/features/media/media_panel.dart';
|
||||
import 'package:cutdex/features/media/media_asset_strip.dart';
|
||||
import 'package:cutdex_ui/icons.dart';
|
||||
import 'package:cutdex_ui/theme.dart';
|
||||
import 'package:cutdex/shared/widgets/drop_to_add_overlay.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
@@ -130,7 +130,7 @@ void main() {
|
||||
locale: locale,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: EditorTheme.penLight,
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
home: Scaffold(
|
||||
body: MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
@@ -269,7 +269,10 @@ void main() {
|
||||
await tester.tap(find.text('重命名'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<TextField>(find.byType(TextField)).controller!.text,
|
||||
tester
|
||||
.widget<TextField>(find.byType(TextField).last)
|
||||
.controller!
|
||||
.text,
|
||||
'second.txt',
|
||||
);
|
||||
await tester.tap(find.text('取消'));
|
||||
@@ -333,7 +336,9 @@ void main() {
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
|
||||
theme: EditorTheme.penLight,
|
||||
theme: touch
|
||||
? EditorTheme.penLight
|
||||
: EditorTheme.desktop(EditorTheme.penLight),
|
||||
home: Scaffold(
|
||||
body: touch
|
||||
? const MediaBrowserPage(projectId: 'project')
|
||||
@@ -346,57 +351,157 @@ void main() {
|
||||
return container;
|
||||
}
|
||||
|
||||
testWidgets('list uses a filmstrip with real duration above its name', (
|
||||
tester,
|
||||
) async {
|
||||
const channel = MethodChannel('cutdex_runtime');
|
||||
final times = <int>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
if (call.method == 'probe') {
|
||||
return {
|
||||
'duration': {'numerator': '290', 'denominator': 1},
|
||||
'videoTrackCount': 1,
|
||||
'videoTrackIds': [1],
|
||||
'audioTrackCount': 0,
|
||||
'audioTrackIds': <int>[],
|
||||
'audioTracks': <Object?>[],
|
||||
'isProtected': false,
|
||||
};
|
||||
}
|
||||
if (call.method == 'thumbnail') {
|
||||
final args = call.arguments as Map;
|
||||
final time = args['time'] as Map;
|
||||
times.add(int.parse(time['numerator'].toString()));
|
||||
}
|
||||
throw PlatformException(code: 'no-preview');
|
||||
});
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
for (final touch in [false, true]) {
|
||||
testWidgets(
|
||||
'${touch ? 'touch' : 'desktop'} waits for file selection without a loading bar',
|
||||
(tester) async {
|
||||
final channel = MethodChannel(
|
||||
touch ? 'filegate' : 'cutdex_native/file_picker',
|
||||
);
|
||||
final cancelled = Completer<Object?>();
|
||||
final selected = Completer<Object?>();
|
||||
var pickerCalls = 0;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
(_) => pickerCalls++ == 0 ? cancelled.future : selected.future,
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
),
|
||||
);
|
||||
final container = await mount(tester, touch: touch);
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
final imported = Completer<void>();
|
||||
projects.importGate = imported.future;
|
||||
final button = find.byKey(const Key('media-import-button'));
|
||||
|
||||
Future<void> openPicker() async {
|
||||
await tester.tap(button);
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 500));
|
||||
expect(find.byType(LinearProgressIndicator), findsNothing);
|
||||
expect(tester.widget<TextButton>(button).onPressed, isNull);
|
||||
}
|
||||
|
||||
await openPicker();
|
||||
cancelled.complete(null);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(LinearProgressIndicator), findsNothing);
|
||||
expect(tester.widget<TextButton>(button).onPressed, isNotNull);
|
||||
expect(projects.received, isEmpty);
|
||||
|
||||
await openPicker();
|
||||
selected.complete(
|
||||
touch
|
||||
? [
|
||||
{
|
||||
'path': '/originals/clip.mp4',
|
||||
'name': 'clip.mp4',
|
||||
'kind': 'file',
|
||||
},
|
||||
]
|
||||
: ['/originals/clip.mp4'],
|
||||
);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 250));
|
||||
await tester.pump();
|
||||
expect(find.byType(LinearProgressIndicator), findsOneWidget);
|
||||
expect(tester.widget<TextButton>(button).onPressed, isNull);
|
||||
|
||||
imported.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(LinearProgressIndicator), findsNothing);
|
||||
expect(tester.widget<TextButton>(button).onPressed, isNotNull);
|
||||
expect(projects.received.single.localPath, '/originals/clip.mp4');
|
||||
expect(pickerCalls, 2);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
variant: TargetPlatformVariant.only(
|
||||
touch ? TargetPlatform.android : TargetPlatform.macOS,
|
||||
),
|
||||
);
|
||||
final container = await mount(tester);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/movie.mp4'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('列表布局'));
|
||||
await tester.pumpAndSettle();
|
||||
final strip = tester.getRect(find.byType(MediaAssetStrip));
|
||||
final name = tester.getRect(find.text('movie.mp4'));
|
||||
final duration = tester.getRect(find.text('04:50'));
|
||||
expect(strip.height, 46);
|
||||
expect(name.top, greaterThanOrEqualTo(strip.bottom));
|
||||
expect(duration.right, lessThanOrEqualTo(strip.right));
|
||||
expect(duration.left, greaterThan(strip.center.dx));
|
||||
expect(duration.top, strip.top + 5);
|
||||
expect(times.any((time) => time > 0), isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'desktop list uses a compact cover with real duration beside its name',
|
||||
(tester) async {
|
||||
await tester.binding.setSurfaceSize(const Size(320, 600));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
const channel = MethodChannel('cutdex_runtime');
|
||||
final times = <int>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
if (call.method == 'probe') {
|
||||
return {
|
||||
'duration': {'numerator': '290', 'denominator': 1},
|
||||
'videoTrackCount': 1,
|
||||
'videoTrackIds': [1],
|
||||
'audioTrackCount': 0,
|
||||
'audioTrackIds': <int>[],
|
||||
'audioTracks': <Object?>[],
|
||||
'isProtected': false,
|
||||
};
|
||||
}
|
||||
if (call.method == 'thumbnail') {
|
||||
final args = call.arguments as Map;
|
||||
final time = args['time'] as Map;
|
||||
times.add(int.parse(time['numerator'].toString()));
|
||||
}
|
||||
throw PlatformException(code: 'no-preview');
|
||||
});
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
channel,
|
||||
null,
|
||||
),
|
||||
);
|
||||
final container = await mount(tester);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/movie.mp4'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byTooltip('列表布局'));
|
||||
await tester.pumpAndSettle();
|
||||
final cover = tester.getRect(
|
||||
find.byKey(const ValueKey('desktop-media-cover-/movie.mp4')),
|
||||
);
|
||||
final name = tester.getRect(find.text('movie.mp4'));
|
||||
final duration = tester.getRect(find.text('04:50'));
|
||||
expect(cover.width, 56);
|
||||
expect(cover.height, closeTo(56 * 9 / 16, .01));
|
||||
expect(name.left, cover.right + 8);
|
||||
expect(duration.left, greaterThanOrEqualTo(name.left));
|
||||
expect(duration.center.dy, closeTo(cover.center.dy, .01));
|
||||
expect(times.every((time) => time == 0), isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.binding.setSurfaceSize(const Size(180, 600));
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: const Scaffold(
|
||||
body: MediaQuery(
|
||||
data: MediaQueryData(textScaler: TextScaler.linear(1.5)),
|
||||
child: MediaPanel(projectId: 'project'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('04:50'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'missing assets stay named and marked in both layouts without dragging',
|
||||
@@ -425,7 +530,133 @@ void main() {
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'category dropdown filters both layouts and restores all assets',
|
||||
'desktop media fits all six themes and keeps selection at narrow widths',
|
||||
(tester) async {
|
||||
final container = await mount(tester);
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
await projects.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/long-original-asset-name.txt'),
|
||||
const ExternalMediaFile(path: '/second.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
browser.selectedAssetId = '/long-original-asset-name.txt';
|
||||
for (final palette in AppPalette.values) {
|
||||
for (final brightness in Brightness.values) {
|
||||
for (final width in [180.0, 240.0, 320.0, 560.0]) {
|
||||
for (final grid in [true, false]) {
|
||||
browser.grid = grid;
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(
|
||||
EditorTheme.forPalette(palette, brightness),
|
||||
),
|
||||
localizationsDelegates:
|
||||
AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('en'),
|
||||
home: Scaffold(
|
||||
body: MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
textScaler: TextScaler.linear(1.5),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: const MediaPanel(projectId: 'project'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(browser.selectedAssetId, '/long-original-asset-name.txt');
|
||||
final cover = tester.getRect(
|
||||
find.byKey(
|
||||
const ValueKey(
|
||||
'desktop-media-cover-/long-original-asset-name.txt',
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(cover.width / cover.height, closeTo(16 / 9, .01));
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: '$palette $brightness width=$width grid=$grid',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'Chinese media cards fit fractional text scaling without overflow',
|
||||
(tester) async {
|
||||
final container = await mount(tester);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/截屏2026-10-08 21.32.56.txt'),
|
||||
const ExternalMediaFile(path: '/gyp-ÁÉ-long-file-name.txt'),
|
||||
]);
|
||||
for (final width in [180.0, 241.0, 321.0]) {
|
||||
for (final scale in [1.0, 1.05, 1.1, 1.25, 1.5, 2.0]) {
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
locale: const Locale('zh'),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
body: Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: MediaQuery(
|
||||
data: MediaQueryData(
|
||||
textScaler: TextScaler.linear(scale),
|
||||
),
|
||||
child: const MediaPanel(projectId: 'project'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: 'width=$width scale=$scale',
|
||||
);
|
||||
final tile = find.byKey(const ValueKey('/截屏2026-10-08 21.32.56.txt'));
|
||||
final metadata = find.descendant(of: tile, matching: find.text('素材'));
|
||||
expect(
|
||||
tester.getRect(tile).bottom - tester.getRect(metadata).bottom,
|
||||
greaterThanOrEqualTo(5),
|
||||
);
|
||||
final cover = tester.getRect(
|
||||
find.byKey(
|
||||
const ValueKey('desktop-media-cover-/截屏2026-10-08 21.32.56.txt'),
|
||||
),
|
||||
);
|
||||
expect(cover.width / cover.height, closeTo(16 / 9, .01));
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'desktop categories filter both layouts and retain shared controls',
|
||||
(tester) async {
|
||||
final container = await mount(tester);
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
@@ -436,80 +667,42 @@ void main() {
|
||||
const ExternalMediaFile(path: '/notes.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('media-import-button')), findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-panel-header'))).height,
|
||||
AppControlSize.panelToolbar * 2,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-import-button'))).height,
|
||||
AppControlSize.headerButton,
|
||||
);
|
||||
final header = tester.getRect(
|
||||
find.byKey(const Key('media-panel-header')),
|
||||
);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('media-panel-body'))).top,
|
||||
header.bottom,
|
||||
);
|
||||
final importButton = tester.getRect(
|
||||
find.byKey(const Key('media-import-button')),
|
||||
);
|
||||
final layoutButton = tester.getRect(
|
||||
find.byKey(const Key('media-layout-toggle')),
|
||||
);
|
||||
final filter = find.byWidgetPredicate(
|
||||
(widget) => widget is Semantics && widget.properties.label == '素材分类',
|
||||
final sortButton = tester.getRect(
|
||||
find.byKey(const Key('media-sort-button')),
|
||||
);
|
||||
final filterButton = tester.getRect(
|
||||
find.descendant(of: filter, matching: find.byType(TextButton)),
|
||||
);
|
||||
expect(header.right - importButton.right, AppSidebarMetrics.outerPadding);
|
||||
expect(importButton.top - header.top, AppSpacing.gap);
|
||||
expect(layoutButton.top - importButton.top, AppControlSize.panelToolbar);
|
||||
expect(header.height, 76);
|
||||
expect(importButton.height, 28);
|
||||
expect(importButton.top - header.top, 4);
|
||||
expect(header.right - importButton.right, 12);
|
||||
expect(header.right - layoutButton.right, 12);
|
||||
expect(sortButton.top, layoutButton.top);
|
||||
expect(layoutButton.left - sortButton.right, 36);
|
||||
expect(find.byKey(const Key('media-category-button')), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('media-filter-image')), findsNothing);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('media-project-button'))).top,
|
||||
importButton.top,
|
||||
tester.getRect(find.byKey(const Key('media-panel-body'))).top,
|
||||
header.bottom,
|
||||
);
|
||||
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<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);
|
||||
expect(filterStyle.height, importStyle.height);
|
||||
expect(find.text('4 个素材'), findsNothing);
|
||||
expect(find.text('4 个素材'), findsOneWidget);
|
||||
for (final entry in {
|
||||
'图片': 'photo.png',
|
||||
'视频': 'movie.mp4',
|
||||
'音频': 'song.wav',
|
||||
'image': 'photo.png',
|
||||
'video': 'movie.mp4',
|
||||
'audio': 'song.wav',
|
||||
}.entries) {
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Semantics && widget.properties.label == '素材分类',
|
||||
),
|
||||
matching: find.byType(TextButton),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('media-category-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(MenuItemButton, entry.key));
|
||||
await tester.tap(find.byKey(ValueKey('media-filter-${entry.key}')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('1 个素材'), findsNothing);
|
||||
expect(find.text('1 个素材'), findsOneWidget);
|
||||
expect(find.text(entry.value), findsOneWidget);
|
||||
expect(find.text('notes.txt'), findsNothing);
|
||||
}
|
||||
@@ -517,24 +710,73 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('song.wav'), findsOneWidget);
|
||||
expect(find.text('movie.mp4'), findsNothing);
|
||||
await tester.tap(
|
||||
find.descendant(
|
||||
of: find.byWidgetPredicate(
|
||||
(widget) =>
|
||||
widget is Semantics && widget.properties.label == '素材分类',
|
||||
),
|
||||
matching: find.byType(TextButton),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('media-category-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.widgetWithText(MenuItemButton, '全部'));
|
||||
await tester.tap(find.byKey(const ValueKey('media-filter-all')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('4 个素材'), findsNothing);
|
||||
expect(find.text('4 个素材'), findsOneWidget);
|
||||
expect(find.text('notes.txt'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'search and sort share selection across layouts and preserve project choices',
|
||||
(tester) async {
|
||||
final container = await mount(tester);
|
||||
final projects = container.read(projectsProvider.notifier) as _Projects;
|
||||
await projects.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/Zebra.png'),
|
||||
const ExternalMediaFile(path: '/Alpha.png'),
|
||||
const ExternalMediaFile(path: '/song.wav'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
final search = find.byKey(const Key('media-search'));
|
||||
await tester.enterText(search, 'ALPHA');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Zebra.png'), findsNothing);
|
||||
expect(find.text('1 个素材'), findsOneWidget);
|
||||
await tester.tap(find.text('Alpha.png'));
|
||||
await tester.pumpAndSettle();
|
||||
final selected = browser.selectedAssetId!;
|
||||
final before = tester.getSize(find.byKey(ValueKey(selected)));
|
||||
await tester.tap(find.text('Alpha.png'));
|
||||
await tester.pump();
|
||||
expect(tester.getSize(find.byKey(ValueKey(selected))), before);
|
||||
await tester.tap(find.byTooltip('列表布局'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(browser.selectedAssetId, selected);
|
||||
expect(tester.widget<TextField>(search).controller!.text, 'ALPHA');
|
||||
expect(find.text('已选 1 个'), findsOneWidget);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('media-browser-footer'))).right -
|
||||
tester.getRect(find.text('已选 1 个')).right,
|
||||
12,
|
||||
);
|
||||
await tester.enterText(search, 'not found');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('没有匹配的素材'), findsOneWidget);
|
||||
expect(find.text('已选 1 个'), findsNothing);
|
||||
await tester.enterText(search, '');
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('media-sort-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const ValueKey('media-sort-nameAscending')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getTopLeft(find.text('Alpha.png')).dy,
|
||||
lessThan(tester.getTopLeft(find.text('Zebra.png')).dy),
|
||||
);
|
||||
expect(browser.sort, MediaSort.nameAscending);
|
||||
final other = container.read(mediaBrowserProvider('second'));
|
||||
expect(other.query, isEmpty);
|
||||
expect(other.sort, MediaSort.importOrder);
|
||||
expect(browser.selectedAssetId, selected);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'media layouts resize columns and retain selection and dragging',
|
||||
(tester) async {
|
||||
@@ -551,7 +793,7 @@ void main() {
|
||||
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
||||
as SliverGridDelegateWithFixedCrossAxisCount)
|
||||
.crossAxisCount;
|
||||
expect(columns(), 3);
|
||||
expect(columns(), 1);
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.byType(GridView),
|
||||
@@ -598,13 +840,15 @@ void main() {
|
||||
await tester.tap(find.byTooltip('宫格布局'));
|
||||
await tester.pumpAndSettle();
|
||||
for (final (width, count) in [
|
||||
(180.0, 2),
|
||||
(280.0, 3),
|
||||
(240.0, 2),
|
||||
(360.0, 3),
|
||||
(520.0, 5),
|
||||
(560.0, 5),
|
||||
(900.0, 8),
|
||||
(120.0, 1),
|
||||
(180.0, 1),
|
||||
(220.0, 1),
|
||||
(280.0, 1),
|
||||
(240.0, 1),
|
||||
(360.0, 2),
|
||||
(520.0, 3),
|
||||
(560.0, 3),
|
||||
(900.0, 5),
|
||||
]) {
|
||||
await tester.binding.setSurfaceSize(Size(width, 600));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -618,7 +862,7 @@ void main() {
|
||||
padding.horizontal -
|
||||
delegate.crossAxisSpacing * (count - 1)) /
|
||||
count;
|
||||
expect(tileWidth, lessThanOrEqualTo(120));
|
||||
expect(tileWidth, greaterThanOrEqualTo(width < 184 ? width - 24 : 160));
|
||||
expect(tester.takeException(), isNull);
|
||||
}
|
||||
expect(
|
||||
@@ -633,10 +877,223 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('thumbnail size is project-specific and retains selection', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.binding.setSurfaceSize(const Size(720, 500));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
for (var i = 0; i < 20; i++) ExternalMediaFile(path: '/asset-$i.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
browser.selectedAssetId = '/asset-0.txt';
|
||||
int columns() =>
|
||||
(tester.widget<GridView>(find.byType(GridView)).gridDelegate
|
||||
as SliverGridDelegateWithFixedCrossAxisCount)
|
||||
.crossAxisCount;
|
||||
expect(columns(), 4);
|
||||
for (final (size, count) in [
|
||||
(MediaGridSize.small, 5),
|
||||
(MediaGridSize.large, 3),
|
||||
(MediaGridSize.medium, 4),
|
||||
]) {
|
||||
await tester.tap(find.byKey(const Key('media-size-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(ValueKey('media-size-${size.name}')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(browser.gridSize, size);
|
||||
expect(columns(), count);
|
||||
expect(browser.selectedAssetId, '/asset-0.txt');
|
||||
}
|
||||
expect(
|
||||
container.read(mediaBrowserProvider('second')).gridSize,
|
||||
MediaGridSize.medium,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'narrow toolbar preserves search space and exposes density in its menu',
|
||||
(tester) async {
|
||||
await tester.binding.setSurfaceSize(const Size(280, 600));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-panel-header'))).height,
|
||||
76,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byKey(const Key('media-search'))).width,
|
||||
greaterThan(160),
|
||||
);
|
||||
expect(find.byKey(const Key('media-sort-button')), findsNothing);
|
||||
expect(find.byKey(const Key('media-size-button')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('media-category-button')));
|
||||
await tester.pumpAndSettle();
|
||||
final size = find.byKey(const ValueKey('media-size-small'));
|
||||
await tester.ensureVisible(size);
|
||||
await tester.tap(size);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
container.read(mediaBrowserProvider('project')).gridSize,
|
||||
MediaGridSize.small,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'view and density changes preserve the first visible asset before settling',
|
||||
(tester) async {
|
||||
await tester.binding.setSurfaceSize(const Size(720, 500));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
await (container.read(
|
||||
projectsProvider.notifier,
|
||||
) as _Projects).importExternalMedia('project', [
|
||||
for (var i = 0; i < 120; i++) ExternalMediaFile(path: '/asset-$i.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.drag(find.byType(GridView), const Offset(0, -650));
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
final anchor = browser.viewportAnchor!;
|
||||
expect(anchor.assetId, isNot('/asset-0.txt'));
|
||||
browser.selectedAssetId = anchor.assetId;
|
||||
browser.grid = false;
|
||||
await tester.pump();
|
||||
final selected = find.byKey(ValueKey(anchor.assetId));
|
||||
final firstRect = tester.getRect(selected);
|
||||
expect(firstRect.overlaps(tester.getRect(find.byType(ListView))), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(selected), firstRect);
|
||||
browser.grid = true;
|
||||
browser.gridSize = MediaGridSize.large;
|
||||
await tester.pump();
|
||||
final gridRect = tester.getRect(selected);
|
||||
expect(gridRect.overlaps(tester.getRect(find.byType(GridView))), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(selected), gridRect);
|
||||
expect(browser.selectedAssetId, anchor.assetId);
|
||||
await tester.binding.setSurfaceSize(const Size(560, 500));
|
||||
await tester.pump();
|
||||
final resized = tester.getRect(selected);
|
||||
expect(resized.overlaps(tester.getRect(find.byType(GridView))), isTrue);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.getRect(selected), resized);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('empty search and panel remount retain the browse anchor', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.binding.setSurfaceSize(const Size(720, 500));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
await (container.read(
|
||||
projectsProvider.notifier,
|
||||
) as _Projects).importExternalMedia('project', [
|
||||
for (var i = 0; i < 120; i++) ExternalMediaFile(path: '/asset-$i.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.drag(find.byType(GridView), const Offset(0, -650));
|
||||
await tester.pumpAndSettle();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
final anchor = browser.viewportAnchor!;
|
||||
final tile = find.byKey(ValueKey(anchor.assetId));
|
||||
final original = tester.getRect(tile);
|
||||
browser.query = 'no matching assets';
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(GridView), findsNothing);
|
||||
browser.query = '';
|
||||
await tester.pump();
|
||||
expect(tester.getRect(tile), original);
|
||||
await tester.pumpAndSettle();
|
||||
final root = tester.widget(find.byType(UncontrolledProviderScope));
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pumpWidget(root);
|
||||
await tester.pump();
|
||||
expect(tester.getRect(tile), original);
|
||||
expect(browser.viewportAnchor, anchor);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('bottom browse position is clamped before the first frame', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.binding.setSurfaceSize(const Size(720, 500));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
final container = await mount(tester);
|
||||
await (container.read(
|
||||
projectsProvider.notifier,
|
||||
) as _Projects).importExternalMedia('project', [
|
||||
for (var i = 0; i < 121; i++) ExternalMediaFile(path: '/asset-$i.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
ScrollPosition position() =>
|
||||
tester.state<ScrollableState>(find.byType(Scrollable).last).position;
|
||||
position().jumpTo(position().maxScrollExtent);
|
||||
await tester.pump();
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
for (final size in [MediaGridSize.small, MediaGridSize.large]) {
|
||||
final anchor = browser.viewportAnchor!;
|
||||
browser.gridSize = size;
|
||||
await tester.pump();
|
||||
final firstOffset = position().pixels;
|
||||
expect(firstOffset, lessThanOrEqualTo(position().maxScrollExtent));
|
||||
await tester.pumpAndSettle();
|
||||
expect(position().pixels, firstOffset);
|
||||
expect(
|
||||
tester
|
||||
.getRect(find.byKey(ValueKey(anchor.assetId)))
|
||||
.overlaps(tester.getRect(find.byType(GridView))),
|
||||
isTrue,
|
||||
);
|
||||
position().jumpTo(position().maxScrollExtent);
|
||||
await tester.pump();
|
||||
}
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('desktop density does not change touch-page geometry', (
|
||||
tester,
|
||||
) async {
|
||||
final container = await mount(tester, touch: true);
|
||||
await (container.read(projectsProvider.notifier) as _Projects)
|
||||
.importExternalMedia('project', [
|
||||
const ExternalMediaFile(path: '/asset.txt'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
final grid = tester.widget<GridView>(find.byType(GridView));
|
||||
final delegate =
|
||||
grid.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
|
||||
final element = tester.element(find.byType(GridView));
|
||||
final tileRect = tester.getRect(find.byKey(const ValueKey('/asset.txt')));
|
||||
container.read(mediaBrowserProvider('project')).gridSize =
|
||||
MediaGridSize.large;
|
||||
await tester.pump();
|
||||
final updated = tester.widget<GridView>(find.byType(GridView));
|
||||
final updatedDelegate =
|
||||
updated.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount;
|
||||
expect(tester.element(find.byType(GridView)), same(element));
|
||||
expect(updated.controller, same(grid.controller));
|
||||
expect(updatedDelegate.crossAxisCount, delegate.crossAxisCount);
|
||||
expect(updatedDelegate.mainAxisExtent, delegate.mainAxisExtent);
|
||||
expect(updatedDelegate.childAspectRatio, delegate.childAspectRatio);
|
||||
expect(tester.getRect(find.byKey(const ValueKey('/asset.txt'))), tileRect);
|
||||
expect(tester.takeException(), isNull);
|
||||
}, variant: TargetPlatformVariant.only(TargetPlatform.android));
|
||||
|
||||
testWidgets('native file event imports real paths without a success prompt', (
|
||||
tester,
|
||||
) async {
|
||||
final container = await mount(tester);
|
||||
container.read(mediaBrowserProvider('project')).query = 'no match';
|
||||
await tester.pumpAndSettle();
|
||||
final target = tester.getCenter(find.byType(NativeProjectDropRegion));
|
||||
await platformEvent(tester, 'enter', [target.dx, target.dy]);
|
||||
expect(find.byKey(const Key('media-drop-highlight')), findsOneWidget);
|
||||
@@ -662,6 +1119,7 @@ void main() {
|
||||
'/originals/中文 视频.flv',
|
||||
]);
|
||||
expect(find.text('video.mp4'), findsOneWidget);
|
||||
expect(container.read(mediaBrowserProvider('project')).query, isEmpty);
|
||||
expect(find.text('中文 视频.RMVB'), findsOneWidget);
|
||||
expect(find.text('中文 视频.flv'), findsOneWidget);
|
||||
expect(find.byType(SnackBar), findsNothing);
|
||||
@@ -680,6 +1138,9 @@ void main() {
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('second.wav'));
|
||||
final browser = container.read(mediaBrowserProvider('project'));
|
||||
browser.query = ' FIRST ';
|
||||
await tester.pumpAndSettle();
|
||||
await platformEvent(tester, 'enter', [0.0, 0.0]);
|
||||
await platformEvent(tester, 'drop', ['/originals/first.mp4']);
|
||||
await tester.pumpAndSettle();
|
||||
@@ -691,6 +1152,7 @@ void main() {
|
||||
container.read(projectsProvider).requireValue.assets,
|
||||
hasLength(2),
|
||||
);
|
||||
expect(browser.query, ' FIRST ');
|
||||
expect(
|
||||
find.ancestor(
|
||||
of: find.text('first.mp4'),
|
||||
@@ -831,7 +1293,7 @@ void main() {
|
||||
const ExternalMediaFile(path: '/originals/bad.wav'),
|
||||
]);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byIcon(Icons.audio_file_outlined), findsOneWidget);
|
||||
expect(find.byIcon(AppIcons.audioFile), findsOneWidget);
|
||||
final before = tester.getSize(
|
||||
find.byKey(const ValueKey('audio-cover-/originals/bad.wav')),
|
||||
);
|
||||
@@ -966,6 +1428,8 @@ class _Projects extends Projects {
|
||||
);
|
||||
@visibleForTesting
|
||||
List<ExternalMediaFile> received = [];
|
||||
@visibleForTesting
|
||||
Future<void>? importGate;
|
||||
@override
|
||||
Future<ProjectState> build() async => const ProjectState(
|
||||
activeProject: RecentProject(
|
||||
@@ -994,6 +1458,7 @@ class _Projects extends Projects {
|
||||
List<ExternalMediaFile> files, {
|
||||
bool Function()? isCancelled,
|
||||
}) async {
|
||||
await importGate;
|
||||
received = files;
|
||||
final previous = state.requireValue.assets;
|
||||
final previousIds = {for (final asset in previous) asset.id};
|
||||
|
||||
Reference in new issue
Block a user