Gitea CI / Check code and tests (pull_request) Failing after 8s
Gitea CI / Build Android APK (pull_request) Skipped
Gitea CI / Build Windows x64 app (pull_request) Skipped
Gitea CI / Audit and package Windows x64 (pull_request) Skipped
Gitea CI / Assemble and validate CI artifacts (pull_request) Skipped
Gitea CI / Gitea CI passed (pull_request) Failing after 1s
280 lines
9.1 KiB
Dart
280 lines
9.1 KiB
Dart
import 'dart:ui' as ui;
|
|
|
|
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/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
final viewport = TimelineViewportRect(width: 240, height: 100);
|
|
|
|
void main() {
|
|
testWidgets(
|
|
'opened compound paints full clips and dims outside source range',
|
|
(tester) async {
|
|
final f = Fixture();
|
|
final c = f.controller;
|
|
addTearDown(c.dispose);
|
|
await tester.pumpWidget(surface(c));
|
|
const normal = 0x4e82d8ff;
|
|
// Probe the body below the 18px name header, outside the name text.
|
|
final outside = await pixel(tester, 20, 58);
|
|
expect(outside, isNot(normal));
|
|
expect(
|
|
outside,
|
|
isNot(0x15171aff),
|
|
reason: 'outside content is not removed',
|
|
);
|
|
expect(await pixel(tester, 80, 58), normal);
|
|
expect(await pixel(tester, 160, 58), outside);
|
|
// The connected body crosses the same source boundary without being cut.
|
|
expect(await pixel(tester, 110, 28), normal);
|
|
expect(await pixel(tester, 160, 28), outside);
|
|
final hit = c.hitTest(
|
|
viewport: viewport,
|
|
position: const Offset(160, 50),
|
|
);
|
|
expect(hit!.identity, f.child);
|
|
expect(hit.bounds.width, 200);
|
|
final original = f.kernel.current;
|
|
c.panBy(horizontalPixels: 20, verticalPixels: 5);
|
|
await tester.pump();
|
|
expect(await pixel(tester, 60, 53), normal);
|
|
expect(await pixel(tester, 140, 53), outside);
|
|
expect(f.kernel.current, same(original));
|
|
expect(tester.takeException(), isNull);
|
|
},
|
|
);
|
|
|
|
testWidgets('theme controls dimming and outer edits follow joint history', (
|
|
tester,
|
|
) async {
|
|
final f = Fixture();
|
|
final c = f.controller;
|
|
addTearDown(c.dispose);
|
|
final theme = const TimelineThemeData.dark().copyWith(
|
|
outsideSourceRangeOverlayColor: const Color(0xffff0000),
|
|
);
|
|
await tester.pumpWidget(surface(c, theme: theme));
|
|
expect(await pixel(tester, 160, 58), 0xff0000ff);
|
|
final preview = const LayoutIntervalEdit().preview(
|
|
kernel: f.kernel,
|
|
engine: f.engine,
|
|
projection: f.engine.currentComponents!.semanticProjection,
|
|
edit: (tx) => tx.setContainerView(
|
|
f.box,
|
|
TimeRange(
|
|
start: RationalTime.seconds(1),
|
|
duration: RationalTime.seconds(8),
|
|
),
|
|
),
|
|
);
|
|
final original = c.version;
|
|
expect(c.effectiveSourceRange, (start: ticks(2), end: ticks(6)));
|
|
preview.commit();
|
|
c.synchronize();
|
|
await tester.pump();
|
|
expect(c.effectiveSourceRange, (start: ticks(1), end: ticks(9)));
|
|
expect(await pixel(tester, 160, 58), 0x4e82d8ff);
|
|
c.undo();
|
|
await tester.pump();
|
|
expect(c.version, same(original));
|
|
expect(await pixel(tester, 160, 58), 0xff0000ff);
|
|
c.redo();
|
|
await tester.pump();
|
|
expect(await pixel(tester, 160, 58), 0x4e82d8ff);
|
|
expect(f.kernel.current.query().element(f.child).duration, ticks(10));
|
|
});
|
|
|
|
test(
|
|
'readonly provenance rejects a different definition and stale origin',
|
|
() {
|
|
final f = Fixture();
|
|
addTearDown(f.controller.dispose);
|
|
expect(
|
|
() => TimelineViewController(
|
|
version: f.engine.current!,
|
|
storyline: f.kernel.current.query().primaryStoryline,
|
|
openedContainer: f.box,
|
|
geometry: f.controller.geometry,
|
|
camera: f.controller.camera,
|
|
),
|
|
throwsStateError,
|
|
);
|
|
final tx = f.kernel.beginTransaction();
|
|
tx.erase(storyline: f.kernel.current.query().primaryStoryline, start: 0);
|
|
final removed = tx.finishPreview();
|
|
expect(
|
|
() => const TimelineLayoutSceneBuilder().updateProjection(
|
|
base: f.engine.currentComponents!.semanticProjection,
|
|
update: TimelineLayoutUpdate.between(
|
|
kernel: f.kernel,
|
|
previousVersion: f.kernel.current,
|
|
version: removed,
|
|
),
|
|
),
|
|
throwsStateError,
|
|
);
|
|
expect(f.controller.effectiveSourceRange, (
|
|
start: ticks(2),
|
|
end: ticks(6),
|
|
));
|
|
},
|
|
);
|
|
|
|
test('source-range theme token copies, interpolates and compares', () {
|
|
const a = TimelineThemeData.dark();
|
|
final b = a.copyWith(
|
|
outsideSourceRangeOverlayColor: const Color(0xff00ff00),
|
|
);
|
|
expect(a.copyWith(), a);
|
|
expect(a, isNot(b));
|
|
expect(
|
|
a.lerp(b, 0.5).outsideSourceRangeOverlayColor,
|
|
Color.lerp(
|
|
a.outsideSourceRangeOverlayColor,
|
|
b.outsideSourceRangeOverlayColor,
|
|
0.5,
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
int ticks(int seconds) => seconds * TimelineClock.ticksPerSecond;
|
|
|
|
Widget surface(TimelineViewController controller, {TimelineThemeData? theme}) =>
|
|
Directionality(
|
|
textDirection: TextDirection.ltr,
|
|
child: Center(
|
|
child: SizedBox(
|
|
width: 240,
|
|
height: 100,
|
|
child: TimelineView(controller: controller, theme: theme),
|
|
),
|
|
),
|
|
);
|
|
|
|
Future<int?> pixel(WidgetTester tester, int x, int y) async {
|
|
final boundary = tester.renderObject<RenderRepaintBoundary>(
|
|
find.descendant(
|
|
of: find.byType(TimelineView),
|
|
matching: find.byType(RepaintBoundary),
|
|
),
|
|
);
|
|
return tester.runAsync(() async {
|
|
final image = await boundary.toImage(pixelRatio: 1);
|
|
final bytes = (await image.toByteData(format: ui.ImageByteFormat.rawRgba))!;
|
|
final value = bytes.getUint32((y * image.width + x) * 4);
|
|
image.dispose();
|
|
return value;
|
|
});
|
|
}
|
|
|
|
final class Fixture {
|
|
Fixture() {
|
|
kernel = TimelineKernel.importDto(
|
|
TimelineDto(
|
|
id: SequenceId('scene'),
|
|
format: TimelineFormat.fps24,
|
|
primaryStorylineId: StorylineId('primary'),
|
|
storylines: [
|
|
StorylineDto(
|
|
id: StorylineId('primary'),
|
|
elementIds: [ElementId('box')],
|
|
),
|
|
StorylineDto(
|
|
id: StorylineId('inside'),
|
|
elementIds: [ElementId('child')],
|
|
),
|
|
],
|
|
elements: [
|
|
ElementDto(
|
|
id: ElementId('box'),
|
|
structure: ElementStructure.container,
|
|
containerStorylineId: StorylineId('inside'),
|
|
containerViewMode: ContainerViewMode.fixedRange,
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.seconds(2),
|
|
duration: RationalTime.seconds(4),
|
|
),
|
|
duration: RationalTime.seconds(4),
|
|
),
|
|
for (final (id, duration) in [('child', 10), ('connected', 4)])
|
|
ElementDto(
|
|
id: ElementId(id),
|
|
structure: ElementStructure.content,
|
|
sourceRange: TimeRange(
|
|
start: RationalTime.zero,
|
|
duration: RationalTime.seconds(duration),
|
|
),
|
|
duration: RationalTime.seconds(duration),
|
|
),
|
|
],
|
|
connections: [
|
|
ConnectionDto(
|
|
id: ConnectionId('link'),
|
|
anchorId: ElementId('child'),
|
|
targetId: ElementId('connected'),
|
|
anchorTime: RationalTime.seconds(5),
|
|
targetTime: RationalTime.zero,
|
|
side: ConnectionSide.above,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
final q = kernel.current.query();
|
|
box = q.elementById(ElementId('box'))!;
|
|
child = q.elementById(ElementId('child'))!;
|
|
final inside = q.storylineById(StorylineId('inside'))!;
|
|
const domain = LayoutDomainId('main');
|
|
final projection = const TimelineLayoutSceneBuilder()
|
|
.openContainerSceneWithMedia(
|
|
media: TimelineLayoutMediaIndex.build(
|
|
version: kernel.current,
|
|
classify: (_) => LayoutMediaLeafClass.nonAudio,
|
|
),
|
|
container: box,
|
|
geometry: (_, _, _) => (height: 20, domain: domain),
|
|
);
|
|
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: inside, side: side),
|
|
primaryBoundary: side == ConnectionSide.above ? 40 : 60,
|
|
innerGap: 10,
|
|
bodyGap: 10,
|
|
domains: const [domain],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
var serial = 0;
|
|
controller = TimelineViewController.editable(
|
|
engine: engine,
|
|
geometry: TimelineViewportGeometry(primaryTop: 40, primaryHeight: 20),
|
|
camera: TimelineCamera(
|
|
baseTick: 0,
|
|
pixelsPerTick: 20 / TimelineClock.ticksPerSecond,
|
|
),
|
|
createConnectionId: () => ConnectionId('new-link-${serial++}'),
|
|
createElementId: () => ElementId('new-clip-${serial++}'),
|
|
);
|
|
}
|
|
late final TimelineKernel kernel;
|
|
late final TimelineLayoutEngine engine;
|
|
late final TimelineViewController controller;
|
|
late final ElementHandle box, child;
|
|
}
|