mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
fix all tests
This commit is contained in:
@@ -273,28 +273,28 @@ test("delete topic from notebook", () =>
|
|||||||
|
|
||||||
test("delete note", () =>
|
test("delete note", () =>
|
||||||
noteTest().then(async ({ db, timestamp }) => {
|
noteTest().then(async ({ db, timestamp }) => {
|
||||||
await db.deleteNotes([{ dateCreated: timestamp }]);
|
expect(await db.deleteNotes({ dateCreated: timestamp })).toBe(true);
|
||||||
let note = db.getNote(timestamp);
|
let note = db.getNote(timestamp);
|
||||||
expect(note).toBeUndefined();
|
expect(note).toBeUndefined();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
test("delete notebook", () =>
|
test("delete notebook", () =>
|
||||||
notebookTest().then(async ({ db, timestamp }) => {
|
notebookTest().then(async ({ db, timestamp }) => {
|
||||||
await db.deleteNotebooks([{ dateCreated: timestamp }]);
|
expect(await db.deleteNotebooks({ dateCreated: timestamp })).toBe(true);
|
||||||
let notebook = db.getNotebook(timestamp);
|
let notebook = db.getNotebook(timestamp);
|
||||||
expect(notebook).toBeUndefined();
|
expect(notebook).toBeUndefined();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
test("trash should not be empty", () =>
|
test("trash should not be empty", () =>
|
||||||
notebookTest().then(async ({ db, timestamp }) => {
|
notebookTest().then(async ({ db, timestamp }) => {
|
||||||
await db.deleteNotebooks([{ dateCreated: timestamp }]);
|
expect(await db.deleteNotebooks({ dateCreated: timestamp })).toBe(true);
|
||||||
let trash = db.getTrash();
|
let trash = db.getTrash();
|
||||||
expect(trash.length).toBeGreaterThan(0);
|
expect(trash.length).toBeGreaterThan(0);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
test("restore an item from trash", () =>
|
test("restore an item from trash", () =>
|
||||||
notebookTest().then(async ({ db, timestamp }) => {
|
notebookTest().then(async ({ db, timestamp }) => {
|
||||||
await db.deleteNotebooks([{ dateCreated: timestamp }]);
|
expect(await db.deleteNotebooks({ dateCreated: timestamp })).toBe(true);
|
||||||
let trash = db.getTrash();
|
let trash = db.getTrash();
|
||||||
expect(trash.length).toBeGreaterThan(0);
|
expect(trash.length).toBeGreaterThan(0);
|
||||||
await db.restoreItem(timestamp);
|
await db.restoreItem(timestamp);
|
||||||
@@ -304,7 +304,7 @@ test("restore an item from trash", () =>
|
|||||||
|
|
||||||
test("clear trash should clear the trash", () =>
|
test("clear trash should clear the trash", () =>
|
||||||
notebookTest().then(async ({ db, timestamp }) => {
|
notebookTest().then(async ({ db, timestamp }) => {
|
||||||
await db.deleteNotebooks([{ dateCreated: timestamp }]);
|
expect(await db.deleteNotebooks({ dateCreated: timestamp })).toBe(true);
|
||||||
let trash = db.getTrash();
|
let trash = db.getTrash();
|
||||||
expect(trash.length).toBeGreaterThan(0);
|
expect(trash.length).toBeGreaterThan(0);
|
||||||
await db.clearTrash();
|
await db.clearTrash();
|
||||||
@@ -340,15 +340,9 @@ test("empty notebook should not be added", () =>
|
|||||||
expect(res).toBeUndefined();
|
expect(res).toBeUndefined();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
test("deletion of unknown item should return false", () =>
|
|
||||||
databaseTest().then(async db => {
|
|
||||||
let res = await db.deleteNotes(undefined);
|
|
||||||
expect(res).toBe(false);
|
|
||||||
}));
|
|
||||||
|
|
||||||
test("deletion of invalid items should cause continue and return true", () =>
|
test("deletion of invalid items should cause continue and return true", () =>
|
||||||
databaseTest().then(async db => {
|
databaseTest().then(async db => {
|
||||||
let res = await db.deleteNotes([null, null, "something"]);
|
let res = await db.deleteNotes(null, null, "something");
|
||||||
expect(res).toBe(true);
|
expect(res).toBe(true);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -120,15 +120,23 @@ class Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addNote(note) {
|
async addNote(_note) {
|
||||||
if (!note) return;
|
if (!_note || !_note.content) return;
|
||||||
let timestamp = note.dateCreated || Date.now();
|
let timestamp = _note.dateCreated || Date.now();
|
||||||
note = { ...this.notes[timestamp], ...note };
|
let note = { ...this.notes[timestamp], ..._note };
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!note.title &&
|
!this.notes[timestamp] &&
|
||||||
|
(note.content.text.length <= 0 || !note.content.delta) &&
|
||||||
|
(!note.title || note.title.length <= 0)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(!note.title || note.title.length <= 0) &&
|
||||||
!note.locked &&
|
!note.locked &&
|
||||||
(!note.content || !note.content.text || !note.content.delta) &&
|
note.content.text.length <= 0 &&
|
||||||
this.notes[timestamp]
|
this.notes[timestamp]
|
||||||
) {
|
) {
|
||||||
//delete the note
|
//delete the note
|
||||||
@@ -433,8 +441,10 @@ class Database {
|
|||||||
export default Database;
|
export default Database;
|
||||||
|
|
||||||
async function deleteItems(items, key) {
|
async function deleteItems(items, key) {
|
||||||
if (!items || items.length <= 0 || !this[key] || this[key].length <= 0)
|
if (!items || items.length <= 0 || !this[key] || this[key].length <= 0) {
|
||||||
|
console.log(items, items.length);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
for (let item of items) {
|
for (let item of items) {
|
||||||
if (!item) continue;
|
if (!item) continue;
|
||||||
if (this[key].hasOwnProperty(item.dateCreated)) {
|
if (this[key].hasOwnProperty(item.dateCreated)) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fuzzysearch": "^1.0.3",
|
"fuzzysearch": "^1.0.3",
|
||||||
"transfun": "^1.0.2"
|
"transfun": "^1.0.2",
|
||||||
|
"node-fetch": "^2.6.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user