Files
cutdex/test/localized_surfaces_test.dart
lingjhf 06f1c26681
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
Move editor UI into the app and release verified Core dependencies (#14)
2026-10-11 19:59:40 +00:00

212 lines
7.7 KiB
Dart

import 'package:cutdex/errors/app_failure.dart';
import 'package:cutdex/workspace/persistence/timeline_creation_names.dart';
import 'dart:io';
import 'package:cutdex/app/shells/phone_workspace_shell.dart';
import 'package:cutdex/app/shells/tablet_workspace_shell.dart';
import 'package:cutdex/features/assistant/composer_document.dart';
import 'package:cutdex/features/assistant/composer_suggestion_surface.dart';
import 'package:cutdex/l10n/l10n.dart';
import 'package:cutdex/workspace/media_color_interpretation.dart';
import 'package:cutdex/workspace/persistence/project_workspace.dart';
import 'package:cutdex/workspace/workspace_mode.dart';
import 'package:cutdex_native_flutter/cutdex_native_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Widget _localized(Locale locale, Widget child) => MaterialApp(
locale: locale,
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: Scaffold(body: child),
);
void main() {
for (final tablet in [false, true]) {
testWidgets(
'${tablet ? 'tablet' : 'phone'} navigation follows locale changes',
(tester) async {
Widget shell() => tablet
? TabletWorkspaceShell(
mode: WorkspaceMode.agent,
onModeChanged: (_) {},
navigation: const SizedBox(),
headerActions: const SizedBox(),
title: '',
integratedTitlebar: false,
agent: const SizedBox(),
editor: const SizedBox(),
)
: PhoneWorkspaceShell(
mode: WorkspaceMode.agent,
onModeChanged: (_) {},
navigation: const SizedBox(),
headerActions: const SizedBox(),
title: '',
integratedTitlebar: false,
agent: const SizedBox(),
editor: const SizedBox(),
);
for (final (locale, agent, cut) in [
(const Locale('en'), 'Agent', 'Cut'),
(const Locale('zh'), '助手', '剪辑'),
(const Locale('fr'), 'Assistant', 'Montage'),
]) {
await tester.pumpWidget(_localized(locale, shell()));
await tester.pumpAndSettle();
expect(find.text(agent), findsOneWidget);
expect(find.text(cut), findsOneWidget);
expect(tester.takeException(), isNull);
}
},
);
}
testWidgets('open reference menu follows locale without changing the draft', (
tester,
) async {
final controller = ComposerDocumentController();
addTearDown(controller.dispose);
Widget composer() => Center(
child: ComposerSuggestionSurface(
controller: controller,
projectId: 'project',
assets: const [],
timelines: const [],
width: 300,
onSend: () {},
builder: (_, focus) =>
TextField(controller: controller, focusNode: focus),
),
);
await tester.pumpWidget(_localized(const Locale('en'), composer()));
await tester.enterText(find.byType(TextField), '@missing');
await tester.pumpAndSettle();
expect(find.text('No options available'), findsOneWidget);
await tester.pumpWidget(_localized(const Locale('zh'), composer()));
await tester.pumpAndSettle();
expect(find.text('暂无可用选项'), findsOneWidget);
expect(controller.text, '@missing');
await tester.pumpWidget(const SizedBox());
});
test('subtitle languages localize names while preserving protocol codes', () {
final expected = {
'en': ['English', 'Japanese', 'Cantonese'],
'zh': ['英语', '日语', '粤语'],
'zh-Hant': ['英文', '日文', '粵語'],
'fr': ['anglais', 'japonais', 'cantonais'],
};
for (final locale in AppLocalizations.supportedLocales) {
final l10n = lookupAppLocalizations(locale);
final key = [locale.languageCode, ?locale.scriptCode].join('-');
if (expected[key] case final names?) {
expect(['en', 'ja', 'yue'].map(l10n.subtitleLanguageName), names);
}
for (final code in {
...m2m100LanguageNames.keys,
...subtitleNativeLanguageNames.keys,
}) {
expect(
l10n.subtitleLanguageName(code),
isNot(code),
reason: '$key:$code',
);
}
expect(l10n.subtitleLanguageName('auto'), l10n.autoDetect);
expect(l10n.subtitleLanguageName('none'), l10n.noTranslation);
expect(l10n.subtitleLanguageName('unknown-code'), 'unknown-code');
}
});
test('known exceptions translate without losing unknown diagnostic text', () {
final en = lookupAppLocalizations(const Locale('en'));
final zh = lookupAppLocalizations(const Locale('zh'));
expect(
en.errorMessage(
AppException(AppErrorCode.mediaReadFailed, diagnostic: 'Any wording'),
),
en.mediaReadFailed,
);
expect(
en.errorMessage(
AppException(
AppErrorCode.timelineRequired,
diagnostic: 'Different punctuation!',
),
),
en.timelineRequired,
);
expect(
en.errorMessage(
AppException(
AppErrorCode.resourceDownloadHttpFailed,
httpStatusCode: 503,
),
),
en.resourceDownloadHttpFailed('503'),
);
expect(
en.errorMessage(AppException(AppErrorCode.resourceChecksumFailed)),
en.resourceChecksumFailed,
);
expect(
zh.errorMessage(AppException(AppErrorCode.timelineMissing)),
zh.timelineMissing,
);
expect(en.errorMessage('Native error 123'), 'Native error 123');
final unknown = const FileSystemException(
'Native error 123',
'/missing.mov',
);
expect(en.errorMessage(unknown), unknown.toString());
expect(
zh.errorMessage(AppException(AppErrorCode.mediaReadFailed)),
'无法读取素材',
);
expect(
en.errorMessage('FormatException: diagnostic 123'),
'FormatException: diagnostic 123',
);
expect(RenderColorSpace.linearRec2020.label(zh), '线性 Rec.2020');
});
test('new sequence names follow the current language and saved names stay intact', () async {
final root = await Directory.systemTemp.createTemp(
'cutdex-localized-names-',
);
var l10n = lookupAppLocalizations(const Locale('en'));
TimelineCreationNames names() => TimelineCreationNames(
timeline: l10n.defaultTimelineName(1),
sequence: l10n.primarySequence,
storyline: l10n.primaryStoryline,
);
final workspace = ProjectWorkspace(creationNames: names());
addTearDown(() async {
await workspace.close();
await root.delete(recursive: true);
});
await workspace.open('${root.path}/Project.cutdex', name: 'My project');
final projectId = workspace.project!.info.id;
final originalId = (await workspace.project!.listTimelines()).first.id;
final original = await workspace.loadTimeline(projectId, originalId);
expect(original.name, 'Timeline 1');
expect(original.sequences.single.name, 'Main sequence');
expect(original.sequences.single.storylines.single.name, 'Main storyline');
l10n = lookupAppLocalizations(const Locale('zh'));
final timelines = await workspace.createTimeline(
'User-chosen name',
creationNames: names(),
);
final added = await workspace.loadTimeline(projectId, timelines.last.id);
expect(added.name, 'User-chosen name');
expect(added.sequences.single.name, '主序列');
expect(added.sequences.single.storylines.single.name, '主线');
final retained = await workspace.loadTimeline(projectId, originalId);
expect(retained.name, 'Timeline 1');
expect(retained.sequences.single.name, 'Main sequence');
});
}