mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
Fix tests
This commit is contained in:
@ -89,8 +89,7 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
// FIXME: Implement this!
|
// FIXME: Implement this!
|
||||||
void updateNote(Note note) {
|
void updateNote(Note note) {
|
||||||
setState(() {
|
setState(() {
|
||||||
//appState.notes.
|
noteRepo.updateNote(note);
|
||||||
//appState.notes.remove(note);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,4 +78,20 @@ class FileStorage implements NoteRepository {
|
|||||||
Future<bool> sync() async {
|
Future<bool> sync() async {
|
||||||
return false;
|
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:test/test.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
import '../lib/note.dart';
|
import 'package:journal/note.dart';
|
||||||
import '../lib/file_storage.dart';
|
import 'package:journal/storage/file_storage.dart';
|
||||||
|
import 'package:journal/storage/serializers.dart';
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
group('FileStorage', () {
|
group('FileStorage', () {
|
||||||
var notes = [
|
var notes = [
|
||||||
Note(id: "1", body: "test", createdAt: new DateTime.now()),
|
Note(id: "1", body: "test", created: new DateTime.now()),
|
||||||
Note(id: "2", body: "test2", createdAt: new DateTime.now()),
|
Note(id: "2", body: "test2", created: new DateTime.now()),
|
||||||
];
|
];
|
||||||
|
|
||||||
final directory = Directory.systemTemp.createTemp('__storage_test__');
|
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 {
|
tearDownAll(() async {
|
||||||
final tempDirectory = await directory;
|
final tempDirectory = await directory;
|
||||||
@ -30,7 +35,7 @@ main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Should load Notes from disk', () async {
|
test('Should load Notes from disk', () async {
|
||||||
var loadedNotes = await storage.loadNotes();
|
var loadedNotes = await storage.listNotes();
|
||||||
loadedNotes.sort();
|
loadedNotes.sort();
|
||||||
notes.sort();
|
notes.sort();
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:journal/note.dart';
|
import 'package:journal/note.dart';
|
||||||
import 'package:journal/serializers.dart';
|
import 'package:journal/storage/serializers.dart';
|
||||||
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user