mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-17 04:07:51 +01:00
core: fix flaky note history tests
This commit is contained in:
@@ -68,20 +68,23 @@ test("editing the same note should create multiple history sessions", () =>
|
|||||||
|
|
||||||
test("restoring an old session should replace note's content", () =>
|
test("restoring an old session should replace note's content", () =>
|
||||||
noteTest({ ...TEST_NOTE, sessionId: Date.now() }).then(async ({ db, id }) => {
|
noteTest({ ...TEST_NOTE, sessionId: Date.now() }).then(async ({ db, id }) => {
|
||||||
|
await delay(1000);
|
||||||
let editedContent = {
|
let editedContent = {
|
||||||
data: TEST_NOTE.content.data + "<p>Some new content</p>",
|
data: TEST_NOTE.content.data + "<p>Some new content</p>",
|
||||||
type: "tiptap"
|
type: "tiptap"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sessionId = `${Date.now() + 10000}`;
|
||||||
await db.notes.add({
|
await db.notes.add({
|
||||||
id: id,
|
id: id,
|
||||||
content: editedContent,
|
content: editedContent,
|
||||||
sessionId: Date.now() + 10000
|
sessionId
|
||||||
});
|
});
|
||||||
|
|
||||||
const [, firstVersion] = await db.noteHistory
|
const [, firstVersion] = await db.noteHistory
|
||||||
.get(id)
|
.get(id)
|
||||||
.items(undefined, { sortBy: "dateModified", sortDirection: "desc" });
|
.items(undefined, { sortBy: "dateModified", sortDirection: "desc" });
|
||||||
|
expect(firstVersion.id).not.toBe(`${id}_${sessionId}`);
|
||||||
await db.noteHistory.restore(firstVersion.id);
|
await db.noteHistory.restore(firstVersion.id);
|
||||||
|
|
||||||
const contentId = (await db.notes.note(id)).contentId;
|
const contentId = (await db.notes.note(id)).contentId;
|
||||||
@@ -138,15 +141,17 @@ test("return empty array if no history available", () =>
|
|||||||
|
|
||||||
test("auto clear sessions if they exceed the limit", () =>
|
test("auto clear sessions if they exceed the limit", () =>
|
||||||
noteTest({ ...TEST_NOTE, sessionId: Date.now() }).then(async ({ db, id }) => {
|
noteTest({ ...TEST_NOTE, sessionId: Date.now() }).then(async ({ db, id }) => {
|
||||||
|
await delay(1000);
|
||||||
let editedContent = {
|
let editedContent = {
|
||||||
data: TEST_NOTE.content.data + "<p>Some new content</p>",
|
data: TEST_NOTE.content.data + "<p>Some new content</p>",
|
||||||
type: "tiptap"
|
type: "tiptap"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sessionId = `${Date.now() + 10000}`;
|
||||||
await db.notes.add({
|
await db.notes.add({
|
||||||
id: id,
|
id: id,
|
||||||
content: editedContent,
|
content: editedContent,
|
||||||
sessionId: `${Date.now() + 10000}`
|
sessionId
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(await db.noteHistory.get(id).count()).toBe(2);
|
expect(await db.noteHistory.get(id).count()).toBe(2);
|
||||||
@@ -157,6 +162,7 @@ test("auto clear sessions if they exceed the limit", () =>
|
|||||||
expect(sessions).toHaveLength(1);
|
expect(sessions).toHaveLength(1);
|
||||||
|
|
||||||
const content = await db.noteHistory.content(sessions[0].id);
|
const content = await db.noteHistory.content(sessions[0].id);
|
||||||
|
expect(sessions[0].id).toBe(`${id}_${sessionId}`);
|
||||||
expect(content.data).toBe(editedContent.data);
|
expect(content.data).toBe(editedContent.data);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user