feat(workspace): add workflow navigation and resizable desktop panels
This commit is contained in:
1 parent
02413383d8
commit
1acfe4a005
17 files changed
+2008
-277
No files matched your search
@@ -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'),
|
||||
|
||||
Reference in new issue
Block a user