Gitea CI / Assemble and validate CI artifacts (push) Successful in 1m47s
Gitea CI / Check code and tests (push) Successful in 7m15s
Gitea CI / Build Android APK (push) Successful in 4m6s
Gitea CI / Build Windows x64 app (push) Successful in 3m34s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m29s
Gitea CI / Gitea CI passed (push) Successful in 1s
Gitea Release / Prepare draft Release (push) Failing after 8s
Gitea Release / Upload Android to draft Release (push) Skipped
Gitea Release / Upload Windows to draft Release (push) Skipped
Gitea Release / Verify and publish Release (push) Skipped
1124 lines
36 KiB
Dart
1124 lines
36 KiB
Dart
import 'dart:ui' show PointerDeviceKind;
|
|
import 'package:cutdex_core/timeline/engine.dart';
|
|
import 'package:cutdex_core/timeline/layout.dart';
|
|
import 'package:cutdex_core/timeline/model.dart';
|
|
import 'package:cutdex_timeline_ui/cutdex_timeline_ui.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
const second = TimelineClock.ticksPerSecond;
|
|
final viewport = TimelineViewportRect(width: 800, height: 120);
|
|
|
|
void main() {
|
|
test('trim hit targets exclude the reserved clip header and gap', () {
|
|
final c = fixture(1);
|
|
addTearDown(c.dispose);
|
|
final clip = c.version.kernelVersion.query().elementById(
|
|
ElementId('clip'),
|
|
)!;
|
|
c.setGeometry(
|
|
TimelineViewportGeometry(
|
|
primaryTop: 40,
|
|
primaryHeight: 40,
|
|
clipHeaderOwners: [clip],
|
|
clipHeaderHeight: 16,
|
|
),
|
|
);
|
|
for (final leading in [true, false]) {
|
|
final x = leading ? 201.0 : 299.0;
|
|
for (final y in [24.0, 27.0, 37.0, 38.0, 39.999, 40.0, 60.0, 79.999]) {
|
|
final position = Offset(x, y);
|
|
final hit = c.hitTest(viewport: viewport, position: position);
|
|
expect(hit?.identity, clip);
|
|
expect(
|
|
c.trimEdgeAt(hit: hit, position: position, extent: 6),
|
|
y < 40
|
|
? isNull
|
|
: leading
|
|
? TimelineTrimEdge.leading
|
|
: TimelineTrimEdge.trailing,
|
|
reason: 'Only the clip body owns edge trim at $position',
|
|
);
|
|
}
|
|
}
|
|
});
|
|
|
|
for (final leading in [true, false]) {
|
|
for (final headerHeight in [0, 16]) {
|
|
testWidgets(
|
|
'trim paints only its active body edge: leading $leading, header $headerHeight',
|
|
(tester) async {
|
|
final c = fixture(1);
|
|
addTearDown(c.dispose);
|
|
final clip = c.version.kernelVersion.query().elementById(
|
|
ElementId('clip'),
|
|
)!;
|
|
c.setGeometry(
|
|
TimelineViewportGeometry(
|
|
primaryTop: 40,
|
|
primaryHeight: 40,
|
|
clipHeaderOwners: headerHeight == 0 ? const [] : [clip],
|
|
clipHeaderHeight: headerHeight,
|
|
),
|
|
);
|
|
c.setSelection([clip]);
|
|
final theme = const TimelineThemeData.dark().copyWith(
|
|
clipCornerRadius: 6,
|
|
);
|
|
await tester.pumpWidget(
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 120,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
edgeScrollExtent: 0,
|
|
child: TimelineView(controller: c, theme: theme),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
_TrimOutlineCanvas paint() {
|
|
final canvas = _TrimOutlineCanvas(theme.selectionOutlineColor);
|
|
tester
|
|
.widget<CustomPaint>(find.byType(CustomPaint))
|
|
.painter!
|
|
.paint(canvas, const Size(800, 120));
|
|
return canvas;
|
|
}
|
|
|
|
final selected = paint();
|
|
expect(selected.closedOutlines, hasLength(1));
|
|
expect(selected.closedOutlines.single.top, 40 - headerHeight);
|
|
expect(selected.edges, isEmpty);
|
|
final down = Offset(leading ? 201 : 299, 60);
|
|
expect(
|
|
c.beginDrag(viewport: viewport, position: down, trimHitExtent: 6),
|
|
isTrue,
|
|
);
|
|
final target = down.translate(leading ? 10 : -10, 0);
|
|
c.updateDrag(viewport: viewport, position: target);
|
|
await tester.pump();
|
|
final frame = c.project(viewport);
|
|
final index = List.generate(
|
|
frame.length,
|
|
(index) => index,
|
|
).firstWhere((index) => frame.identityAt(index) == clip);
|
|
final layout = c.clipLayoutAt(frame, index);
|
|
final rect = layout.toViewport(layout.bodyPaintBounds);
|
|
final trimming = paint();
|
|
expect(trimming.closedOutlines, isEmpty);
|
|
expect(trimming.edges, hasLength(1));
|
|
final path = trimming.edges.single;
|
|
expect(path.computeMetrics().single.isClosed, isFalse);
|
|
final bounds = path.getBounds();
|
|
// The 14 px speed bar plus its 2 px gap are outside the trim bracket.
|
|
expect(bounds.top - theme.trimHandleWidth / 2, closeTo(40, 0.001));
|
|
expect(
|
|
bounds.top,
|
|
closeTo(rect.top + theme.trimHandleWidth / 2, 0.001),
|
|
);
|
|
expect(
|
|
bounds.bottom,
|
|
closeTo(rect.bottom - theme.trimHandleWidth / 2, 0.001),
|
|
);
|
|
if (leading) {
|
|
expect(
|
|
bounds.left,
|
|
closeTo(rect.left + theme.trimHandleWidth / 2, 0.001),
|
|
);
|
|
expect(bounds.right, lessThan(rect.center.dx));
|
|
} else {
|
|
expect(
|
|
bounds.right,
|
|
closeTo(rect.right - theme.trimHandleWidth / 2, 0.001),
|
|
);
|
|
expect(bounds.left, greaterThan(rect.center.dx));
|
|
}
|
|
expect(c.finishDrag(viewport: viewport, position: target), isTrue);
|
|
await tester.pump();
|
|
final finished = paint();
|
|
expect(c.isTrimming, isFalse);
|
|
expect(c.trimEdge, isNull);
|
|
expect(finished.closedOutlines, isEmpty);
|
|
expect(finished.edges, hasLength(1));
|
|
expect(finished.edges.single.getBounds(), bounds);
|
|
c.setHoveredIdentity(clip);
|
|
await tester.pump();
|
|
expect(paint().edges, hasLength(1));
|
|
if (leading) {
|
|
// Clicking an already-selected clip must switch the outline too.
|
|
await tester.tapAt(rect.center);
|
|
} else {
|
|
expect(
|
|
c.beginDrag(
|
|
viewport: viewport,
|
|
position: rect.center,
|
|
trimHitExtent: 6,
|
|
),
|
|
isTrue,
|
|
);
|
|
expect(c.isTrimming, isFalse);
|
|
}
|
|
await tester.pump();
|
|
expect(paint().edges, isEmpty);
|
|
expect(paint().closedOutlines, isNotEmpty);
|
|
c.cancelDrag();
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
test(
|
|
'released edge persists without a timing edit and resets on selection',
|
|
() {
|
|
final c = fixture(1);
|
|
addTearDown(c.dispose);
|
|
final clip = c.version.kernelVersion.query().elementById(
|
|
ElementId('clip'),
|
|
)!;
|
|
final base = c.version;
|
|
expect(
|
|
c.beginDrag(
|
|
viewport: viewport,
|
|
position: const Offset(299, 60),
|
|
trimHitExtent: 6,
|
|
),
|
|
isTrue,
|
|
);
|
|
expect(
|
|
c.finishDrag(viewport: viewport, position: const Offset(299, 60)),
|
|
isFalse,
|
|
);
|
|
expect(c.version, same(base));
|
|
expect(c.isDragging, isFalse);
|
|
expect(c.trimOutlineEdgeFor(clip), TimelineTrimEdge.trailing);
|
|
expect(
|
|
c.beginDrag(
|
|
viewport: viewport,
|
|
position: const Offset(201, 60),
|
|
trimHitExtent: 6,
|
|
),
|
|
isTrue,
|
|
);
|
|
expect(c.trimOutlineEdgeFor(clip), TimelineTrimEdge.leading);
|
|
expect(
|
|
c.finishDrag(viewport: viewport, position: const Offset(201, 60)),
|
|
isFalse,
|
|
);
|
|
expect(c.trimOutlineEdgeFor(clip), TimelineTrimEdge.leading);
|
|
c.clearSelection();
|
|
expect(c.trimOutlineEdgeFor(clip), isNull);
|
|
c.setSelection([clip]);
|
|
expect(c.trimOutlineEdgeFor(clip), isNull);
|
|
expect(
|
|
c.beginDrag(
|
|
viewport: viewport,
|
|
position: const Offset(299, 60),
|
|
trimHitExtent: 6,
|
|
),
|
|
isTrue,
|
|
);
|
|
c.cancelDrag();
|
|
expect(c.trimOutlineEdgeFor(clip), isNull);
|
|
},
|
|
);
|
|
|
|
test('a host can clear a released trim hint without changing selection', () {
|
|
final c = fixture(1);
|
|
addTearDown(c.dispose);
|
|
final clip = c.version.kernelVersion.query().elementById(
|
|
ElementId('clip'),
|
|
)!;
|
|
const position = Offset(299, 60);
|
|
final base = c.version;
|
|
expect(
|
|
c.beginDrag(viewport: viewport, position: position, trimHitExtent: 6),
|
|
isTrue,
|
|
);
|
|
expect(c.finishDrag(viewport: viewport, position: position), isFalse);
|
|
expect(c.trimOutlineEdgeFor(clip), TimelineTrimEdge.trailing);
|
|
var repaints = 0;
|
|
var edits = 0;
|
|
c.contentChanges.addListener(() => repaints++);
|
|
c.editingChanges.addListener(() => edits++);
|
|
c.clearRetainedTrimOutline();
|
|
expect(c.trimOutlineEdgeFor(clip), isNull);
|
|
expect(c.selectedIdentities, [clip]);
|
|
expect(c.version, same(base));
|
|
expect(c.isDragging, isFalse);
|
|
expect(repaints, 1);
|
|
expect(edits, 0);
|
|
c.clearRetainedTrimOutline();
|
|
expect(repaints, 1);
|
|
expect(
|
|
c.beginDrag(viewport: viewport, position: position, trimHitExtent: 6),
|
|
isTrue,
|
|
);
|
|
c.clearRetainedTrimOutline();
|
|
expect(c.isTrimming, isTrue);
|
|
expect(c.trimOutlineEdgeFor(clip), TimelineTrimEdge.trailing);
|
|
c.cancelDrag();
|
|
});
|
|
|
|
for (final (divisor, explicit) in [(1, false), (3, false), (3, true)]) {
|
|
for (final leading in [true, false]) {
|
|
for (final extend in [false, true]) {
|
|
test(
|
|
'split clip trims both edges: speed 1/$divisor, explicit $explicit, leading $leading, extend $extend',
|
|
() {
|
|
final c = fixture(divisor, explicitRetime: explicit);
|
|
addTearDown(c.dispose);
|
|
c.seekTo((20 + 5 * divisor) * second);
|
|
expect(c.cutSelectionAtPlayhead(), isTrue);
|
|
final base = c.version;
|
|
final q = base.kernelVersion.query();
|
|
final clip = q.elementAt(q.primaryStoryline, leading ? 2 : 1);
|
|
final record = q.element(clip);
|
|
final start = q.localContext(clip).start;
|
|
final x = c.camera.screenXForTick(
|
|
leading ? start : start + record.duration,
|
|
viewport,
|
|
);
|
|
final down = Offset(x + (leading ? 1 : -1), 60);
|
|
expect(
|
|
c.beginDrag(viewport: viewport, position: down, trimHitExtent: 6),
|
|
isTrue,
|
|
);
|
|
expect(c.isTrimming, isTrue);
|
|
// This tick cannot map exactly through a 1/3 speed section.
|
|
final delta = (second + 1) * (extend ? 1 : -1);
|
|
final target = down.translate(
|
|
(leading ? -delta : delta) * c.camera.pixelsPerTick,
|
|
0,
|
|
);
|
|
c.updateDrag(viewport: viewport, position: target);
|
|
expect(c.dragRejection, isNull);
|
|
final prepared = c.project(viewport).version;
|
|
expect(
|
|
prepared.kernelVersion.query().element(clip).duration,
|
|
record.duration + delta,
|
|
);
|
|
expect(c.version, same(base));
|
|
expect(c.finishDrag(viewport: viewport, position: target), isTrue);
|
|
c.undo();
|
|
expect(c.version, same(base));
|
|
c.redo();
|
|
expect(c.version, same(prepared));
|
|
},
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
for (final leading in [true, false]) {
|
|
testWidgets(
|
|
'trim past ${leading ? 'left' : 'right'} viewport edge keeps its preview and commits',
|
|
(tester) async {
|
|
final c = fixture(1);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 120,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
edgeScrollExtent: 0,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final base = c.version;
|
|
final clip = base.kernelVersion.query().elementById(ElementId('clip'))!;
|
|
final gesture = await tester.startGesture(
|
|
Offset(leading ? 201 : 299, 60),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
await gesture.moveTo(Offset(leading ? 190 : 310, 60));
|
|
await tester.pump();
|
|
expect(c.isTrimming, isTrue);
|
|
await gesture.moveTo(Offset(leading ? -20 : 820, 60));
|
|
await tester.pump();
|
|
expect(c.dragRejection, isNull);
|
|
final prepared = c.project(viewport).version;
|
|
expect(prepared, isNot(same(base)));
|
|
expect(
|
|
prepared.kernelVersion.query().element(clip).duration,
|
|
(leading ? 15 : 25) * second,
|
|
);
|
|
await gesture.up();
|
|
expect(c.version, same(prepared));
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
}
|
|
|
|
for (final leading in [true, false]) {
|
|
testWidgets(
|
|
'${leading ? 'leading' : 'trailing'} trim keeps scrolling beyond the viewport',
|
|
(tester) async {
|
|
final c = fixture(1);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 120,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
c.setCamera(
|
|
TimelineCamera(
|
|
baseTick: (leading ? 18 : 12) * second,
|
|
pixelsPerTick: (leading ? 100 : 40) / second,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
final clip = c.version.kernelVersion.query().elementById(
|
|
ElementId('clip'),
|
|
)!;
|
|
final gesture = await tester.startGesture(
|
|
Offset(leading ? 201 : 719, 60),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
await gesture.moveTo(Offset(leading ? -20 : 820, 60));
|
|
await tester.pump();
|
|
expect(c.isTrimming, isTrue);
|
|
final beforeCamera = c.camera.baseTick;
|
|
final beforeDuration = c
|
|
.project(viewport)
|
|
.version
|
|
.kernelVersion
|
|
.query()
|
|
.element(clip)
|
|
.duration;
|
|
await tester.pump(const Duration(milliseconds: 250));
|
|
expect(
|
|
c.camera.baseTick,
|
|
leading ? lessThan(beforeCamera) : greaterThan(beforeCamera),
|
|
);
|
|
expect(c.dragRejection, isNull);
|
|
final prepared = c.project(viewport).version;
|
|
expect(
|
|
prepared.kernelVersion.query().element(clip).duration,
|
|
greaterThan(beforeDuration),
|
|
);
|
|
await gesture.up();
|
|
expect(c.version, same(prepared));
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
}
|
|
|
|
for (final leading in [true, false]) {
|
|
testWidgets(
|
|
'${leading ? 'left' : 'right'} edge trim pans the composed timeline viewport',
|
|
(tester) async {
|
|
final c = fixture(1);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 160,
|
|
child: TimelineViewport(
|
|
controller: c,
|
|
leadingPadding: 16,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
c.setCamera(
|
|
TimelineCamera(
|
|
baseTick: (leading ? 18 : 12) * second,
|
|
pixelsPerTick: (leading ? 100 : 40) / second,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
final initialEnd = c.contentEndTick;
|
|
final origin = tester.getTopLeft(
|
|
find.byType(TimelineInteractionRegion).last,
|
|
);
|
|
final gesture = await tester.startGesture(
|
|
origin + Offset(leading ? 201 : 719, 60),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
await gesture.moveTo(origin + Offset(leading ? -20 : 810, 60));
|
|
await tester.pump();
|
|
expect(c.isTrimming, isTrue);
|
|
final before = c.camera.baseTick;
|
|
await tester.pump(const Duration(milliseconds: 250));
|
|
expect(
|
|
c.camera.baseTick,
|
|
leading ? lessThan(before) : greaterThan(before),
|
|
);
|
|
if (!leading) {
|
|
for (var frame = 0; frame < 40; frame++) {
|
|
await tester.pump(const Duration(milliseconds: 50));
|
|
}
|
|
expect(
|
|
c.camera.baseTick,
|
|
greaterThan(21 * second),
|
|
reason: 'Trimming beyond the original end must extend navigation',
|
|
);
|
|
}
|
|
expect(c.dragRejection, isNull);
|
|
final prepared = c.project(viewport).version;
|
|
if (!leading) {
|
|
expect(c.contentEndTick, greaterThan(initialEnd));
|
|
}
|
|
await gesture.up();
|
|
expect(c.isTrimming, isFalse);
|
|
expect(c.version, same(prepared));
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
}
|
|
|
|
testWidgets(
|
|
'shortening the last clip does not move a stationary trim pointer',
|
|
(tester) async {
|
|
final c = fixture(1);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 160,
|
|
child: TimelineViewport(
|
|
controller: c,
|
|
leadingPadding: 16,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
c.setCamera(
|
|
TimelineCamera(baseTick: 30 * second, pixelsPerTick: 40 / second),
|
|
);
|
|
await tester.pump();
|
|
final initialCamera = c.camera.baseTick;
|
|
final contentViewport = TimelineViewportRect(width: 784, height: 160);
|
|
final rightEdge = c.camera.screenXForTick(30 * second, contentViewport);
|
|
final origin = tester.getTopLeft(
|
|
find.byType(TimelineInteractionRegion).last,
|
|
);
|
|
final gesture = await tester.startGesture(
|
|
origin + Offset(rightEdge - 1, 60),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
await gesture.moveBy(const Offset(-12, 0));
|
|
await tester.pump();
|
|
expect(c.isTrimming, isTrue);
|
|
final clip = c.version.kernelVersion.query().elementById(
|
|
ElementId('clip'),
|
|
)!;
|
|
final firstDuration = c
|
|
.project(contentViewport)
|
|
.version
|
|
.kernelVersion
|
|
.query()
|
|
.element(clip)
|
|
.duration;
|
|
expect(firstDuration, lessThan(10 * second));
|
|
expect(c.navigationContentEndTick, 30 * second);
|
|
expect(
|
|
(10 * second - firstDuration) / second,
|
|
closeTo(12 / (c.camera.pixelsPerTick * second), 0.06),
|
|
);
|
|
await tester.pump(const Duration(milliseconds: 250));
|
|
final laterDuration = c
|
|
.project(contentViewport)
|
|
.version
|
|
.kernelVersion
|
|
.query()
|
|
.element(clip)
|
|
.duration;
|
|
expect(laterDuration, firstDuration);
|
|
expect(c.camera.baseTick, initialCamera);
|
|
await gesture.up();
|
|
await tester.pump();
|
|
expect(
|
|
c.version.kernelVersion.query().element(clip).duration,
|
|
firstDuration,
|
|
);
|
|
expect(c.navigationContentEndTick, c.contentEndTick);
|
|
expect(c.navigationContentEndTick, lessThan(30 * second));
|
|
expect(c.camera.baseTick, lessThan(initialCamera));
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
'trim coalesces pointer bursts and commits the final unpainted position',
|
|
(tester) async {
|
|
final c = connectedFixture(gap: false);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 120,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
edgeScrollExtent: 0,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final gesture = await tester.startGesture(
|
|
const Offset(99, 105),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
await gesture.moveTo(const Offset(90, 105));
|
|
await tester.pump();
|
|
expect(c.isTrimming, isTrue);
|
|
var changes = 0;
|
|
c.addListener(() => changes++);
|
|
var inspected = 0;
|
|
c.editingChanges.addListener(() => inspected++);
|
|
for (var x = 89; x >= 75; x--) {
|
|
await gesture.moveTo(Offset(x.toDouble(), 105));
|
|
}
|
|
expect(
|
|
changes,
|
|
0,
|
|
reason: 'A burst must prepare at most one preview per display frame',
|
|
);
|
|
await tester.pump();
|
|
expect(changes, 1);
|
|
expect(
|
|
inspected,
|
|
0,
|
|
reason: 'Private trim geometry does not change inspected properties',
|
|
);
|
|
await gesture.moveTo(const Offset(70, 105));
|
|
await gesture.up();
|
|
await tester.pump();
|
|
expect(c.isTrimming, isFalse);
|
|
expect(
|
|
inspected,
|
|
greaterThan(0),
|
|
reason: 'The commit must update inspected properties',
|
|
);
|
|
final query = c.version.kernelVersion.query();
|
|
expect(
|
|
query.element(query.elementById(ElementId('c'))!).duration,
|
|
71 * second ~/ 10,
|
|
);
|
|
final committed = c.version;
|
|
await tester.pump();
|
|
expect(
|
|
c.version,
|
|
same(committed),
|
|
reason: 'No queued preview may run after publication',
|
|
);
|
|
},
|
|
);
|
|
|
|
testWidgets('trailing pointer trim hands a removed anchor to the next clip', (
|
|
tester,
|
|
) async {
|
|
final c = connectedFixture(gap: false, childAnchorSeconds: 4);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 120,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
edgeScrollExtent: 0,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final base = c.version;
|
|
final a = base.kernelVersion.query().elementById(ElementId('a'))!;
|
|
final child = base.kernelVersion.query().elementById(ElementId('c'))!;
|
|
final frame = c.project(viewport);
|
|
final index = List.generate(
|
|
frame.length,
|
|
(i) => i,
|
|
).firstWhere((i) => frame.identityAt(i) == a);
|
|
final bounds = c.presentationBoundsAt(frame, index);
|
|
final gesture = await tester.startGesture(
|
|
Offset(bounds.right - 1, bounds.center.dy),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
await gesture.moveBy(Offset(-3 * c.camera.pixelsPerTick * second, 0));
|
|
await tester.pump();
|
|
expect(c.isTrimming, isTrue);
|
|
expect(c.dragRejection, isNull);
|
|
final prepared = c.project(viewport).version;
|
|
final preview = prepared.kernelVersion.query();
|
|
expect(
|
|
preview.element(preview.connectionForTarget(child)!.anchor).id,
|
|
ElementId('b'),
|
|
);
|
|
expect(preview.absoluteStart(child), 4 * second);
|
|
expect(c.version, same(base));
|
|
await gesture.up();
|
|
expect(c.version, same(prepared));
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
for (final leading in [true, false]) {
|
|
testWidgets(
|
|
'waveform retained region is stable during ${leading ? 'leading' : 'trailing'} trim',
|
|
(tester) async {
|
|
final c = connectedFixture(gap: false);
|
|
final waveforms = _TrimWaveforms();
|
|
addTearDown(c.dispose);
|
|
addTearDown(waveforms.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 120,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
edgeScrollExtent: 0,
|
|
child: TimelineView(controller: c, waveforms: waveforms),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
List<(Offset, Offset)> retainedBars() {
|
|
final canvas = _TrimWaveCanvas();
|
|
tester
|
|
.widget<CustomPaint>(
|
|
find.descendant(
|
|
of: find.byType(TimelineView),
|
|
matching: find.byType(CustomPaint),
|
|
),
|
|
)
|
|
.painter!
|
|
.paint(canvas, const Size(800, 120));
|
|
return canvas.bars
|
|
.where((bar) => bar.$1.dx > 60 && bar.$1.dx < 80)
|
|
.toList();
|
|
}
|
|
|
|
final before = retainedBars();
|
|
expect(before, isNotEmpty);
|
|
final base = c.version;
|
|
final start = leading ? 1.0 : 99.0;
|
|
final gesture = await tester.startGesture(
|
|
Offset(start, 105),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
for (final delta
|
|
in leading
|
|
? [0.5, 1.0, 1.5, 2.5, 10.5, 51.5]
|
|
: [0.5, 1.0, 1.5, 2.5, 10.5]) {
|
|
await gesture.moveTo(Offset(start + (leading ? delta : -delta), 105));
|
|
await tester.pump();
|
|
expect(c.dragRejection, isNull);
|
|
expect(
|
|
retainedBars(),
|
|
before,
|
|
reason: 'retained waveform moved after $delta px trim',
|
|
);
|
|
}
|
|
await gesture.cancel();
|
|
await tester.pump();
|
|
expect(c.version, same(base));
|
|
expect(retainedBars(), before);
|
|
},
|
|
);
|
|
}
|
|
for (final gap in [false, true]) {
|
|
testWidgets(
|
|
'connected leading trim crosses its anchor boundary, gap=$gap',
|
|
(tester) async {
|
|
final c = connectedFixture(gap: gap);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 120,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
edgeScrollExtent: 0,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final base = c.version;
|
|
final clip = base.kernelVersion.query().elementById(ElementId('c'))!;
|
|
final gesture = await tester.startGesture(
|
|
const Offset(1, 105),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
for (final tenth in [39, 40, 41, 49, 50, 51, 60, 45, 60]) {
|
|
await gesture.moveTo(Offset(1 + tenth.toDouble(), 105));
|
|
await tester.pump();
|
|
expect(c.isTrimming, isTrue);
|
|
expect(
|
|
c.dragRejection,
|
|
isNull,
|
|
reason: 'leading edge at ${tenth / 10}s',
|
|
);
|
|
final q = c.project(viewport).version.kernelVersion.query();
|
|
expect(q.absoluteStart(clip), tenth * second ~/ 10);
|
|
expect(q.absoluteStart(clip) + q.element(clip).duration, 10 * second);
|
|
expect(q.element(clip).sourceStart, tenth * second ~/ 10);
|
|
expect(c.version, same(base));
|
|
if (tenth > 50) {
|
|
expect(
|
|
q.element(q.connectionForTarget(clip)!.anchor).id,
|
|
ElementId('b'),
|
|
);
|
|
}
|
|
}
|
|
final prepared = c.project(viewport).version;
|
|
await gesture.up();
|
|
expect(c.version, same(prepared));
|
|
c.undo();
|
|
expect(c.version, same(base));
|
|
c.redo();
|
|
expect(c.version, same(prepared));
|
|
c.undo();
|
|
final cancelled = await tester.startGesture(
|
|
const Offset(1, 105),
|
|
kind: PointerDeviceKind.mouse,
|
|
);
|
|
await cancelled.moveTo(const Offset(61, 105));
|
|
await tester.pump();
|
|
expect(c.project(viewport).version, isNot(same(base)));
|
|
await cancelled.cancel();
|
|
await tester.pump();
|
|
expect(c.version, same(base));
|
|
expect(c.project(viewport).version, same(base));
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
}
|
|
for (final kind in [PointerDeviceKind.mouse, PointerDeviceKind.touch]) {
|
|
for (final divisor in [1, 2]) {
|
|
for (final leading in [false, true]) {
|
|
testWidgets(
|
|
'media edge clamps: $kind, speed 1/$divisor, leading $leading',
|
|
(tester) async {
|
|
final c = fixture(divisor);
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Align(
|
|
alignment: Alignment.topLeft,
|
|
child: SizedBox(
|
|
width: 800,
|
|
height: 120,
|
|
child: TimelineInteractionRegion(
|
|
controller: c,
|
|
edgeScrollExtent: 0,
|
|
child: TimelineView(controller: c),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final base = c.version;
|
|
final clip = base.kernelVersion.query().elementById(
|
|
ElementId('clip'),
|
|
)!;
|
|
final startX = leading ? 201.0 : 200 + 100.0 * divisor - 1;
|
|
final gesture = await tester.startGesture(
|
|
Offset(startX, 60),
|
|
kind: kind,
|
|
);
|
|
await gesture.moveTo(Offset(leading ? 20 : 790, 60));
|
|
await tester.pump();
|
|
final prepared = c.project(viewport).version;
|
|
final duration = (leading ? 15 : 25) * divisor * second;
|
|
expect(c.dragRejection, isNull);
|
|
expect(
|
|
prepared.kernelVersion.query().element(clip).duration,
|
|
duration,
|
|
);
|
|
expect(c.version, same(base));
|
|
await gesture.up();
|
|
expect(c.version, same(prepared));
|
|
final q = c.version.kernelVersion.query();
|
|
expect(q.element(clip).sourceStart, (leading ? 0 : 5) * second);
|
|
expect(
|
|
q.element(clip).sourceDuration,
|
|
(leading ? 15 : 25) * second,
|
|
);
|
|
c.undo();
|
|
expect(c.version, same(base));
|
|
c.redo();
|
|
expect(c.version, same(prepared));
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class _TrimWaveforms extends ChangeNotifier implements TimelineWaveforms {
|
|
final waveform = TimelineWaveform(
|
|
sampleRate: 100,
|
|
frameCount: 1000,
|
|
levels: [
|
|
TimelineWaveformLevel(
|
|
samplesPerBucket: 1,
|
|
channels: [
|
|
[
|
|
for (var i = 0; i < 1000; i++) ...[
|
|
-((i ~/ 30 % 7 + 1) / 8),
|
|
(i ~/ 30 % 7 + 1) / 8,
|
|
0.1,
|
|
],
|
|
],
|
|
],
|
|
),
|
|
],
|
|
);
|
|
@override
|
|
void beginFrame() {}
|
|
@override
|
|
bool hasAudioFor(ElementRecord element) => true;
|
|
@override
|
|
TimelineWaveform? waveformFor(ElementRecord element) => waveform;
|
|
@override
|
|
void endFrame() {}
|
|
}
|
|
|
|
class _TrimOutlineCanvas extends TestRecordingCanvas {
|
|
_TrimOutlineCanvas(this.color);
|
|
final Color color;
|
|
final closedOutlines = <RRect>[];
|
|
final edges = <Path>[];
|
|
|
|
@override
|
|
void drawDRRect(RRect outer, RRect inner, Paint paint) {
|
|
if (paint.color.toARGB32() == color.toARGB32()) closedOutlines.add(outer);
|
|
super.drawDRRect(outer, inner, paint);
|
|
}
|
|
|
|
@override
|
|
void drawPath(Path path, Paint paint) {
|
|
if (paint.color.toARGB32() == color.toARGB32() &&
|
|
paint.style == PaintingStyle.stroke) {
|
|
edges.add(Path.from(path));
|
|
}
|
|
super.drawPath(path, paint);
|
|
}
|
|
}
|
|
|
|
class _TrimWaveCanvas extends TestRecordingCanvas {
|
|
final bars = <(Offset, Offset)>[];
|
|
@override
|
|
void drawLine(Offset p1, Offset p2, Paint paint) {
|
|
if (paint.color.toARGB32() ==
|
|
const TimelineThemeData.dark().audioAccentColor.toARGB32()) {
|
|
bars.add((p1, p2));
|
|
}
|
|
super.drawLine(p1, p2, paint);
|
|
}
|
|
}
|
|
|
|
TimelineViewController fixture(int divisor, {bool explicitRetime = false}) {
|
|
final kernel = TimelineKernel.importDto(
|
|
TimelineDto(
|
|
id: SequenceId('bounded'),
|
|
format: TimelineFormat.fps24,
|
|
primaryStorylineId: StorylineId('p'),
|
|
storylines: [
|
|
StorylineDto(
|
|
id: StorylineId('p'),
|
|
elementIds: [ElementId('preroll'), ElementId('clip')],
|
|
),
|
|
],
|
|
elements: [
|
|
ElementDto(
|
|
id: ElementId('preroll'),
|
|
structure: ElementStructure.gap,
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.seconds(20),
|
|
),
|
|
duration: RationalTime.seconds(20),
|
|
),
|
|
ElementDto(
|
|
id: ElementId('clip'),
|
|
structure: ElementStructure.content,
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.seconds(5),
|
|
duration: RationalTime.seconds(10),
|
|
),
|
|
mediaRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.seconds(30),
|
|
),
|
|
duration: RationalTime.seconds(10 * divisor),
|
|
retimeSegments: explicitRetime
|
|
? [
|
|
RetimeSegmentDto(
|
|
projectDuration: RationalTime.seconds(10 * divisor),
|
|
sourceStart: RationalTime.seconds(5),
|
|
sourceDelta: RationalTime.seconds(10),
|
|
),
|
|
]
|
|
: const [],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
return controllerFor(kernel);
|
|
}
|
|
|
|
TimelineViewController connectedFixture({
|
|
required bool gap,
|
|
int childAnchorSeconds = 0,
|
|
}) => controllerFor(
|
|
TimelineKernel.importDto(
|
|
TimelineDto(
|
|
id: SequenceId('connected-trim'),
|
|
format: TimelineFormat.fps24,
|
|
primaryStorylineId: StorylineId('p'),
|
|
storylines: [
|
|
StorylineDto(
|
|
id: StorylineId('p'),
|
|
elementIds: [
|
|
ElementId('a'),
|
|
if (gap) ElementId('gap'),
|
|
ElementId('b'),
|
|
],
|
|
),
|
|
],
|
|
elements: [
|
|
for (final (id, duration) in [
|
|
('a', gap ? 4 : 5),
|
|
if (gap) ('gap', 1),
|
|
('b', 5),
|
|
('c', 10),
|
|
])
|
|
ElementDto(
|
|
id: ElementId(id),
|
|
structure: id == 'gap'
|
|
? ElementStructure.gap
|
|
: ElementStructure.content,
|
|
duration: RationalTime.seconds(duration),
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.seconds(duration),
|
|
),
|
|
mediaRange: id == 'gap'
|
|
? null
|
|
: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.seconds(20),
|
|
),
|
|
),
|
|
],
|
|
connections: [
|
|
ConnectionDto(
|
|
id: ConnectionId('audio-link'),
|
|
side: ConnectionSide.below,
|
|
anchorId: ElementId('a'),
|
|
targetId: ElementId('c'),
|
|
anchorTime: RationalTime.seconds(childAnchorSeconds),
|
|
targetTime: RationalTime.zero,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
TimelineViewController controllerFor(TimelineKernel kernel) {
|
|
final primary = kernel.current.query().primaryStoryline;
|
|
const domain = LayoutDomainId('main');
|
|
final projection = const TimelineLayoutSceneBuilder()
|
|
.projectDefinitionWithMedia(
|
|
media: TimelineLayoutMediaIndex.build(
|
|
version: kernel.current,
|
|
classify: (element) => element.id == ElementId('c')
|
|
? LayoutMediaLeafClass.audioOnly
|
|
: LayoutMediaLeafClass.nonAudio,
|
|
),
|
|
definition: primary,
|
|
geometry: (_, _, _) => (height: 40, domain: domain),
|
|
);
|
|
final engine = TimelineLayoutEngine(kernel: kernel);
|
|
engine.buildComponents(
|
|
kernel: kernel,
|
|
components: TimelineLayoutComponents.build(
|
|
semantic: projection,
|
|
expanded: const [],
|
|
resolve: (_, _, _, _) => const [],
|
|
),
|
|
policy: LayoutPolicy(
|
|
version: 1,
|
|
stacks: [
|
|
for (final side in ConnectionSide.values)
|
|
LayoutStackPolicy(
|
|
stack: LayoutStackKey(scope: primary, side: side),
|
|
primaryBoundary: side == ConnectionSide.above ? 40 : 80,
|
|
domains: const [domain],
|
|
innerGap: 10,
|
|
bodyGap: 10,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
var id = 0;
|
|
return TimelineViewController.editable(
|
|
engine: engine,
|
|
geometry: TimelineViewportGeometry(primaryTop: 40, primaryHeight: 40),
|
|
camera: TimelineCamera(baseTick: 0, pixelsPerTick: 10 / second),
|
|
createConnectionId: () => ConnectionId('c-${id++}'),
|
|
createElementId: () => ElementId('e-${id++}'),
|
|
);
|
|
}
|