mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-10 21:13:57 +08:00

A note can reside in a subfolder, so lets just use the path as an identifier instead of using just the fileName.
53 lines
1.4 KiB
Dart
53 lines
1.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:journal/note.dart';
|
|
import 'package:journal/storage/file_storage.dart';
|
|
import 'package:journal/storage/serializers.dart';
|
|
import 'package:path/path.dart' as p;
|
|
import 'package:test/test.dart';
|
|
|
|
DateTime nowWithoutMicro() {
|
|
var dt = DateTime.now();
|
|
return DateTime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
|
|
}
|
|
|
|
void main() {
|
|
group('FileStorage', () {
|
|
var notes = [
|
|
Note(filePath: "1.md", body: "test", created: nowWithoutMicro()),
|
|
Note(filePath: "2.md", body: "test2", created: nowWithoutMicro()),
|
|
];
|
|
|
|
Directory tempDir;
|
|
FileStorage storage;
|
|
|
|
setUpAll(() async {
|
|
tempDir = await Directory.systemTemp.createTemp('__storage_test__');
|
|
storage = FileStorage(
|
|
baseDirectory: tempDir.path,
|
|
noteSerializer: JsonNoteSerializer(),
|
|
);
|
|
});
|
|
|
|
tearDownAll(() async {
|
|
tempDir.deleteSync(recursive: true);
|
|
});
|
|
|
|
test('Should persist Notes to disk', () async {
|
|
var dir = await storage.saveNotes(notes);
|
|
expect(dir.listSync(recursive: true).length, 2);
|
|
|
|
expect(File(p.join(dir.path, "1.md")).existsSync(), isTrue);
|
|
expect(File(p.join(dir.path, "2.md")).existsSync(), isTrue);
|
|
});
|
|
|
|
test('Should load Notes from disk', () async {
|
|
var loadedNotes = await storage.listNotes();
|
|
loadedNotes.sort();
|
|
notes.sort();
|
|
|
|
expect(loadedNotes, notes);
|
|
});
|
|
});
|
|
}
|