Files
cutdex/test/desktop_workspace_cards_test.dart
T
lingjhf 2e0033ce2d
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
feat(workspace): refresh desktop editing experience and prepare 0.1.2
2026-10-09 01:56:01 +08:00

270 lines
9.8 KiB
Dart

import 'package:cutdex/app/adaptive/desktop_workspace_controller.dart';
import 'package:cutdex/shared/layout/workspace_layout_metrics.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('inspector has an independent frame aligned with the preview', (
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);
expect(divider.bottom, card.bottom);
expect(properties.top, divider.top);
expect(properties.bottom, divider.bottom);
expect(header.right, divider.left - 1);
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,
tester.getRect(find.byKey(const Key('editor-preview-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 6 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,
WorkspaceLayoutMetrics.desktopSpacing,
);
final resize = find.byKey(const Key('editor-timeline-resize'));
expect(
tester.getSize(resize).height,
WorkspaceLayoutMetrics.desktopResizeHitExtent,
);
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,
WorkspaceLayoutMetrics.desktopSpacing,
);
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, 6),
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,
WorkspaceLayoutMetrics.desktopSpacing,
);
expect(agent.left - editor.right, WorkspaceLayoutMetrics.desktopSpacing);
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,
WorkspaceLayoutMetrics.desktopResizeHitExtent,
);
expect(
tester.getSize(agentResize).width,
WorkspaceLayoutMetrics.desktopResizeHitExtent,
);
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,
WorkspaceLayoutMetrics.desktopSpacing,
);
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(-6, 0),
const Offset(30, 0),
);
await tester.pumpAndSettle();
expect(card('project').width, project.width + 40);
expect(
card('editor').left - card('project').right,
WorkspaceLayoutMetrics.desktopSpacing,
);
controller.setAgentVisible(true);
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());
},
);
}