Merge remote-tracking branch 'origin/main' into ci/gitea-parallel-build-retries
This commit is contained in:
commit
e9d04bea2c
93 files changed
+5812
-2651
No files matched your search
@@ -22,7 +22,6 @@ import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/integrations/platform/device_experience.dart';
|
||||
import 'package:cutdex/persistence/app_database.dart';
|
||||
import 'package:cutdex/persistence/app_settings_repositories.dart';
|
||||
import 'package:cutdex/shared/layout/workspace_layout_metrics.dart';
|
||||
import 'package:cutdex/workspace/media_availability.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
@@ -139,6 +138,48 @@ void main() {
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'desktop navigation switches sidebar content and retains workspace',
|
||||
(tester) async {
|
||||
final mounted = await mount(tester, const Size(1200, 800));
|
||||
final headerToggle = find.byKey(const Key('project-sidebar-toggle'));
|
||||
final headerTasks = find.byKey(const ValueKey('background-tasks-button'));
|
||||
expect(tester.getSize(headerToggle), const Size.square(28));
|
||||
expect(tester.getSize(headerTasks), const Size.square(28));
|
||||
expect(
|
||||
tester.getRect(headerToggle).center.dx,
|
||||
tester.getRect(find.byKey(const Key('desktop-rail-cut'))).center.dx,
|
||||
);
|
||||
expect(
|
||||
tester.getRect(headerTasks).center.dx -
|
||||
tester.getRect(headerToggle).center.dx,
|
||||
32,
|
||||
);
|
||||
expect(find.byKey(const Key('desktop-rail-agent')), findsNothing);
|
||||
expect(find.byKey(const Key('desktop-rail-cut')), findsOneWidget);
|
||||
final library = find.byKey(const Key('desktop-rail-library'));
|
||||
final editorElement = tester.element(find.byType(EditorWorkspace));
|
||||
await tester.tap(library);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('desktop-library-workspace')), findsNothing);
|
||||
expect(find.byType(EditorWorkspace), findsOneWidget);
|
||||
expect(
|
||||
tester.element(find.byType(EditorWorkspace, skipOffstage: false)),
|
||||
same(editorElement),
|
||||
);
|
||||
expect(find.byType(MediaPanel), findsOneWidget);
|
||||
expect(tester.widget<IconButton>(library).isSelected, isTrue);
|
||||
expect(find.byKey(const Key('project-settings-button')), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('desktop-rail-cut')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('desktop-library-workspace')), findsNothing);
|
||||
expect(tester.element(find.byType(EditorWorkspace)), same(editorElement));
|
||||
expect(find.byType(MediaPanel), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
await mounted.close();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('Windows caption space follows real workspace pane changes', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -160,14 +201,29 @@ void main() {
|
||||
messenger.setMockMethodCallHandler(dropChannel, null);
|
||||
});
|
||||
final mounted = await mount(tester, const Size(1200, 800));
|
||||
final contentRect = tester.getRect(
|
||||
find.byKey(const Key('desktop-content-container')),
|
||||
);
|
||||
expect(
|
||||
contentRect.top,
|
||||
tester.getRect(find.byKey(const Key('desktop-window-header'))).bottom,
|
||||
);
|
||||
expect(
|
||||
contentRect.left,
|
||||
tester.getRect(find.byKey(const Key('desktop-navigation-rail'))).right,
|
||||
);
|
||||
expect(contentRect.right, 1199);
|
||||
expect(contentRect.bottom, 799);
|
||||
for (final mode in [WorkspaceMode.agent, WorkspaceMode.cut]) {
|
||||
await setMode(tester, mounted.container, mode);
|
||||
for (final width in [1200.0, 700.0, 400.0, 1200.0]) {
|
||||
tester.view.physicalSize = Size(width, 800);
|
||||
await tester.pumpAndSettle();
|
||||
final controlsLeft = tester
|
||||
.getTopLeft(find.byKey(const Key('window-minimize')))
|
||||
.dx;
|
||||
final captionRect = tester
|
||||
.getRect(find.byKey(const Key('window-minimize')))
|
||||
.expandToInclude(
|
||||
tester.getRect(find.byKey(const Key('window-close'))),
|
||||
);
|
||||
for (final key in [
|
||||
'editor-media-button',
|
||||
'editor-properties-button',
|
||||
@@ -191,8 +247,8 @@ void main() {
|
||||
});
|
||||
if (rect.isEmpty) continue;
|
||||
expect(
|
||||
rect.right,
|
||||
lessThanOrEqualTo(controlsLeft + 0.1),
|
||||
rect.overlaps(captionRect),
|
||||
isFalse,
|
||||
reason: '$key at $width in $mode',
|
||||
);
|
||||
}
|
||||
@@ -285,69 +341,45 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'desktop tools overlay in limited editor space and restore fixed sidebars',
|
||||
(tester) async {
|
||||
final mounted = await mount(tester, const Size(1200, 800));
|
||||
await setMode(tester, mounted.container, WorkspaceMode.cut);
|
||||
await tester.tap(find.byKey(const Key('editor-media-button')));
|
||||
await tester.tap(find.byKey(const Key('editor-properties-button')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.getSize(find.byType(MediaPanel)).width,
|
||||
WorkspaceLayoutMetrics.mediaPanelWidth,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byType(EditorPropertiesPanel)).width,
|
||||
WorkspaceLayoutMetrics.propertiesPanelWidth,
|
||||
);
|
||||
expect(find.byKey(const Key('editor-tool-surface')), findsNothing);
|
||||
|
||||
await setMode(tester, mounted.container, WorkspaceMode.agent);
|
||||
expect(find.byKey(const Key('editor-tool-surface')), findsOneWidget);
|
||||
expect(find.byType(EditorPropertiesPanel), findsOneWidget);
|
||||
expect(find.byType(PropertiesEditorPage), findsNothing);
|
||||
expect(find.byType(EditorTimelinePanel), findsOneWidget);
|
||||
expect(
|
||||
mounted.container
|
||||
.read(projectViewSettingsProvider(mounted.projectId))
|
||||
.requireValue
|
||||
.propertiesOpen,
|
||||
isTrue,
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('editor-media-button')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(MediaPanel), findsOneWidget);
|
||||
|
||||
expect(find.byType(MediaBrowserDrawer), findsNothing);
|
||||
expect(find.byType(PropertiesToolPanel), findsNothing);
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(find.byKey(const Key('editor-media-button')))
|
||||
.isSelected,
|
||||
isTrue,
|
||||
);
|
||||
await setMode(tester, mounted.container, WorkspaceMode.cut);
|
||||
expect(find.byKey(const Key('editor-tool-surface')), findsNothing);
|
||||
expect(
|
||||
tester.getSize(find.byType(MediaPanel)).width,
|
||||
WorkspaceLayoutMetrics.mediaPanelWidth,
|
||||
);
|
||||
expect(
|
||||
tester.getSize(find.byType(EditorPropertiesPanel)).width,
|
||||
WorkspaceLayoutMetrics.propertiesPanelWidth,
|
||||
);
|
||||
expect(
|
||||
await mounted.container.read(
|
||||
editorTimelineProvider(mounted.projectId, 'project').future,
|
||||
),
|
||||
same(mounted.session),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
await mounted.close();
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('desktop resources retain state across navigation switches', (
|
||||
tester,
|
||||
) async {
|
||||
final mounted = await mount(tester, const Size(1800, 800));
|
||||
await setMode(tester, mounted.container, WorkspaceMode.cut);
|
||||
expect(find.byKey(const Key('editor-media-button')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('desktop-rail-library')));
|
||||
await tester.pumpAndSettle();
|
||||
final mediaElement = tester.element(find.byType(MediaPanel));
|
||||
expect(
|
||||
tester
|
||||
.getRect(find.byKey(const Key('desktop-project-card')))
|
||||
.contains(tester.getRect(find.byType(MediaPanel)).center),
|
||||
isTrue,
|
||||
);
|
||||
final browser = mounted.container.read(
|
||||
mediaBrowserProvider(mounted.projectId),
|
||||
);
|
||||
browser.filter = MediaFilter.image;
|
||||
browser.selectedAssetId = 'media';
|
||||
await tester.tap(find.byKey(const Key('desktop-rail-cut')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(MediaPanel), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('desktop-rail-library')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.element(find.byType(MediaPanel)), same(mediaElement));
|
||||
expect(browser.filter, MediaFilter.image);
|
||||
expect(browser.selectedAssetId, 'media');
|
||||
expect(find.byKey(const Key('sidebar-tab-resources')), findsNothing);
|
||||
expect(find.byType(EditorWorkspace), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('desktop-rail-cut')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('editor-properties-button')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(EditorPropertiesPanel), findsOneWidget);
|
||||
expect(find.byKey(const Key('editor-media-region')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
await mounted.close();
|
||||
});
|
||||
testWidgets(
|
||||
'phone tools use independent pages without changing desktop preferences',
|
||||
(tester) async {
|
||||
@@ -449,7 +481,15 @@ void main() {
|
||||
experience: experience,
|
||||
);
|
||||
await setMode(tester, mounted.container, WorkspaceMode.cut);
|
||||
await tester.tap(find.byKey(const Key('editor-media-button')));
|
||||
await tester.tap(
|
||||
find.byKey(
|
||||
Key(
|
||||
experience == DeviceExperience.desktop
|
||||
? 'desktop-rail-library'
|
||||
: 'editor-media-button',
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
final browser = mounted.container.read(
|
||||
mediaBrowserProvider(mounted.projectId),
|
||||
@@ -463,8 +503,19 @@ void main() {
|
||||
]) {
|
||||
tester.view.physicalSize = size;
|
||||
await tester.pumpAndSettle();
|
||||
if (experience == DeviceExperience.desktop) {
|
||||
if (size.width < 700) {
|
||||
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
await tester.tap(find.byKey(const Key('desktop-rail-library')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
expect(
|
||||
find.byKey(Key('${experience.name}-workspace-shell')),
|
||||
find.byKey(
|
||||
Key('${experience.name}-workspace-shell'),
|
||||
skipOffstage: false,
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(
|
||||
@@ -506,7 +557,10 @@ void main() {
|
||||
);
|
||||
if (experience == DeviceExperience.desktop) {
|
||||
expect(
|
||||
find.byKey(const Key('editor-timeline-resize')),
|
||||
find.byKey(
|
||||
const Key('editor-timeline-resize'),
|
||||
skipOffstage: false,
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
}
|
||||
@@ -517,6 +571,10 @@ void main() {
|
||||
expect(browser.filter, MediaFilter.image);
|
||||
expect(browser.selectedAssetId, 'media');
|
||||
expect(tester.takeException(), isNull);
|
||||
if (experience == DeviceExperience.desktop && size.width < 700) {
|
||||
Scaffold.of(tester.element(find.byType(MediaPanel))).closeDrawer();
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
await mounted.close();
|
||||
},
|
||||
@@ -957,14 +1015,17 @@ void main() {
|
||||
}
|
||||
resolver.gate.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(SnackBar), findsNothing);
|
||||
expect(find.byKey(const Key('global-error-notification')), findsNothing);
|
||||
if (target == 'media') {
|
||||
await tester.tap(find.byKey(const Key('editor-media-button')));
|
||||
await tester.pumpAndSettle();
|
||||
} else {
|
||||
await setMode(tester, mounted.container, WorkspaceMode.agent);
|
||||
}
|
||||
expect(find.byType(SnackBar), findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('global-error-notification')),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('bad.mov:'), findsOneWidget);
|
||||
final feedback = target == 'media'
|
||||
? mounted.container
|
||||
@@ -980,8 +1041,7 @@ void main() {
|
||||
)
|
||||
.feedback;
|
||||
expect(feedback.hasPending, isFalse);
|
||||
ScaffoldMessenger.of(tester.element(find.byType(SnackBar)))
|
||||
.removeCurrentSnackBar();
|
||||
await tester.tap(find.byKey(const Key('close-error-button')));
|
||||
await tester.pumpAndSettle();
|
||||
await setMode(tester, mounted.container, WorkspaceMode.cut);
|
||||
await setMode(tester, mounted.container, WorkspaceMode.agent);
|
||||
@@ -990,7 +1050,7 @@ void main() {
|
||||
await tester.tap(find.byKey(const Key('editor-media-button')));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
expect(find.byType(SnackBar), findsNothing);
|
||||
expect(find.byKey(const Key('global-error-notification')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -1002,14 +1062,9 @@ void main() {
|
||||
expect(find.byKey(const Key('desktop-workspace-shell')), findsOneWidget);
|
||||
expect(find.byKey(const Key('agent-panel-resize')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
tester.view.physicalSize = const Size(240, 800);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('agent-panel-resize')), findsOneWidget);
|
||||
await tester.drag(
|
||||
find.byKey(const Key('agent-panel-resize')),
|
||||
const Offset(-20, 0),
|
||||
);
|
||||
tester.view.physicalSize = const Size(308, 800);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('agent-panel-resize')), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
tester.view.physicalSize = const Size(200, 800);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:cutdex/features/settings/settings_page.dart';
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
|
||||
import 'dart:io';
|
||||
@@ -110,14 +113,11 @@ void main() {
|
||||
Future<void> panel(WidgetTester tester, {String? conversationId}) async {
|
||||
await tester.binding.setSurfaceSize(const Size(1000, 760));
|
||||
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: EditorTheme.penDark,
|
||||
home: Scaffold(
|
||||
final router = GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => Scaffold(
|
||||
body: SizedBox(
|
||||
width: 360,
|
||||
child: AgentChatPanel(
|
||||
@@ -128,6 +128,25 @@ void main() {
|
||||
),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/settings',
|
||||
builder: (context, state) => SettingsPage(
|
||||
initialTab: int.parse(state.uri.queryParameters['tab'] ?? '0'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
addTearDown(router.dispose);
|
||||
await tester.pumpWidget(
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp.router(
|
||||
routerConfig: router,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: EditorTheme.penDark,
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
import 'package:cutdex/app/adaptive/desktop_workspace_controller.dart';
|
||||
import 'package:cutdex/app/shells/desktop_workspace_shell.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex/features/editor/layouts/expanded_editor_layout.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'properties divider spans the preview card including its header',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(1000, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
var showProperties = true;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return ExpandedEditorLayout(
|
||||
preview: const SizedBox.expand(key: Key('test-preview')),
|
||||
header: const SizedBox(height: 40, key: Key('test-header')),
|
||||
properties: const SizedBox.expand(),
|
||||
media: const SizedBox(),
|
||||
showMedia: false,
|
||||
showProperties: showProperties,
|
||||
timelineHeight: 200,
|
||||
onTimelineHeightChanged: (_) {},
|
||||
onTimelineHeightChangeEnd: () {},
|
||||
timeline: const SizedBox(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
final card = tester.getRect(find.byKey(const Key('editor-preview-card')));
|
||||
final divider = tester.getRect(
|
||||
find.byKey(const Key('editor-properties-divider')),
|
||||
);
|
||||
final properties = tester.getRect(
|
||||
find.byKey(const Key('editor-properties-region')),
|
||||
);
|
||||
final header = tester.getRect(find.byKey(const Key('test-header')));
|
||||
expect(divider.top, card.top + 1);
|
||||
expect(divider.bottom, card.bottom - 1);
|
||||
expect(properties.top, divider.top);
|
||||
expect(properties.bottom, divider.bottom);
|
||||
expect(header.right, divider.left);
|
||||
expect(properties.left, divider.right);
|
||||
final preview = tester.element(find.byKey(const Key('test-preview')));
|
||||
update(() => showProperties = false);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('editor-properties-divider')), findsNothing);
|
||||
expect(
|
||||
tester.getRect(find.byKey(const Key('test-header'))).right,
|
||||
card.right - 1,
|
||||
);
|
||||
expect(
|
||||
tester.element(find.byKey(const Key('test-preview'))),
|
||||
same(preview),
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
testWidgets('preview and timeline cards resize through their 1 dp gap', (
|
||||
tester,
|
||||
) async {
|
||||
tester.view.physicalSize = const Size(700, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
double? timelineHeight;
|
||||
var saves = 0;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, update) => ExpandedEditorLayout(
|
||||
preview: const Text('Preview'),
|
||||
header: const SizedBox(height: 46, child: Text('Preview controls')),
|
||||
properties: const SizedBox(),
|
||||
media: const SizedBox(),
|
||||
showMedia: false,
|
||||
showProperties: false,
|
||||
timelineHeight: timelineHeight,
|
||||
onTimelineHeightChanged: (value) =>
|
||||
update(() => timelineHeight = value),
|
||||
onTimelineHeightChangeEnd: () => saves++,
|
||||
timeline: const Column(
|
||||
children: [
|
||||
Text('Toolbar'),
|
||||
Expanded(child: Text('Timeline')),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
Rect card(String name) =>
|
||||
tester.getRect(find.byKey(Key('editor-$name-card')));
|
||||
final timelineBefore = card('timeline');
|
||||
expect(timelineBefore.top - card('preview').bottom, 1);
|
||||
final resize = find.byKey(const Key('editor-timeline-resize'));
|
||||
expect(tester.getSize(resize).height, 5);
|
||||
expect(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('editor-timeline-card')),
|
||||
matching: find.text('Toolbar'),
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(resize) + const Offset(0, -2),
|
||||
const Offset(0, -80),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('timeline').height, timelineBefore.height + 80);
|
||||
expect(card('timeline').top - card('preview').bottom, 1);
|
||||
expect(saves, 1);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(resize) + const Offset(0, 2),
|
||||
const Offset(0, 20),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('timeline').height, timelineBefore.height + 60);
|
||||
expect(saves, 2);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(resize) + const Offset(0, 3),
|
||||
const Offset(0, -30),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('timeline').height, timelineBefore.height + 60);
|
||||
expect(saves, 2);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets(
|
||||
'desktop cards keep their order and resize through both gutters',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(1600, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final controller = DesktopWorkspaceController();
|
||||
addTearDown(controller.dispose);
|
||||
double sidebarWidth = 260;
|
||||
var mode = WorkspaceMode.agent;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return DesktopWorkspaceShell(
|
||||
mode: mode,
|
||||
controller: controller,
|
||||
sidebarCollapsed: false,
|
||||
sidebarWidth: sidebarWidth,
|
||||
onSidebarCollapsedChanged: (_) {},
|
||||
onSidebarWidthChanged: (value) =>
|
||||
setState(() => sidebarWidth = value),
|
||||
sidebarBuilder: (_, _) => const Text('Projects'),
|
||||
agentBuilder: (_, _) => const Text('Agent'),
|
||||
editor: const Text('Editor'),
|
||||
scaffoldKey: GlobalKey<ScaffoldState>(),
|
||||
navigationDrawer: const SizedBox(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
Rect card(String name) =>
|
||||
tester.getRect(find.byKey(Key('desktop-$name-card')));
|
||||
final project = card('project');
|
||||
final editor = card('editor');
|
||||
final agent = card('agent');
|
||||
expect(editor.left - project.right, 1);
|
||||
expect(agent.left - editor.right, 1);
|
||||
expect(project.top, editor.top);
|
||||
expect(editor.bottom, agent.bottom);
|
||||
|
||||
final projectResize = find.byKey(const Key('project-sidebar-resize'));
|
||||
final agentResize = find.byKey(const Key('agent-panel-resize'));
|
||||
expect(tester.getSize(projectResize).width, 5);
|
||||
expect(tester.getSize(agentResize).width, 5);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(projectResize) + const Offset(-2, 0),
|
||||
const Offset(60, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('project').width, project.width + 60);
|
||||
expect(card('agent').width, agent.width);
|
||||
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(agentResize) + const Offset(2, 0),
|
||||
const Offset(-80, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('agent').width, agent.width + 80);
|
||||
expect(card('project').width, project.width + 60);
|
||||
expect(card('agent').left - card('editor').right, 1);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(projectResize) + const Offset(2, 0),
|
||||
const Offset(-20, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('project').width, project.width + 40);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(agentResize) + const Offset(-2, 0),
|
||||
const Offset(20, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('agent').width, agent.width + 60);
|
||||
await tester.dragFrom(
|
||||
tester.getCenter(projectResize) + const Offset(-3, 0),
|
||||
const Offset(30, 0),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(card('project').width, project.width + 40);
|
||||
expect(card('editor').left - card('project').right, 1);
|
||||
|
||||
update(() => mode = WorkspaceMode.cut);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('desktop-agent-card')), findsOneWidget);
|
||||
expect(card('editor').left, greaterThan(card('project').right));
|
||||
expect(card('agent').left, greaterThan(card('editor').right));
|
||||
final agentElement = tester.element(find.text('Agent'));
|
||||
await tester.drag(agentResize, const Offset(-2000, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Agent'), findsOneWidget);
|
||||
expect(tester.element(find.text('Agent')), same(agentElement));
|
||||
expect(find.text('Editor'), findsOneWidget);
|
||||
expect(card('editor').width, 480);
|
||||
expect(agentResize, findsOneWidget);
|
||||
await tester.drag(agentResize, const Offset(600, 0));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Agent'), findsOneWidget);
|
||||
expect(find.text('Editor'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
@@ -167,6 +169,7 @@ void main() {
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
theme: EditorTheme.penLight,
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
home: Scaffold(body: SizedBox(width: 800, height: 600, child: child)),
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/editor/editor_panel_defaults.dart';
|
||||
import 'package:cutdex/features/preview/preview_panel.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex_sdk/editor.dart';
|
||||
import 'package:cutdex_ui/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('pending preview uses black, zero times and default ratio', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.penLight,
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('en'),
|
||||
home: const Scaffold(
|
||||
body: EditorPreviewPanel(
|
||||
projectId: 'pending-project',
|
||||
timelineId: '',
|
||||
pending: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(find.text('00:00:00:00 / 00:00:00:00'), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.widget<ColoredBox>(find.byKey(const Key('preview-default-frame')))
|
||||
.color,
|
||||
Colors.black,
|
||||
);
|
||||
final ratio = tester.widget<AppSelect<ProjectCanvas>>(
|
||||
find.byType(AppSelect<ProjectCanvas>),
|
||||
);
|
||||
expect(ratio.value, ProjectCanvas.widescreen);
|
||||
expect(ratio.onChanged, isNull);
|
||||
final play = tester.widget<IconButton>(
|
||||
find.widgetWithIcon(IconButton, Icons.play_arrow),
|
||||
);
|
||||
expect(play.onPressed, isNull);
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('default timeline has empty content and disabled commands', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: EditorTheme.penLight,
|
||||
home: const Scaffold(body: EditorTimelineDefaults()),
|
||||
),
|
||||
);
|
||||
expect(find.byKey(const Key('timeline-default-tracks')), findsOneWidget);
|
||||
expect(find.byKey(const Key('timeline-toolbar')), findsOneWidget);
|
||||
for (final button in tester.widgetList<IconButton>(
|
||||
find.byType(IconButton),
|
||||
)) {
|
||||
expect(button.onPressed, isNull);
|
||||
}
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
Future<ErrorNotificationHostState> mount(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
home: const Scaffold(body: Text('Workspace')),
|
||||
),
|
||||
);
|
||||
return tester.state<ErrorNotificationHostState>(
|
||||
find.byType(ErrorNotificationHost),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('top error copies complete details and closes', (tester) async {
|
||||
String? copied;
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'Clipboard.setData') {
|
||||
copied = (call.arguments as Map)['text'] as String;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
null,
|
||||
),
|
||||
);
|
||||
final host = await mount(tester);
|
||||
host.showFailure(
|
||||
const AppFailure(
|
||||
AppErrorCode.resourceDownloadHttpFailed,
|
||||
httpStatusCode: 503,
|
||||
diagnostic: 'service unavailable',
|
||||
),
|
||||
'Download failed',
|
||||
);
|
||||
await tester.pump();
|
||||
final notice = find.byKey(const Key('global-error-notification'));
|
||||
expect(tester.getRect(notice).top, 48);
|
||||
expect(find.byType(SnackBar), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('copy-error-button')));
|
||||
await tester.pump();
|
||||
expect(copied, contains('Download failed'));
|
||||
expect(copied, contains('code: resourceDownloadHttpFailed'));
|
||||
expect(copied, contains('HTTP: 503'));
|
||||
expect(copied, contains('service unavailable'));
|
||||
expect(find.byIcon(Icons.check), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('close-error-button')));
|
||||
await tester.pump();
|
||||
expect(notice, findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('errors queue and pause dismissal while hovered', (tester) async {
|
||||
final host = await mount(tester);
|
||||
host.show(const ErrorNotification(content: Text('First')));
|
||||
host.show(const ErrorNotification(content: Text('Second')));
|
||||
await tester.pump();
|
||||
expect(find.text('First'), findsOneWidget);
|
||||
expect(find.text('Second'), findsNothing);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
await mouse.addPointer(location: Offset.zero);
|
||||
await mouse.moveTo(
|
||||
tester.getCenter(find.byKey(const Key('global-error-notification'))),
|
||||
);
|
||||
await tester.pump(const Duration(seconds: 9));
|
||||
expect(find.text('First'), findsOneWidget);
|
||||
await mouse.moveTo(const Offset(1, 500));
|
||||
await tester.pump(const Duration(seconds: 8));
|
||||
expect(find.text('Second'), findsOneWidget);
|
||||
await tester.pump(const Duration(seconds: 8));
|
||||
expect(find.byKey(const Key('global-error-notification')), findsNothing);
|
||||
await mouse.removePointer();
|
||||
});
|
||||
|
||||
testWidgets('error remains above an open dialog', (tester) async {
|
||||
final host = await mount(tester);
|
||||
final context = tester.element(find.text('Workspace'));
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (_) => const AlertDialog(content: Text('Dialog')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
host.show(const ErrorNotification(content: Text('Dialog error')));
|
||||
await tester.pump();
|
||||
expect(find.text('Dialog'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('close-error-button')));
|
||||
await tester.pump();
|
||||
expect(find.text('Dialog error'), findsNothing);
|
||||
expect(find.text('Dialog'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -59,6 +59,8 @@ class _Repository extends ConversationRepository {
|
||||
_Repository() : super(Directory('/unused'));
|
||||
Completer<List<ConversationMetadata>>? blocked;
|
||||
final started = Completer<void>();
|
||||
int groupReads = 0;
|
||||
Completer<List<ConversationMetadata>>? blockedTrash;
|
||||
bool fail = false;
|
||||
bool failDelete = false;
|
||||
final trashed = <ConversationMetadata>[];
|
||||
@@ -69,7 +71,8 @@ class _Repository extends ConversationRepository {
|
||||
String projectId, {
|
||||
bool trash = false,
|
||||
}) async {
|
||||
if (trash) return List.of(trashed);
|
||||
if (trash) return blockedTrash?.future ?? Future.value(List.of(trashed));
|
||||
groupReads++;
|
||||
if (fail) throw StateError('read failed');
|
||||
if (projectId == 'a' && blocked != null) {
|
||||
if (!started.isCompleted) started.complete();
|
||||
@@ -267,6 +270,29 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'project switching keeps groups visible without rereading their listings',
|
||||
() async {
|
||||
final initial = container.read(conversationSidebarProvider).requireValue;
|
||||
final reads = repository.groupReads;
|
||||
repository.blockedTrash = Completer();
|
||||
(container.read(projectsProvider.notifier) as _Projects).selectProject(1);
|
||||
await container.pump();
|
||||
final switching = container.read(conversationSidebarProvider);
|
||||
expect(switching.isLoading, isFalse);
|
||||
expect(switching.requireValue.groups['a'], same(initial.groups['a']));
|
||||
expect(switching.requireValue.groups['b'], same(initial.groups['b']));
|
||||
expect(repository.groupReads, reads);
|
||||
repository.blockedTrash!.complete([]);
|
||||
await container.pump();
|
||||
expect(
|
||||
container.read(conversationSidebarProvider).requireValue.projectId,
|
||||
'b',
|
||||
);
|
||||
expect(repository.groupReads, reads);
|
||||
},
|
||||
);
|
||||
|
||||
test('reopening a project reloads its saved selection', () async {
|
||||
final provider = conversationSelectionProvider('a');
|
||||
container.listen(provider, (_, _) {});
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:cutdex/shared/widgets/listenable_selector.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('selection ignores unrelated events and detaches old sources', (
|
||||
tester,
|
||||
) async {
|
||||
final first = _Source((time: 0, playing: false));
|
||||
final second = _Source((time: 0, playing: true));
|
||||
addTearDown(first.dispose);
|
||||
addTearDown(second.dispose);
|
||||
var builds = 0;
|
||||
Widget region(ValueNotifier<({int time, bool playing})> source) =>
|
||||
Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: ListenableSelector(
|
||||
listenable: source,
|
||||
select: () => source.value.playing,
|
||||
builder: (context, playing) {
|
||||
builds++;
|
||||
return Text('$playing');
|
||||
},
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(region(first));
|
||||
final initial = builds;
|
||||
first.value = (time: 1, playing: false);
|
||||
await tester.pump();
|
||||
expect(builds, initial);
|
||||
first.value = (time: 1, playing: true);
|
||||
await tester.pump();
|
||||
expect(builds, initial + 1);
|
||||
await tester.pumpWidget(region(second));
|
||||
expect(first.subscribed, isFalse);
|
||||
expect(second.subscribed, isTrue);
|
||||
second.value = (time: 2, playing: false);
|
||||
await tester.pump();
|
||||
expect(find.text('false'), findsOneWidget);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
expect(second.subscribed, isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
class _Source extends ValueNotifier<({int time, bool playing})> {
|
||||
_Source(super.value);
|
||||
bool get subscribed => hasListeners;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex/features/media/media_browser_feedback.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/external_media_import.dart';
|
||||
@@ -15,6 +16,7 @@ void main() {
|
||||
late StateSetter changeVisibility;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
home: Scaffold(
|
||||
@@ -42,26 +44,32 @@ void main() {
|
||||
feedback.recordFailure();
|
||||
await tester.pumpAndSettle();
|
||||
expect(feedback.hasPending, isTrue);
|
||||
expect(find.byType(SnackBar), findsNothing);
|
||||
expect(find.byKey(const Key('global-error-notification')), findsNothing);
|
||||
changeVisibility(() => visible = true);
|
||||
await tester.pumpAndSettle();
|
||||
expect(feedback.hasPending, isFalse);
|
||||
expect(find.byType(SnackBar), findsOneWidget);
|
||||
final messenger = ScaffoldMessenger.of(
|
||||
expect(
|
||||
find.byKey(const Key('global-error-notification')),
|
||||
findsOneWidget,
|
||||
);
|
||||
final messenger = ErrorNotificationHost.of(
|
||||
tester.element(find.text('Browser')),
|
||||
);
|
||||
messenger.clearSnackBars();
|
||||
messenger.removeCurrentSnackBar();
|
||||
messenger.clear();
|
||||
|
||||
await tester.pumpAndSettle();
|
||||
changeVisibility(() => visible = false);
|
||||
await tester.pumpAndSettle();
|
||||
changeVisibility(() => visible = true);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(SnackBar), findsNothing);
|
||||
expect(find.byKey(const Key('global-error-notification')), findsNothing);
|
||||
feedback.recordFailure();
|
||||
await tester.pumpAndSettle();
|
||||
expect(feedback.hasPending, isFalse);
|
||||
expect(find.byType(SnackBar), findsOneWidget);
|
||||
expect(
|
||||
find.byKey(const Key('global-error-notification')),
|
||||
findsOneWidget,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
+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));
|
||||
}
|
||||
|
||||
@@ -349,6 +349,8 @@ void main() {
|
||||
return pending.future;
|
||||
});
|
||||
final loadingRect = tester.getRect(toolbar);
|
||||
expect(find.byKey(const Key('preview-default-frame')), findsOneWidget);
|
||||
expect(find.byType(CircularProgressIndicator), findsNothing);
|
||||
expect(find.text('00:00:00:00 / 00:00:00:00'), findsOneWidget);
|
||||
expect(tester.widget<IconButton>(playButton).onPressed, isNull);
|
||||
pending.completeError(StateError('unavailable'));
|
||||
@@ -408,6 +410,76 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('clock and playback update only their own preview regions', (
|
||||
tester,
|
||||
) async {
|
||||
final preview = _Preview();
|
||||
addTearDown(preview.dispose);
|
||||
await mount(tester, () async => preview);
|
||||
await tester.pumpAndSettle();
|
||||
final canvasBefore = tester.widget<PreviewCanvas>(
|
||||
find.byType(PreviewCanvas),
|
||||
);
|
||||
final toolbarBefore = tester.widget(toolbar);
|
||||
final playBefore = tester.widget<IconButton>(playButton);
|
||||
final ratioBefore = tester.widget<AppSelect<ProjectCanvas>>(
|
||||
find.byType(AppSelect<ProjectCanvas>),
|
||||
);
|
||||
final timeFinder = find.descendant(
|
||||
of: find.byKey(const Key('preview-time')),
|
||||
matching: find.byType(Text),
|
||||
);
|
||||
final timeBefore = tester.widget<Text>(timeFinder);
|
||||
|
||||
preview.moveTo(TimelineClock.ticksPerSecond);
|
||||
await tester.pump();
|
||||
expect(find.text('00:00:01:00 / 02:00:00:00'), findsOneWidget);
|
||||
expect(tester.widget(toolbar), same(toolbarBefore));
|
||||
expect(
|
||||
tester.widget<PreviewCanvas>(find.byType(PreviewCanvas)),
|
||||
same(canvasBefore),
|
||||
);
|
||||
expect(tester.widget<IconButton>(playButton), same(playBefore));
|
||||
expect(
|
||||
tester.widget<AppSelect<ProjectCanvas>>(
|
||||
find.byType(AppSelect<ProjectCanvas>),
|
||||
),
|
||||
same(ratioBefore),
|
||||
);
|
||||
expect(tester.widget<Text>(timeFinder), isNot(same(timeBefore)));
|
||||
final timeAfterSeek = tester.widget<Text>(timeFinder);
|
||||
|
||||
await preview.togglePlayback();
|
||||
await tester.pump();
|
||||
expect(find.byIcon(Icons.pause), findsOneWidget);
|
||||
expect(tester.widget(toolbar), same(toolbarBefore));
|
||||
expect(
|
||||
tester.widget<PreviewCanvas>(find.byType(PreviewCanvas)),
|
||||
same(canvasBefore),
|
||||
);
|
||||
expect(tester.widget<Text>(timeFinder), same(timeAfterSeek));
|
||||
expect(
|
||||
tester.widget<AppSelect<ProjectCanvas>>(
|
||||
find.byType(AppSelect<ProjectCanvas>),
|
||||
),
|
||||
same(ratioBefore),
|
||||
);
|
||||
|
||||
preview.setCanvas(
|
||||
ProjectCanvasPresets.values.values.firstWhere(
|
||||
(value) => value != preview.canvas,
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(tester.widget(toolbar), same(toolbarBefore));
|
||||
expect(tester.widget<Text>(timeFinder), same(timeAfterSeek));
|
||||
expect(
|
||||
tester.widget<PreviewCanvas>(find.byType(PreviewCanvas)),
|
||||
isNot(same(canvasBefore)),
|
||||
);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('offline media keeps playback available with a local notice', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:cutdex/shared/widgets/error_notification_host.dart';
|
||||
import 'package:cutdex/errors/app_failure.dart';
|
||||
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
@@ -523,6 +524,7 @@ void main() {
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp.router(
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
@@ -584,6 +586,7 @@ void main() {
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp.router(
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
@@ -638,6 +641,7 @@ void main() {
|
||||
UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp.router(
|
||||
builder: (context, child) => ErrorNotificationHost(child: child!),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
@@ -652,10 +656,7 @@ void main() {
|
||||
expect(tester.getTopRight(find.byIcon(Icons.close)).dx, lessThan(1200));
|
||||
await tester.tap(find.byIcon(Icons.close));
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
final opacity = tester.widgetList<AnimatedOpacity>(
|
||||
find.byType(AnimatedOpacity),
|
||||
);
|
||||
expect(opacity.any((widget) => widget.opacity == 0), isTrue);
|
||||
expect(find.byKey(const Key('global-error-notification')), findsNothing);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
container.dispose();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:cutdex/features/projects/project_switch_region.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
Widget region(String? pending) => Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: ProjectSwitchRegion(
|
||||
pendingProjectId: pending,
|
||||
builder: (context, showDefaults) =>
|
||||
Text(showDefaults ? 'defaults' : 'content'),
|
||||
),
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'fast completion never displays defaults or waits for the timer',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(region('A'));
|
||||
expect(find.text('content'), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<IgnorePointer>(find.byType(IgnorePointer)).ignoring,
|
||||
isTrue,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 100));
|
||||
await tester.pumpWidget(region(null));
|
||||
expect(find.text('defaults'), findsNothing);
|
||||
expect(
|
||||
tester.widget<IgnorePointer>(find.byType(IgnorePointer)).ignoring,
|
||||
isFalse,
|
||||
);
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(find.text('defaults'), findsNothing);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'slow switches show defaults after 150ms and reset on a new target',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(region('A'));
|
||||
await tester.pump(const Duration(milliseconds: 149));
|
||||
expect(find.text('defaults'), findsNothing);
|
||||
await tester.pump(const Duration(milliseconds: 1));
|
||||
expect(find.text('defaults'), findsOneWidget);
|
||||
await tester.pumpWidget(region('B'));
|
||||
expect(find.text('defaults'), findsNothing);
|
||||
await tester.pump(const Duration(milliseconds: 150));
|
||||
expect(find.text('defaults'), findsOneWidget);
|
||||
await tester.pumpWidget(region(null));
|
||||
expect(find.text('content'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('disposing during a switch cancels the pending timer', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(region('A'));
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
await tester.pump(const Duration(milliseconds: 200));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
@@ -33,10 +33,14 @@ void main() {
|
||||
timelines.single.id,
|
||||
);
|
||||
final session = await workspace.openTimelineSession(firstId, document);
|
||||
final thumbnails = session.thumbnails;
|
||||
final waveforms = session.waveforms;
|
||||
await workspace.open('${root.path}/Two.cutdex', name: 'Two');
|
||||
await workspace.open('${root.path}/One.cutdex', expectedId: firstId);
|
||||
final restored = await workspace.openTimelineSession(firstId, document);
|
||||
expect(restored, same(session));
|
||||
expect(restored.thumbnails, same(thumbnails));
|
||||
expect(restored.waveforms, same(waveforms));
|
||||
expect(restored.acceptsEdits, isTrue);
|
||||
await workspace.open('${root.path}/Two.cutdex');
|
||||
await workspace.open('${root.path}/Three.cutdex', name: 'Three');
|
||||
@@ -44,6 +48,8 @@ void main() {
|
||||
expect(workspace.cachedProjectIds.length, 3);
|
||||
expect(workspace.cachedProjectIds, isNot(contains(firstId)));
|
||||
expect(session.acceptsEdits, isFalse);
|
||||
expect(() => thumbnails.addListener(() {}), throwsFlutterError);
|
||||
expect(() => waveforms.addListener(() {}), throwsFlutterError);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -896,6 +896,43 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('prepared timeline stays visible while provider binds', (
|
||||
tester,
|
||||
) async {
|
||||
final pending = Completer<EditorTimelineSession>();
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(
|
||||
() => _CachedViewProjects(session, projectId),
|
||||
),
|
||||
editorTimelineProvider(
|
||||
projectId,
|
||||
'project',
|
||||
).overrideWith((ref) => pending.future),
|
||||
],
|
||||
child: MaterialApp(
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
theme: EditorTheme.penDark,
|
||||
home: Scaffold(
|
||||
body: EditorTimelinePanel(
|
||||
projectId: projectId,
|
||||
timelineId: 'project',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byKey(const Key('timeline-pending')), findsNothing);
|
||||
expect(find.byKey(const Key('editor-timeline-surface')), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
pending.complete(session);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
});
|
||||
|
||||
testWidgets('timeline switch keeps the toolbar element mounted', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -936,6 +973,13 @@ void main() {
|
||||
await tester.pumpWidget(panel('project'));
|
||||
await tester.pumpAndSettle();
|
||||
final toolbar = tester.element(find.byKey(const Key('timeline-toolbar')));
|
||||
// Entering the clip enables cut/trim; subsequent motion keeps that state.
|
||||
session.view(session.activeSequenceId!).seekTo(100);
|
||||
await tester.pump();
|
||||
final toolbarWidget = toolbar.widget;
|
||||
session.view(session.activeSequenceId!).seekTo(200);
|
||||
await tester.pump();
|
||||
expect(toolbar.widget, same(toolbarWidget));
|
||||
|
||||
await tester.pumpWidget(panel(second.document.id));
|
||||
await tester.pump();
|
||||
@@ -3768,3 +3812,14 @@ class _ImportingDropProjects extends _DropProjects {
|
||||
return _importResult.future;
|
||||
}
|
||||
}
|
||||
|
||||
class _CachedViewProjects extends _ViewProjects {
|
||||
_CachedViewProjects(super.session, super.projectId);
|
||||
@override
|
||||
EditorTimelineSession? cachedTimelineSession(
|
||||
String projectId,
|
||||
String timelineId,
|
||||
) => projectId == this.projectId && timelineId == session.document.id
|
||||
? session
|
||||
: null;
|
||||
}
|
||||
+421
-291
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,36 @@
|
||||
import 'package:cutdex/shared/widgets/workspace_card.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'content replacement preserves the card frame and updates theme',
|
||||
(tester) async {
|
||||
Widget card(String content, Brightness brightness) => MaterialApp(
|
||||
theme: ThemeData(brightness: brightness),
|
||||
home: Scaffold(body: WorkspaceCard(child: Text(content))),
|
||||
);
|
||||
final frame = find
|
||||
.descendant(
|
||||
of: find.byType(WorkspaceCard),
|
||||
matching: find.byType(DecoratedBox),
|
||||
)
|
||||
.first;
|
||||
await tester.pumpWidget(card('Project A', Brightness.light));
|
||||
final before = tester.widget<DecoratedBox>(frame);
|
||||
final frameElement = tester.element(frame);
|
||||
await tester.pumpWidget(card('Project B', Brightness.light));
|
||||
expect(find.text('Project A'), findsNothing);
|
||||
expect(find.text('Project B'), findsOneWidget);
|
||||
expect(tester.element(frame), same(frameElement));
|
||||
expect(tester.widget<DecoratedBox>(frame), same(before));
|
||||
await tester.pumpWidget(card('Project B', Brightness.dark));
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.element(frame), same(frameElement));
|
||||
expect(
|
||||
(tester.widget<DecoratedBox>(frame).decoration as BoxDecoration).color,
|
||||
isNot((before.decoration as BoxDecoration).color),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import 'package:cutdex/shared/widgets/workspace_resize_handle.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
for (final axis in Axis.values) {
|
||||
for (final finish in ['release', 'cancel', 'unmount']) {
|
||||
testWidgets('$axis resize cursor stays locked until $finish', (
|
||||
tester,
|
||||
) async {
|
||||
var showHandle = true;
|
||||
var taps = 0;
|
||||
var ends = 0;
|
||||
var updates = 0;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
left: 400,
|
||||
top: 400,
|
||||
width: 100,
|
||||
height: 60,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
key: const Key('button'),
|
||||
onTap: () => taps++,
|
||||
child: const ColoredBox(color: Colors.blue),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showHandle)
|
||||
Positioned(
|
||||
left: 100,
|
||||
top: 100,
|
||||
width: axis == Axis.horizontal ? 5 : 200,
|
||||
height: axis == Axis.horizontal ? 200 : 5,
|
||||
child: WorkspaceResizeHandle(
|
||||
key: const Key('handle'),
|
||||
axis: axis,
|
||||
initialValue: 100,
|
||||
onResize: (_) => updates++,
|
||||
onEnd: () => ends++,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
final start = tester.getCenter(find.byKey(const Key('handle')));
|
||||
final button = tester.getCenter(find.byKey(const Key('button')));
|
||||
await mouse.addPointer(location: start);
|
||||
await mouse.down(start);
|
||||
await mouse.moveBy(
|
||||
axis == Axis.horizontal ? const Offset(30, 0) : const Offset(0, 30),
|
||||
);
|
||||
await tester.pump();
|
||||
await mouse.moveTo(button);
|
||||
await tester.pump();
|
||||
expect(updates, greaterThan(0));
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
axis == Axis.horizontal
|
||||
? SystemMouseCursors.resizeColumn
|
||||
: SystemMouseCursors.resizeRow,
|
||||
);
|
||||
// A second pointer still reaches the control through the cursor overlay.
|
||||
await tester.tap(find.byKey(const Key('button')));
|
||||
expect(taps, 1);
|
||||
|
||||
if (finish == 'unmount') {
|
||||
update(() => showHandle = false);
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.up();
|
||||
} else if (finish == 'cancel') {
|
||||
await mouse.cancel();
|
||||
} else {
|
||||
await mouse.up();
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.moveTo(button + const Offset(1, 0));
|
||||
await tester.pump();
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
SystemMouseCursors.click,
|
||||
);
|
||||
expect(ends, finish == 'unmount' ? 0 : 1);
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user