mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 09:47:35 +08:00
Fix tests
This commit is contained in:
@ -89,8 +89,7 @@ class StateContainerState extends State<StateContainer> {
|
||||
// FIXME: Implement this!
|
||||
void updateNote(Note note) {
|
||||
setState(() {
|
||||
//appState.notes.
|
||||
//appState.notes.remove(note);
|
||||
noteRepo.updateNote(note);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -78,4 +78,20 @@ class FileStorage implements NoteRepository {
|
||||
Future<bool> sync() async {
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<Directory> saveNotes(List<Note> notes) async {
|
||||
final dir = await getDirectory();
|
||||
await dir.delete(recursive: true);
|
||||
await dir.create();
|
||||
|
||||
for (var note in notes) {
|
||||
var filePath = p.join(dir.path, fileNameGenerator(note));
|
||||
|
||||
var file = new File(filePath);
|
||||
var contents = noteSerializer.encode(note);
|
||||
await file.writeAsString(contents);
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
}
|
||||
|
@ -3,18 +3,23 @@ import 'dart:io';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
import '../lib/note.dart';
|
||||
import '../lib/file_storage.dart';
|
||||
import 'package:journal/note.dart';
|
||||
import 'package:journal/storage/file_storage.dart';
|
||||
import 'package:journal/storage/serializers.dart';
|
||||
|
||||
main() {
|
||||
group('FileStorage', () {
|
||||
var notes = [
|
||||
Note(id: "1", body: "test", createdAt: new DateTime.now()),
|
||||
Note(id: "2", body: "test2", createdAt: new DateTime.now()),
|
||||
Note(id: "1", body: "test", created: new DateTime.now()),
|
||||
Note(id: "2", body: "test2", created: new DateTime.now()),
|
||||
];
|
||||
|
||||
final directory = Directory.systemTemp.createTemp('__storage_test__');
|
||||
final storage = FileStorage(getDirectory: () => directory);
|
||||
final storage = FileStorage(
|
||||
getDirectory: () => directory,
|
||||
noteSerializer: new JsonNoteSerializer(),
|
||||
fileNameGenerator: (Note note) => note.id,
|
||||
);
|
||||
|
||||
tearDownAll(() async {
|
||||
final tempDirectory = await directory;
|
||||
@ -30,7 +35,7 @@ main() {
|
||||
});
|
||||
|
||||
test('Should load Notes from disk', () async {
|
||||
var loadedNotes = await storage.loadNotes();
|
||||
var loadedNotes = await storage.listNotes();
|
||||
loadedNotes.sort();
|
||||
notes.sort();
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:journal/note.dart';
|
||||
import 'package:journal/serializers.dart';
|
||||
import 'package:journal/storage/serializers.dart';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
|
||||
|
Reference in New Issue
Block a user