81 lines
2.5 KiB
Dart
81 lines
2.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:kouyu_english/core/app_state.dart';
|
||
import 'package:kouyu_english/widgets/lexicon_lookup.dart';
|
||
|
||
void main() {
|
||
test('lookup prefers the longest reviewed phrase', () {
|
||
final entry = findCourseLexicon('Nice to meet you, Mia.');
|
||
|
||
expect(entry, isNotNull);
|
||
expect(entry!.word, 'Nice to meet you');
|
||
expect(entry.meaning, isNotEmpty);
|
||
});
|
||
|
||
test('lookup includes reviewed vocabulary from split segments', () {
|
||
final entry = findCourseLexicon("It's three o'clock.");
|
||
|
||
expect(entry, isNotNull);
|
||
expect(entry!.word, "It's three o'clock.");
|
||
});
|
||
|
||
test('unknown text has no invented dictionary entry', () {
|
||
expect(findCourseLexicon('supercalifragilistic'), isNull);
|
||
});
|
||
|
||
test('lookup does not match substrings within longer words', () {
|
||
expect(findCourseLexicon('often'), isNull);
|
||
expect(findCourseLexicon('sentence'), isNull);
|
||
expect(findCourseLexicon('teacher'), isNull);
|
||
});
|
||
|
||
test('lookup matches reviewed vocabulary with punctuation and apostrophes', () {
|
||
expect(findCourseLexicon('tea'), isNotNull);
|
||
expect(findCourseLexicon('tea.'), isNotNull);
|
||
expect(findCourseLexicon("What's this?"), isNotNull);
|
||
expect(findCourseLexicon('What’s this?'), isNotNull);
|
||
});
|
||
|
||
testWidgets('cached temporary definition appears when lookup opens', (
|
||
tester,
|
||
) async {
|
||
final state = AppState()
|
||
..cacheTemporaryDefinition(query: 'library', definition: '图书馆');
|
||
await tester.pumpWidget(
|
||
MaterialApp(
|
||
home: Builder(
|
||
builder: (context) => ElevatedButton(
|
||
onPressed: () => showLexiconLookup(
|
||
context,
|
||
state: state,
|
||
initialText: 'library',
|
||
),
|
||
child: const Text('查词'),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
await tester.tap(find.text('查词'));
|
||
await tester.pumpAndSettle();
|
||
|
||
expect(find.textContaining('待审核临时释义'), findsOneWidget);
|
||
expect(find.textContaining('图书馆'), findsOneWidget);
|
||
});
|
||
|
||
testWidgets('selected arbitrary text exposes a dynamic lookup action', (
|
||
tester,
|
||
) async {
|
||
await tester.pumpWidget(
|
||
MaterialApp(
|
||
home: Scaffold(body: LexiconText('mystery widget', state: AppState())),
|
||
),
|
||
);
|
||
|
||
expect(find.byType(SelectableText), findsOneWidget);
|
||
await tester.longPress(find.text('mystery widget'));
|
||
await tester.pumpAndSettle();
|
||
|
||
expect(find.text('查询已选文本'), findsOneWidget);
|
||
});
|
||
}
|