mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Add another test for FlattenedNotes
This commit is contained in:
54
test/flattened_notes_folder_large_test.dart
Normal file
54
test/flattened_notes_folder_large_test.dart
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:gitjournal/core/flattened_notes_folder.dart';
|
||||||
|
import 'package:gitjournal/core/notes_folder_fs.dart';
|
||||||
|
import 'package:gitjournal/core/note.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('Flattened Notes Folder Large Test', () {
|
||||||
|
Directory tempDir;
|
||||||
|
NotesFolderFS rootFolder;
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
tempDir = await Directory.systemTemp.createTemp('__flat_folder_test__');
|
||||||
|
print("TempDir: ${tempDir.path}");
|
||||||
|
|
||||||
|
var random = Random();
|
||||||
|
for (var i = 0; i < 300; i++) {
|
||||||
|
print("Building Note $i");
|
||||||
|
await _writeRandomNote(random, tempDir.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
rootFolder = NotesFolderFS(null, tempDir.path);
|
||||||
|
await rootFolder.loadRecursively();
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
print("Cleaning Up TempDir: ${tempDir.path}");
|
||||||
|
tempDir.deleteSync(recursive: true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Should load all the notes flattened', () async {
|
||||||
|
var f = FlattenedNotesFolder(rootFolder);
|
||||||
|
expect(f.notes.length, 300);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _writeRandomNote(Random random, String dirPath) async {
|
||||||
|
String path;
|
||||||
|
while (true) {
|
||||||
|
path = p.join(dirPath, "${random.nextInt(10000)}.md");
|
||||||
|
if (!File(path).existsSync()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var note = Note(NotesFolderFS(null, dirPath), path);
|
||||||
|
note.modified = DateTime(2014, 1, 1 + (random.nextInt(2000)));
|
||||||
|
note.body = "p1";
|
||||||
|
await note.save();
|
||||||
|
}
|
Reference in New Issue
Block a user