64 lines
1.9 KiB
Dart
64 lines
1.9 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'note_list_harness.dart';
|
|
|
|
Future<void> _search(WidgetTester tester, String query) async {
|
|
await tester.enterText(find.byType(TextField), query);
|
|
// Filtering is debounced.
|
|
await tester.pump(const Duration(milliseconds: 400));
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
void main() {
|
|
late Directory notes;
|
|
|
|
setUp(() => notes = setUpNotes({
|
|
'root.md': '# root\n',
|
|
'work/plan.md': '# plan\n',
|
|
'work/deep/notes.md': '# notes\n',
|
|
'home/plan.md': '# plan\n',
|
|
}));
|
|
|
|
testWidgets('/folder terms filter by the start of the folder path',
|
|
(tester) async {
|
|
await pumpList(tester);
|
|
expect(listedNotes(tester), hasLength(4));
|
|
|
|
await _search(tester, '/work');
|
|
expect(listedNotes(tester)..sort(), ['notes', 'plan']);
|
|
|
|
await _search(tester, '/work/deep');
|
|
expect(listedNotes(tester), ['notes']);
|
|
|
|
await _search(tester, '/ho plan');
|
|
expect(listedNotes(tester), ['plan']);
|
|
|
|
await _search(tester, '/nowhere');
|
|
expect(listedNotes(tester), isEmpty);
|
|
});
|
|
|
|
testWidgets('Enter runs a command instead of creating a note',
|
|
(tester) async {
|
|
var tagToggles = 0;
|
|
await pumpList(tester, toggleTags: () => tagToggles++);
|
|
|
|
await _search(tester, ':tags');
|
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(tagToggles, 1);
|
|
expect(tester.widget<TextField>(find.byType(TextField)).controller!.text,
|
|
isEmpty);
|
|
expect(File('${notes.path}/tags.md').existsSync(), isFalse);
|
|
});
|
|
|
|
testWidgets('an unknown command does not create a note', (tester) async {
|
|
await pumpList(tester);
|
|
await _search(tester, ':nope');
|
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(File('${notes.path}/nope.md').existsSync(), isFalse);
|
|
});
|
|
}
|