Files
cutdex/test/composer_suggestions_test.dart
T
lingjhf 38ca180cf7
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
refactor(core): own editor UI and pin verified native releases
2026-10-12 03:20:29 +08:00

99 lines
2.7 KiB
Dart

import 'package:cutdex/features/assistant/composer_suggestions.dart';
import 'package:cutdex_core/project.dart';
import 'package:cutdex/l10n/app_localizations_en.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
test('all triggers appear at word boundaries but not in paths or email', () {
for (final trigger in ['@', '/', r'$']) {
final value = TextEditingValue(
text: 'hello $trigger片段',
selection: TextSelection.collapsed(offset: 'hello $trigger片段'.length),
);
final query = findComposerTrigger(value, const []);
expect(query?.trigger, trigger);
expect(query?.query, '片段');
}
for (final plain in ['foo@example.com', '/Users/name', r'price$100']) {
expect(
findComposerTrigger(
TextEditingValue(
text: plain,
selection: TextSelection.collapsed(offset: plain.length),
),
const [],
),
isNull,
);
}
const chinese = '看看@片段';
expect(
findComposerTrigger(
const TextEditingValue(
text: chinese,
selection: TextSelection.collapsed(offset: 5),
),
const [],
)?.query,
'片段',
);
expect(
findComposerTrigger(
const TextEditingValue(
text: '@p',
selection: TextSelection.collapsed(offset: 2),
composing: TextRange(start: 1, end: 2),
),
const [],
),
isNull,
);
});
test(
'built-in current-project options distinguish equal names and filter',
() {
final options = ComposerOptionCatalog.forTrigger(
'@',
l10n: AppLocalizationsEn(),
projectId: 'project',
assets: [
AssetDocument(
id: 'asset',
name: '片段',
storage: AssetStorage.external,
location: 'file:///tmp/a',
),
],
timelines: [
const TimelineSummary(id: 'timeline', name: '片段', revision: 1),
],
);
expect(options.length, 2);
expect(options.map((option) => option.subtitle).toSet().length, 2);
expect(filterComposerOptions(options, '片').length, 2);
expect(
ComposerOptionCatalog.forTrigger(
'/',
l10n: AppLocalizationsEn(),
projectId: 'project',
assets: const [],
timelines: const [],
),
isEmpty,
);
expect(
ComposerOptionCatalog.forTrigger(
r'$',
l10n: AppLocalizationsEn(),
projectId: 'project',
assets: const [],
timelines: const [],
),
isEmpty,
);
},
);
}