Skip to content

Commit

Permalink
Fix creating notes from context menu (#31)
Browse files Browse the repository at this point in the history
Fix creating notes so null parent doesn't crash app
  • Loading branch information
EddieAbbondanzio authored Jan 6, 2023
1 parent c34b73f commit 476f6b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/shared/domain/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export function createNote(props: Partial<Note> & Pick<Note, "name">): Note {
note.dateCreated ??= new Date();
note.content ??= "";

// Trim out null parent id
if (note.parent === null) {
delete note.parent;
}

if (!isEmpty(note.children)) {
for (const child of note.children!) {
child.parent = note.id;
Expand Down
6 changes: 6 additions & 0 deletions test/main/ipc/plugins/notes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ function createMetadata(props?: Partial<NoteMetadata>): NoteMetadata {
return metadata;
}

test("createNote", () => {
// Trims out null
const note = createNote({ name: "foo", parent: null });
expect(note).not.toHaveProperty("parent");
});

test("registers attachment protocol", async () => {
mockFS({
[FAKE_NOTE_DIRECTORY]: {},
Expand Down

0 comments on commit 476f6b7

Please sign in to comment.