Files
GitJournal/test/file_storage_test.dart
Vishesh Handa 8345f1424e Note: Rename 'fileName' to 'filePath'
A note can reside in a subfolder, so lets just use the path as an
identifier instead of using just the fileName.
2019-02-14 12:07:23 +01:00

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);
});
});
}