feat(workspace): add workflow navigation and resizable desktop panels

This commit is contained in:
lingjhf committed 2026-10-09 19:23:49 +08:00
1 parent 02413383d8
commit 1acfe4a005
17 files changed
+2008 -277

No files matched your search

+373 -13
View File
@@ -61,8 +61,8 @@ Future<void> floatOrDockChat(WidgetTester tester) async {
void main() {
test('space classes and two-pane decisions do not depend on workflow', () {
expect(WorkspaceLayoutPolicy.desktopNavigationFits(545), isFalse);
expect(WorkspaceLayoutPolicy.desktopNavigationFits(546), isTrue);
expect(WorkspaceLayoutPolicy.desktopNavigationFits(541), isFalse);
expect(WorkspaceLayoutPolicy.desktopNavigationFits(542), isTrue);
expect(WorkspaceLayoutPolicy.showAgentBesideEditor(839), isFalse);
expect(WorkspaceLayoutPolicy.showAgentBesideEditor(840), isTrue);
});
@@ -178,7 +178,7 @@ void main() {
expect(header.contains(tester.getCenter(projectTab)), isTrue);
expect(find.byKey(const Key('sidebar-tab-chat')), findsNothing);
expect(find.byKey(const Key('sidebar-tab-resources')), findsNothing);
expect(find.byKey(const Key('desktop-navigation-rail')), findsNothing);
expect(find.byKey(const Key('desktop-navigation-rail')), findsOneWidget);
expect(find.byKey(const Key('media-project-button')), findsNothing);
expect(find.byKey(const Key('media-panel-close')), findsNothing);
final mediaHeader = find.byKey(const Key('media-panel-header'));
@@ -202,12 +202,49 @@ void main() {
find.byKey(const Key('editor-timeline-card')),
);
final chatRect = tester.getRect(find.byKey(const Key('desktop-chat-card')));
expect(media.left - chatRect.right, 6);
expect(preview.left - media.right, 6);
expect(media.left - chatRect.right, 2);
expect(preview.left - media.right, 2);
expect(timeline.top - media.bottom, 2);
final content = tester.getRect(
find.byKey(const Key('desktop-content-container')),
);
expect(content.left, 46);
expect(content.right, 1198);
expect(content.bottom, 798);
expect(media.top, preview.top);
expect(timeline.left, media.left);
expect(timeline.right, preview.right);
final previewElement = tester.element(find.byType(EditorPreviewPanel));
await tester.drag(
find.byKey(const Key('editor-media-resize')),
const Offset(60, 0),
);
await tester.pumpAndSettle();
expect(
tester.getSize(find.byKey(const Key('editor-media-card'))).width,
media.width + 60,
);
await tester.drag(
find.byKey(const Key('editor-media-timeline-junction')),
const Offset(40, -30),
);
await tester.pumpAndSettle();
final resizedSettings = mounted.container
.read(projectViewSettingsProvider(mounted.projectId))
.requireValue;
expect(resizedSettings.mediaWidth, media.width + 100);
expect(resizedSettings.timelineHeight, closeTo(timeline.height + 30, .01));
expect(
tester.getSize(find.byKey(const Key('editor-timeline-card'))).height,
closeTo(timeline.height + 30, .01),
);
expect(
mounted.container
.read(projectViewSettingsProvider(mounted.projectId))
.requireValue
.mediaWidth,
media.width + 100,
);
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(find.byType(MediaPanel), findsNothing);
@@ -218,6 +255,10 @@ void main() {
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(find.byType(MediaPanel), findsOneWidget);
expect(
tester.getSize(find.byKey(const Key('editor-media-card'))).width,
media.width + 100,
);
expect(tester.element(find.byType(AgentChatPanel)), same(chat));
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
expect(
@@ -228,6 +269,319 @@ void main() {
await mounted.close();
});
testWidgets(
'chat/timeline junction resizes both axes, persists and follows docking',
(tester) async {
final mounted = await mount(tester, const Size(1800, 800));
final junction = find.byKey(const Key('desktop-chat-timeline-junction'));
Rect card(String name) => tester.getRect(find.byKey(Key(name)));
final chat = card('desktop-chat-card');
final media = card('editor-media-card');
final timeline = card('editor-timeline-card');
final center = tester.getCenter(junction);
expect(center.dx, (chat.right + media.left) / 2);
expect(center.dy, (media.bottom + timeline.top) / 2);
final editorElement = tester.element(find.byType(EditorWorkspace));
final mediaElement = tester.element(find.byType(MediaPanel));
final input = find.descendant(
of: find.byType(AgentChatPanel),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Keep draft while resizing the junction');
await tester.drag(junction, const Offset(60, -50));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, chat.width + 60);
expect(
card('editor-timeline-card').height,
closeTo(timeline.height + 50, .01),
);
expect(card('editor-media-card').width, media.width);
expect(
mounted.container
.read(workspaceViewSettingsProvider)
.requireValue
.sidebarWidth,
chat.width + 60,
);
expect(
mounted.container
.read(projectViewSettingsProvider(mounted.projectId))
.requireValue
.timelineHeight,
closeTo(timeline.height + 50, .01),
);
final savedWorkspace = await tester.runAsync(
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
);
final savedProject = await tester.runAsync(
() => mounted.container
.read(projectViewSettingsRepositoryProvider)
.load(mounted.projectId),
);
expect(savedWorkspace!.sidebarWidth, chat.width + 60);
expect(savedProject!.timelineHeight, closeTo(timeline.height + 50, .01));
await tester.drag(junction, const Offset(-40, 30));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, chat.width + 20);
expect(
card('editor-timeline-card').height,
closeTo(timeline.height + 20, .01),
);
await tester.drag(junction, const Offset(-100, -2000));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, 220);
expect(card('editor-preview-card').height, 180);
await tester.drag(junction, const Offset(40, -60));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, 260);
expect(card('editor-preview-card').height, 180);
await tester.drag(junction, const Offset(2000, 2000));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, 320);
expect(card('editor-timeline-card').height, 220);
expect(tester.element(find.byType(EditorWorkspace)), same(editorElement));
expect(tester.element(find.byType(MediaPanel)), same(mediaElement));
expect(
tester.widget<TextField>(input).controller!.text,
'Keep draft while resizing the junction',
);
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
expect(card('desktop-chat-card').width, 320);
expect(card('editor-timeline-card').height, 220);
await floatOrDockChat(tester);
await tester.pumpAndSettle();
expect(junction, findsNothing);
await floatOrDockChat(tester);
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
// The same T remains between chat, preview and timeline with media hidden.
await tester.tap(find.byKey(const Key('editor-media-button')));
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
await tester.drag(junction, const Offset(-40, -30));
await tester.pumpAndSettle();
expect(card('desktop-chat-card').width, 280);
expect(card('editor-timeline-card').height, 250);
tester.view.physicalSize = const Size(600, 360);
await tester.pumpAndSettle();
final narrowCenter = tester.getCenter(junction);
expect(
narrowCenter.dy,
(card('editor-preview-card').bottom +
card('editor-timeline-card').top) /
2,
);
await tester.drag(junction, const Offset(2000, -2000));
await tester.pumpAndSettle();
expect(card('editor-preview-card').height, 180);
expect(card('desktop-editor-card').width, 320);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
for (final junctionDrag in [false, true]) {
testWidgets(
'${junctionDrag ? 'junction' : 'sidebar'} persists resize only when the gesture ends',
(tester) async {
final mounted = await mount(tester, const Size(1800, 800));
final repository = mounted.container.read(
workspaceViewSettingsRepositoryProvider,
);
final savedBefore = (await tester.runAsync(repository.load))!;
final sidebar = find.byKey(const Key('desktop-chat-card'));
final initialWidth = tester.getSize(sidebar).width;
final handle = find.byKey(
Key(
junctionDrag
? 'desktop-chat-timeline-junction'
: 'project-sidebar-resize',
),
);
final drag = await tester.startGesture(
tester.getCenter(handle),
kind: PointerDeviceKind.mouse,
);
for (var i = 0; i < 5; i++) {
await drag.moveBy(Offset(10, junctionDrag ? -10 : 0));
await tester.pumpAndSettle();
}
expect(tester.getSize(sidebar).width, initialWidth + 50);
final savedDuring = (await tester.runAsync(repository.load))!;
expect(savedDuring.sidebarWidth, savedBefore.sidebarWidth);
// Cancellation also commits the last visible size.
if (junctionDrag) {
await drag.cancel();
} else {
await drag.up();
}
await tester.pumpAndSettle();
final savedAfter = (await tester.runAsync(repository.load))!;
expect(savedAfter.sidebarWidth, initialWidth + 50);
await mounted.close();
},
);
}
for (final junctionDrag in [false, true]) {
testWidgets(
'${junctionDrag ? 'junction' : 'sidebar'} drag snaps closed and can drag back open',
(tester) async {
final mounted = await mount(tester, const Size(1800, 800));
final sidebar = find.byKey(const Key('desktop-chat-card'));
final resize = find.byKey(const Key('project-sidebar-resize'));
final junction = find.byKey(
const Key('desktop-chat-timeline-junction'),
);
final initialWidth = tester.getSize(sidebar).width;
final initialTimeline = tester
.getSize(find.byKey(const Key('editor-timeline-card')))
.height;
final editor = tester.element(find.byType(EditorWorkspace));
final input = find.descendant(
of: find.byType(AgentChatPanel),
matching: find.byType(TextField),
);
await tester.enterText(input, 'Draft survives sidebar snapping');
final start = tester.getCenter(junctionDrag ? junction : resize);
final drag = await tester.startGesture(
start,
kind: PointerDeviceKind.mouse,
);
await drag.moveTo(
start + Offset(115 - initialWidth, junctionDrag ? -30 : 0),
);
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, 220);
await drag.moveBy(Offset(-6, junctionDrag ? -20 : 0));
await tester.pumpAndSettle();
expect(sidebar, findsNothing);
expect(resize, findsOneWidget);
expect(
mounted.container
.read(workspaceViewSettingsProvider)
.requireValue
.sidebarCollapsed,
isTrue,
);
// Crossing back over the threshold within the same gesture restores it.
await drag.moveBy(const Offset(16, 0));
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, 220);
await drag.moveBy(Offset(-16, junctionDrag ? -20 : 0));
await tester.pumpAndSettle();
expect(sidebar, findsNothing);
if (junctionDrag) {
expect(junction, findsOneWidget);
expect(
tester
.getSize(find.byKey(const Key('editor-timeline-card')))
.height,
closeTo(initialTimeline + 70, .01),
);
await drag.cancel();
} else {
await drag.up();
}
await tester.pumpAndSettle();
expect(junction, findsOneWidget);
final saved = await tester.runAsync(
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
);
expect(saved!.sidebarCollapsed, isTrue);
expect(saved.sidebarWidth, initialWidth);
if (junctionDrag) {
final savedProject = await tester.runAsync(
() => mounted.container
.read(projectViewSettingsRepositoryProvider)
.load(mounted.projectId),
);
expect(
savedProject!.timelineHeight,
closeTo(initialTimeline + 70, .01),
);
}
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, initialWidth);
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
expect(
tester.widget<TextField>(input).controller!.text,
'Draft survives sidebar snapping',
);
await tester.tap(find.byKey(const Key('project-sidebar-toggle')));
await tester.pumpAndSettle();
// A fresh edge or junction drag starts from the collapsed width of zero.
final edgeTimeline = tester
.getSize(find.byKey(const Key('editor-timeline-card')))
.height;
expect(junction, findsOneWidget);
final edge = await tester.startGesture(
tester.getCenter(junctionDrag ? junction : resize),
kind: PointerDeviceKind.mouse,
);
await edge.moveBy(Offset(109, junctionDrag ? -25 : 0));
await tester.pumpAndSettle();
expect(sidebar, findsNothing);
if (junctionDrag) {
expect(
tester
.getSize(find.byKey(const Key('editor-timeline-card')))
.height,
closeTo(edgeTimeline + 25, .01),
);
}
await edge.moveBy(const Offset(1, 0));
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, 220);
await edge.moveBy(const Offset(140, 0));
await tester.pumpAndSettle();
expect(tester.getSize(sidebar).width, 250);
await edge.up();
await tester.pumpAndSettle();
expect(
mounted.container
.read(workspaceViewSettingsProvider)
.requireValue
.sidebarCollapsed,
isFalse,
);
final reopened = await tester.runAsync(
mounted.container.read(workspaceViewSettingsRepositoryProvider).load,
);
expect(reopened!.sidebarCollapsed, isFalse);
expect(reopened.sidebarWidth, 250);
if (junctionDrag) {
final reopenedProject = await tester.runAsync(
() => mounted.container
.read(projectViewSettingsRepositoryProvider)
.load(mounted.projectId),
);
expect(
reopenedProject!.timelineHeight,
closeTo(edgeTimeline + 25, .01),
);
}
expect(
tester.widget<TextField>(input).controller!.text,
'Draft survives sidebar snapping',
);
expect(tester.takeException(), isNull);
await mounted.close();
},
);
}
testWidgets('project tabs switch scoped drafts and preserve failed close', (
tester,
) async {
@@ -504,9 +858,9 @@ void main() {
);
expect(preview.top, properties.top);
expect(preview.bottom, properties.bottom);
expect(properties.left - preview.right, 6);
expect(properties.left - preview.right, 2);
expect(playback.bottom, preview.bottom - 1);
expect(playback.height, 36);
expect(playback.height, 32);
expect(
tester.getSize(find.byKey(const Key('timeline-tabs-bar'))).height,
32,
@@ -527,7 +881,7 @@ void main() {
);
expect(
tester.getSize(find.byKey(const Key('timeline-toolbar'))).height,
36,
32,
);
expect(tester.element(find.byType(EditorWorkspace)), same(editor));
expect(AppColors.of(Theme.of(editor)).family, palette);
@@ -839,9 +1193,9 @@ void main() {
contentRect.top,
tester.getRect(find.byKey(const Key('desktop-window-header'))).bottom,
);
expect(contentRect.left, 6);
expect(contentRect.right, 1194);
expect(contentRect.bottom, 794);
expect(contentRect.left, 46);
expect(contentRect.right, 1198);
expect(contentRect.bottom, 798);
expect(
tester.getRect(find.byKey(const Key('window-minimize'))).left -
tester
@@ -1022,8 +1376,14 @@ void main() {
expect(left.left - headerRect.left, AppSidebarMetrics.outerPadding);
expect(headerRect.right - right.right, AppSidebarMetrics.outerPadding);
expect(middle.center.dx, closeTo(headerRect.center.dx, 0.01));
expect(middle.left, greaterThanOrEqualTo(left.right));
expect(middle.right, lessThanOrEqualTo(right.left));
expect(
middle.left - left.right,
greaterThanOrEqualTo(AppSpacing.small),
);
expect(
right.left - middle.right,
greaterThanOrEqualTo(AppSpacing.small),
);
expect(left.center.dy, right.center.dy);
expect(tester.widget<Text>(title).overflow, TextOverflow.ellipsis);
expect(tester.takeException(), isNull);
@@ -69,6 +69,7 @@ void main() {
onRename: (_) {},
),
onHomePressed: () {},
onWorkflowPressed: () {},
onSettingsPressed: () {},
child: const SizedBox.shrink(),
),
+396 -1
View File
@@ -1,12 +1,399 @@
import 'dart:ui' as ui;
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/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'junctions paint both connected boundaries during hover and drag',
(tester) async {
tester.view.physicalSize = const Size(1500, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final controller = DesktopWorkspaceController();
addTearDown(controller.dispose);
const accent = Color(0xFF0D99FF);
final repaintKey = GlobalKey();
final scaffoldKey = GlobalKey<ScaffoldState>();
var sidebarWidth = 240.0;
var mediaWidth = 260.0;
var timelineHeight = 280.0;
var showMedia = true;
var sidebarCollapsed = false;
late StateSetter update;
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: accent)
.copyWith(primary: accent),
),
home: RepaintBoundary(
key: repaintKey,
child: StatefulBuilder(
builder: (context, setState) {
update = setState;
return DesktopWorkspaceShell(
projectTabsLayout: true,
mode: WorkspaceMode.cut,
controller: controller,
sidebarCollapsed: sidebarCollapsed,
sidebarWidth: sidebarWidth,
onSidebarCollapsedChanged: (collapsed) =>
setState(() => sidebarCollapsed = collapsed),
onSidebarWidthChanged: (width) =>
setState(() => sidebarWidth = width),
timelineHeight: timelineHeight,
onTimelineHeightChanged: (height) =>
setState(() => timelineHeight = height),
sidebarBuilder: (_, _) => const SizedBox.expand(),
agentBuilder: (_, _) => const SizedBox.expand(),
scaffoldKey: scaffoldKey,
navigationDrawer: const SizedBox.shrink(),
editor: ExpandedEditorLayout(
preview: const SizedBox.expand(),
header: const SizedBox(height: 40),
properties: const SizedBox.expand(),
media: const SizedBox.expand(),
showMedia: showMedia,
showProperties: false,
mediaWidth: mediaWidth,
onMediaWidthChanged: (width) =>
setState(() => mediaWidth = width),
onMediaWidthChangeEnd: () {},
timelineHeight: timelineHeight,
onTimelineHeightChanged: (height) =>
setState(() => timelineHeight = height),
onTimelineHeightChangeEnd: () {},
onJunctionResizeEnd: () {},
timeline: const SizedBox.expand(),
),
);
},
),
),
),
);
const boundaries = {
'sidebar': 'project-sidebar-resize',
'media': 'editor-media-resize',
'timeline': 'editor-timeline-resize',
};
Future<void> expectPainted(Set<String> active) async {
final render =
repaintKey.currentContext!.findRenderObject()!
as RenderRepaintBoundary;
final image = (await tester.runAsync(render.toImage))!;
final data = (await tester.runAsync(
() => image.toByteData(format: ui.ImageByteFormat.rawRgba),
))!;
Color pixel(Offset global) {
final point = render.globalToLocal(global);
final offset =
(point.dy.floor() * image.width + point.dx.floor()) * 4;
return Color.fromARGB(
data.getUint8(offset + 3),
data.getUint8(offset),
data.getUint8(offset + 1),
data.getUint8(offset + 2),
);
}
for (final entry in boundaries.entries) {
final handle = find.byKey(Key(entry.value));
if (handle.evaluate().isEmpty) continue;
final rect = tester.getRect(handle);
final paint = tester.getRect(
find.descendant(of: handle, matching: find.byType(DecoratedBox)),
);
final color = pixel(paint.center);
expect(
color,
active.contains(entry.key) ? accent : isNot(accent),
reason: entry.key,
);
if (active.contains(entry.key)) {
final vertical = entry.key != 'timeline';
expect(vertical ? rect.width : rect.height, 10);
expect(vertical ? paint.width : paint.height, 4);
}
}
if (active.containsAll({'sidebar', 'timeline'})) {
final sidebar = tester.getRect(
find.byKey(const Key('project-sidebar-resize')),
);
final timeline = tester.getRect(
find.byKey(const Key('editor-timeline-resize')),
);
if (sidebarCollapsed) {
expect(sidebar.left, 0);
expect(sidebar.width, 10);
final verticalPaint = tester.getRect(
find.descendant(
of: find.byKey(const Key('project-sidebar-resize')),
matching: find.byType(DecoratedBox),
),
);
expect(verticalPaint.center.dx, timeline.left);
expect(
pixel(Offset(sidebar.center.dx, timeline.center.dy - 20)),
isNot(accent),
reason: 'Collapsed feedback sits at the edge, not the hit center',
);
expect(
pixel(Offset(timeline.left, timeline.center.dy - 20)),
accent,
);
}
if (showMedia) {
final media = tester.getRect(
find.byKey(const Key('editor-media-resize')),
);
expect(
pixel(Offset(media.center.dx, timeline.center.dy)),
accent,
reason: 'The original media/preview/timeline T stays continuous',
);
}
}
image.dispose();
}
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.addPointer(location: const Offset(1400, 50));
await tester.pumpAndSettle();
await expectPainted({});
await mouse.moveTo(
tester.getCenter(find.byKey(const Key('editor-media-resize'))),
);
await tester.pumpAndSettle();
await expectPainted({'media'});
await mouse.moveTo(
tester.getCenter(
find.byKey(const Key('editor-media-timeline-junction')),
),
);
await tester.pumpAndSettle();
await expectPainted({'media', 'timeline'});
// Removing the junction leaves the pointer hovering over the timeline.
update(() => showMedia = false);
await tester.pumpAndSettle();
await expectPainted({'timeline'});
await mouse.moveTo(const Offset(1450, 50));
await tester.pumpAndSettle();
await expectPainted({});
update(() => showMedia = true);
await tester.pumpAndSettle();
final junction = find.byKey(const Key('desktop-chat-timeline-junction'));
await mouse.moveTo(tester.getCenter(junction));
await tester.pumpAndSettle();
await expectPainted({'sidebar', 'timeline'});
await mouse.down(tester.getCenter(junction));
await mouse.moveBy(const Offset(60, -40));
await tester.pumpAndSettle();
await mouse.moveTo(const Offset(1450, 50));
await tester.pumpAndSettle();
await expectPainted({'sidebar', 'timeline'});
await mouse.up();
await tester.pumpAndSettle();
await expectPainted({});
await mouse.moveTo(tester.getCenter(junction));
await mouse.down(tester.getCenter(junction));
await mouse.moveBy(const Offset(-300, 20));
await tester.pumpAndSettle();
expect(sidebarCollapsed, isTrue);
await expectPainted({'sidebar', 'timeline'});
final node = tester.getRect(
find.descendant(of: junction, matching: find.byType(DecoratedBox)),
);
expect(node.center.dx, 0);
expect(tester.getSize(junction).width, 10);
// Reverse the same drag: feedback returns to the expanded boundary.
await mouse.moveBy(const Offset(150, -20));
await tester.pumpAndSettle();
expect(sidebarCollapsed, isFalse);
await expectPainted({'sidebar', 'timeline'});
final expandedNode = tester.getRect(
find.descendant(of: junction, matching: find.byType(DecoratedBox)),
);
expect(expandedNode.center.dx, tester.getCenter(junction).dx);
await mouse.up();
await tester.pumpAndSettle();
await mouse.removePointer();
expect(tester.takeException(), isNull);
},
);
testWidgets(
'media/timeline junction drags both splits and clamps each axis',
(tester) async {
tester.view.physicalSize = const Size(1100, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
var mediaWidth = 260.0;
var timelineHeight = 280.0;
var showMedia = true;
var saves = 0;
var singleAxisEnds = 0;
late StateSetter update;
await tester.pumpWidget(
MaterialApp(
home: StatefulBuilder(
builder: (context, setState) {
update = setState;
return ExpandedEditorLayout(
preview: const SizedBox.expand(),
header: const SizedBox(height: 40),
properties: const SizedBox.expand(),
media: const SizedBox.expand(),
showMedia: showMedia,
showProperties: true,
mediaWidth: mediaWidth,
onMediaWidthChanged: (value) =>
setState(() => mediaWidth = value),
onMediaWidthChangeEnd: () => singleAxisEnds++,
timelineHeight: timelineHeight,
onTimelineHeightChanged: (value) =>
setState(() => timelineHeight = value),
onTimelineHeightChangeEnd: () => singleAxisEnds++,
onJunctionResizeEnd: () => saves++,
timeline: const SizedBox.expand(),
);
},
),
),
);
final junction = find.byKey(const Key('editor-media-timeline-junction'));
Rect card(String name) =>
tester.getRect(find.byKey(Key('editor-$name-card')));
final center = tester.getCenter(junction);
expect(center.dx, (card('media').right + card('preview').left) / 2);
expect(center.dy, (card('preview').bottom + card('timeline').top) / 2);
await tester.drag(junction, const Offset(80, -60));
await tester.pumpAndSettle();
expect(card('media').width, 340);
expect(card('timeline').height, 340);
expect(saves, 1);
expect(singleAxisEnds, 0);
await tester.drag(junction, const Offset(-40, 30));
await tester.pumpAndSettle();
expect(card('media').width, 300);
expect(card('timeline').height, 310);
expect(saves, 2);
await tester.drag(junction, const Offset(-2000, -2000));
await tester.pumpAndSettle();
expect(card('media').width, 220);
expect(card('preview').height, 180);
await tester.drag(junction, const Offset(80, -60));
await tester.pumpAndSettle();
expect(card('media').width, 300);
expect(card('preview').height, 180);
await tester.drag(junction, const Offset(2000, 2000));
await tester.pumpAndSettle();
expect(card('preview').width, 320);
expect(card('timeline').height, 220);
expect(saves, 5);
expect(singleAxisEnds, 0);
update(() => showMedia = false);
await tester.pump();
expect(junction, findsNothing);
expect(tester.takeException(), isNull);
},
);
testWidgets('media width drags, respects other panels and survives hiding', (
tester,
) async {
tester.view.physicalSize = const Size(1100, 800);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
double? mediaWidth;
var showMedia = true;
var saves = 0;
late StateSetter update;
await tester.pumpWidget(
MaterialApp(
home: StatefulBuilder(
builder: (context, setState) {
update = setState;
return ExpandedEditorLayout(
preview: const SizedBox.expand(),
header: const SizedBox(height: 40),
properties: const SizedBox.expand(),
media: const SizedBox.expand(key: Key('test-media')),
showMedia: showMedia,
showProperties: true,
mediaWidth: mediaWidth,
onMediaWidthChanged: (value) =>
setState(() => mediaWidth = value),
onMediaWidthChangeEnd: () => saves++,
timelineHeight: 220,
onTimelineHeightChanged: (_) {},
onTimelineHeightChangeEnd: () {},
onJunctionResizeEnd: () {},
timeline: const SizedBox.expand(),
);
},
),
),
);
Rect card(String name) =>
tester.getRect(find.byKey(Key('editor-$name-card')));
final resize = find.byKey(const Key('editor-media-resize'));
final mediaElement = tester.element(find.byKey(const Key('test-media')));
expect(card('media').width, 260);
expect(tester.getSize(resize).width, 10);
expect(tester.getRect(resize).bottom, card('preview').bottom);
await tester.dragFrom(
tester.getCenter(resize) + const Offset(4, 0),
const Offset(80, 0),
);
await tester.pumpAndSettle();
expect(card('media').width, 340);
expect(saves, 1);
expect(card('preview').left - card('media').right, 2);
expect(card('properties').width, 240);
await tester.drag(resize, const Offset(2000, 0));
await tester.pumpAndSettle();
expect(card('preview').width, 320);
expect(card('media').width, 536);
await tester.drag(resize, const Offset(-2000, 0));
await tester.pumpAndSettle();
expect(card('media').width, 220);
expect(saves, 3);
update(() => mediaWidth = 400);
await tester.pump();
tester.view.physicalSize = const Size(900, 800);
await tester.pumpAndSettle();
expect(card('media').width, 336);
expect(card('preview').width, 320);
expect(mediaWidth, 400);
tester.view.physicalSize = const Size(1100, 800);
await tester.pumpAndSettle();
expect(card('media').width, 400);
update(() => showMedia = false);
await tester.pump();
expect(resize, findsNothing);
update(() => showMedia = true);
await tester.pump();
expect(card('media').width, 400);
expect(
tester.element(find.byKey(const Key('test-media'))),
same(mediaElement),
);
expect(saves, 3);
expect(tester.takeException(), isNull);
});
testWidgets('inspector has an independent frame aligned with the preview', (
tester,
) async {
@@ -28,9 +415,13 @@ void main() {
media: const SizedBox(),
showMedia: false,
showProperties: showProperties,
mediaWidth: null,
onMediaWidthChanged: (_) {},
onMediaWidthChangeEnd: () {},
timelineHeight: 200,
onTimelineHeightChanged: (_) {},
onTimelineHeightChangeEnd: () {},
onJunctionResizeEnd: () {},
timeline: const SizedBox(),
);
},
@@ -65,7 +456,7 @@ void main() {
);
expect(tester.takeException(), isNull);
});
testWidgets('preview and timeline cards resize through their 6 dp gap', (
testWidgets('preview and timeline cards resize through their narrow gap', (
tester,
) async {
tester.view.physicalSize = const Size(700, 800);
@@ -84,10 +475,14 @@ void main() {
media: const SizedBox(),
showMedia: false,
showProperties: false,
mediaWidth: null,
onMediaWidthChanged: (_) {},
onMediaWidthChangeEnd: () {},
timelineHeight: timelineHeight,
onTimelineHeightChanged: (value) =>
update(() => timelineHeight = value),
onTimelineHeightChangeEnd: () => saves++,
onJunctionResizeEnd: () {},
timeline: const Column(
children: [
Text('Toolbar'),
+1 -1
View File
@@ -66,7 +66,7 @@ void main() {
expect(find.byKey(const Key('timeline-toolbar')), findsOneWidget);
expect(
tester.getSize(find.byKey(const Key('timeline-add-button'))),
const Size.square(26),
const Size.square(24),
);
for (final button in tester.widgetList<IconButton>(
find.byType(IconButton),
+5 -6
View File
@@ -131,7 +131,7 @@ void main() {
.top,
),
);
expect(settingsRect.left - navigationRect.right, 6);
expect(settingsRect.left - navigationRect.right, 2);
expect(settingsRect.top, navigationRect.top);
expect(settingsRect.bottom, navigationRect.bottom);
expect(find.byKey(const Key('settings-sidebar-divider')), findsNothing);
@@ -885,13 +885,13 @@ void main() {
.textStyle!
.resolve({})!
.fontSize,
13,
11,
);
final projectTabFinder = find.byKey(
const ValueKey('timeline-tab-project'),
);
final tabRect = tester.getRect(projectTabFinder);
expect(tabRect.height, 26);
expect(tabRect.height, 24);
for (final key in ['timeline-add-button', 'timeline-list-button']) {
final buttonRect = tester.getRect(find.byKey(Key(key)));
expect(buttonRect.height, tabRect.height);
@@ -901,7 +901,7 @@ void main() {
expect(
tester.getRect(find.byKey(const Key('timeline-tabs-bar'))).right -
tester.getRect(find.byKey(const Key('timeline-list-button'))).right,
4,
8,
);
expect(
tester
@@ -909,8 +909,7 @@ void main() {
.style!
.backgroundColor!
.resolve({}),
Theme.of(tester.element(projectTabFinder)).colorScheme.primary
.withValues(alpha: .12),
Theme.of(tester.element(projectTabFinder)).colorScheme.surfaceContainer,
);
expect(find.byKey(const ValueKey('timeline-tab-second')), findsOneWidget);
final tabs = find.byKey(const Key('timeline-tabs-list'));
+232 -95
View File
@@ -5,107 +5,244 @@ 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 starts = 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),
),
),
for (final axis in [...Axis.values, null]) {
testWidgets('$axis feedback fades and expands with rounded ends', (
tester,
) async {
final handle = find.byKey(const Key('animated-handle'));
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: axis == Axis.vertical ? 200 : 10,
height: axis == Axis.horizontal ? 200 : 10,
child: axis == null
? WorkspaceResizeHandle.junction(
key: const Key('animated-handle'),
initialWidth: 100,
initialHeight: 100,
onWidthChanged: (_) {},
onHeightChanged: (_) {},
)
: WorkspaceResizeHandle(
key: const Key('animated-handle'),
axis: axis,
initialValue: 100,
onResize: (_) {},
),
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,
onStart: () => starts++,
onResize: (_) {
expect(starts, 1);
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(starts, 1);
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);
),
);
final fade = find.descendant(of: handle, matching: find.byType(Opacity));
final paint = find.descendant(
of: handle,
matching: find.byType(DecoratedBox),
);
double opacity() => tester.widget<Opacity>(fade).opacity;
final hitSize = tester.getSize(handle);
final center = tester.getCenter(handle);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
expect(opacity(), 0);
await mouse.addPointer(location: center);
await tester.pump();
expect(opacity(), 0);
await tester.pump(const Duration(milliseconds: 60));
expect(opacity(), inExclusiveRange(0, 1));
final growing = tester.getRect(paint);
expect(
axis == Axis.vertical ? growing.height : growing.width,
inExclusiveRange(2, 4),
);
expect(tester.getSize(handle), hitSize);
await tester.pumpAndSettle();
expect(opacity(), 1);
final decoration =
tester.widget<DecoratedBox>(paint).decoration as BoxDecoration;
expect(decoration.borderRadius, BorderRadius.circular(2));
await mouse.moveTo(const Offset(10, 10));
await tester.pump();
await tester.pump(const Duration(milliseconds: 30));
final fading = opacity();
expect(fading, inExclusiveRange(0, 1));
// Reentering mid-fade continues from its current appearance.
await mouse.moveTo(center);
await tester.pump();
expect(opacity(), closeTo(fading, .001));
await tester.pumpAndSettle();
expect(opacity(), 1);
await mouse.moveTo(const Offset(10, 10));
await tester.pumpAndSettle();
expect(opacity(), 0);
await mouse.removePointer();
expect(tester.takeException(), isNull);
});
}
if (finish == 'unmount') {
update(() => showHandle = false);
for (final axis in [...Axis.values, null]) {
for (final finish in ['release', 'cancel', 'unmount']) {
testWidgets(
'$axis resize cursor stays locked until $finish',
(tester) async {
final expectedCursor = axis == null
? SystemMouseCursors.grab
: axis == Axis.horizontal
? SystemMouseCursors.resizeColumn
: SystemMouseCursors.resizeRow;
var showHandle = true;
var taps = 0;
var ends = 0;
var starts = 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 == null || axis == Axis.horizontal
? 5
: 200,
height: axis == null || axis == Axis.vertical
? 5
: 200,
child: axis == null
? WorkspaceResizeHandle.junction(
key: const Key('handle'),
initialWidth: 100,
initialHeight: 100,
onStart: () => starts++,
onWidthChanged: (_) {
expect(starts, 1);
updates++;
},
onHeightChanged: (_) {
expect(starts, 1);
updates++;
},
onEnd: () => ends++,
)
: WorkspaceResizeHandle(
key: const Key('handle'),
axis: axis,
initialValue: 100,
onStart: () => starts++,
onResize: (_) {
expect(starts, 1);
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')));
double highlightOpacity() => tester
.widget<Opacity>(
find.descendant(
of: find.byKey(const Key('handle')),
matching: find.byType(Opacity),
),
)
.opacity;
expect(highlightOpacity(), 0);
await mouse.addPointer(location: start);
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);
});
expect(highlightOpacity(), 1);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
expectedCursor,
);
await mouse.down(start);
await mouse.moveBy(
axis == null
? const Offset(30, 30)
: 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(starts, 1);
expect(highlightOpacity(), 1);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
axis == null ? SystemMouseCursors.grabbing : expectedCursor,
);
// 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);
if (finish != 'unmount') {
expect(highlightOpacity(), 0);
await mouse.moveTo(start);
await tester.pumpAndSettle();
expect(highlightOpacity(), 1);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
expectedCursor,
);
}
await mouse.removePointer();
expect(tester.takeException(), isNull);
},
variant: const TargetPlatformVariant({
TargetPlatform.macOS,
TargetPlatform.windows,
TargetPlatform.linux,
}),
);
}
}
}