Add the Flutter video editing application with project management, media import, timeline editing, preview, AI assistance, diagnostics and settings. Include shared UI and native host packages, platform runners, application tests and release tooling. Provide usage and contribution guides, the MIT license and third-party notices. Exclude local credentials, build outputs and validation data.
101 lines
3.7 KiB
Dart
101 lines
3.7 KiB
Dart
import 'package:cutdex/features/assistant/composer_document.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
const _media = ComposerReference(
|
|
kind: ComposerReferenceKind.media,
|
|
projectId: 'project',
|
|
id: 'media-1',
|
|
label: '片段.mp4',
|
|
);
|
|
|
|
void main() {
|
|
test('reference insertion adds one separating space and places the caret after it', () {
|
|
final atEnd = ComposerDocumentController(text: '看 @片段');
|
|
addTearDown(atEnd.dispose);
|
|
atEnd.insertReference(2, 5, _media);
|
|
expect(atEnd.text, '看 @片段.mp4 ');
|
|
expect(atEnd.selection.extentOffset, atEnd.text.length);
|
|
expect(atEnd.marks.single.end, atEnd.text.length - 1);
|
|
|
|
final beforeSpace = ComposerDocumentController(text: '@片段 后面');
|
|
addTearDown(beforeSpace.dispose);
|
|
beforeSpace.insertReference(0, 3, _media);
|
|
expect(beforeSpace.text, '@片段.mp4 后面');
|
|
expect(
|
|
beforeSpace.selection.extentOffset,
|
|
beforeSpace.marks.single.end + 1,
|
|
);
|
|
});
|
|
|
|
test('reference insertion, atomic deletion and undo/redo', () {
|
|
final controller = ComposerDocumentController(text: '看 @片段 后面');
|
|
addTearDown(controller.dispose);
|
|
controller.insertReference(2, 5, _media);
|
|
expect(controller.text, '看 @片段.mp4 后面');
|
|
expect(
|
|
controller.segments.map(
|
|
(segment) => switch (segment) {
|
|
ComposerText() => null,
|
|
ComposerReferenceSegment(:final value) => value.id,
|
|
},
|
|
),
|
|
[null, 'media-1', null],
|
|
);
|
|
|
|
final mark = controller.marks.single;
|
|
controller.value = controller.value.copyWith(
|
|
text: controller.text.replaceRange(mark.end - 1, mark.end, ''),
|
|
selection: TextSelection.collapsed(offset: mark.end - 1),
|
|
);
|
|
expect(controller.text, '看 后面');
|
|
expect(controller.marks, isEmpty);
|
|
controller.undoDocument();
|
|
expect(controller.text, '看 @片段.mp4 后面');
|
|
expect(controller.marks.single.reference.id, 'media-1');
|
|
controller.redoDocument();
|
|
expect(controller.marks, isEmpty);
|
|
});
|
|
|
|
test('caret and selection cannot split a reference', () {
|
|
final controller = ComposerDocumentController(text: 'a @m z');
|
|
addTearDown(controller.dispose);
|
|
controller.insertReference(2, 4, _media);
|
|
final mark = controller.marks.single;
|
|
controller.selection = TextSelection.collapsed(offset: mark.start + 1);
|
|
expect(controller.selection.extentOffset, mark.start);
|
|
controller.selection = TextSelection(
|
|
baseOffset: mark.start + 1,
|
|
extentOffset: mark.end + 1,
|
|
);
|
|
expect(controller.selection.start, mark.start);
|
|
expect(controller.selection.end, mark.end + 1);
|
|
});
|
|
|
|
test('Chinese composing range and plain paste remain text', () {
|
|
final controller = ComposerDocumentController();
|
|
addTearDown(controller.dispose);
|
|
controller.value = const TextEditingValue(
|
|
text: '拼',
|
|
selection: TextSelection.collapsed(offset: 1),
|
|
composing: TextRange(start: 0, end: 1),
|
|
);
|
|
expect(controller.value.composing, const TextRange(start: 0, end: 1));
|
|
controller.value = const TextEditingValue(
|
|
text: '图片.png',
|
|
selection: TextSelection.collapsed(offset: 6),
|
|
);
|
|
expect(controller.marks, isEmpty);
|
|
});
|
|
|
|
test('invalid reference blocks send until project is restored', () {
|
|
final controller = ComposerDocumentController(text: '@');
|
|
addTearDown(controller.dispose);
|
|
controller.insertReference(0, 1, _media);
|
|
controller.updateValidity((reference) => reference.projectId == 'other');
|
|
expect(controller.hasInvalidReferences, isTrue);
|
|
controller.updateValidity((reference) => reference.projectId == 'project');
|
|
expect(controller.hasInvalidReferences, isFalse);
|
|
});
|
|
}
|