fix: don't mutate the notebook object

This commit is contained in:
thecodrr
2020-02-22 17:59:48 +05:00
parent f8b5e6039e
commit 4a96a0aae2
2 changed files with 10 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ test("pin a notebook", () =>
notebookTest().then(async ({ db, id }) => {
let notebook = db.notebooks.notebook(id);
await notebook.pin();
notebook = db.notebooks.notebook(id);
expect(notebook.data.pinned).toBe(true);
}));
@@ -43,8 +44,10 @@ test("unpin a notebook", () =>
notebookTest().then(async ({ db, id }) => {
let notebook = db.notebooks.notebook(id);
await notebook.pin();
notebook = db.notebooks.notebook(id);
expect(notebook.data.pinned).toBe(true);
await notebook.pin();
notebook = db.notebooks.notebook(id);
expect(notebook.data.pinned).toBe(false);
}));
@@ -52,6 +55,7 @@ test("favorite a notebook", () =>
notebookTest().then(async ({ db, id }) => {
let notebook = db.notebooks.notebook(id);
await notebook.favorite();
notebook = db.notebooks.notebook(id);
expect(notebook.data.favorite).toBe(true);
}));
@@ -59,8 +63,10 @@ test("unfavorite a notebook", () =>
notebookTest().then(async ({ db, id }) => {
let notebook = db.notebooks.notebook(id);
await notebook.favorite();
notebook = db.notebooks.notebook(id);
expect(notebook.data.favorite).toBe(true);
await notebook.favorite();
notebook = db.notebooks.notebook(id);
expect(notebook.data.favorite).toBe(false);
}));

View File

@@ -25,8 +25,10 @@ export default class Notebook {
}
toggle(prop) {
this.notebook[prop] = !this.notebook[prop];
return this.notebooks.add(this.notebook);
return this.notebooks.add({
id: this.notebook.id,
[prop]: !this.notebook[prop]
});
}
pin() {