Refactor note file naming logic

I want to make the note class immutable, and the file path naming logic
is the toughest part.
This commit is contained in:
Vishesh Handa
2022-01-14 12:55:27 +01:00
parent 7bb7fb94f2
commit 0488714e89
15 changed files with 238 additions and 157 deletions

View File

@ -26,6 +26,8 @@ void main() {
late NotesFolderFS parent;
late FileStorage fileStorage;
final gitDt = DateTime.now();
setUpAll(() async {
SharedPreferences.setMockInitialValues({});
config = NotesFolderConfig('', await SharedPreferences.getInstance());
@ -46,7 +48,7 @@ void main() {
serializer.settings.emojify = true;
serializer.settings.titleSettings = SettingsTitle.InYaml;
var file = File.short("file-path-not-important", repoPath);
var file = File.short("file-path-not-important", repoPath, gitDt);
var note = serializer.decode(data: doc, parent: parent, file: file);
expect(note.body, "I ❤️ you");
@ -67,7 +69,7 @@ void main() {
var serializer = NoteSerializer.raw();
serializer.settings.titleSettings = SettingsTitle.InH1;
var file = File.short("file-path-not-important", repoPath);
var file = File.short("file-path-not-important", repoPath, gitDt);
var note = serializer.decode(data: doc, parent: parent, file: file);
expect(note.body, "I heart you");
@ -87,7 +89,7 @@ void main() {
var serializer = NoteSerializer.raw();
var file = File.short("file-path-not-important", repoPath);
var file = File.short("file-path-not-important", repoPath, gitDt);
var note = serializer.decode(data: doc, parent: parent, file: file);
expect(note.body, "I heart you");
@ -100,7 +102,7 @@ void main() {
var serializer = NoteSerializer.raw();
var file = File.short("file-path-not-important", repoPath);
var file = File.short("file-path-not-important", repoPath, gitDt);
var note = serializer.decode(data: doc, parent: parent, file: file);
expect(note.body.length, 0);
@ -115,7 +117,7 @@ void main() {
var serializer = NoteSerializer.raw();
serializer.settings.titleSettings = SettingsTitle.InH1;
var file = File.short("file-path-not-important", repoPath);
var file = File.short("file-path-not-important", repoPath, gitDt);
var note = serializer.decode(data: doc, parent: parent, file: file);
expect(note.body, "I heart you");
@ -137,7 +139,7 @@ void main() {
var serializer = NoteSerializer.raw();
serializer.settings.titleSettings = SettingsTitle.InYaml;
var file = File.short("file-path-not-important", repoPath);
var file = File.short("file-path-not-important", repoPath, gitDt);
var note = serializer.decode(data: doc, parent: parent, file: file);
expect(note.body, "body");
@ -162,7 +164,7 @@ void main() {
var serializer = NoteSerializer.raw();
serializer.settings.titleSettings = SettingsTitle.InYaml;
var file = File.short("file-path-not-important", repoPath);
var file = File.short("file-path-not-important", repoPath, gitDt);
var note = serializer.decode(data: doc, parent: parent, file: file);
expect(note.body, "body");