mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 06:59:31 +01:00
core: shorcuts -> shortcuts
This commit is contained in:
@@ -26,56 +26,56 @@ beforeEach(() => {
|
||||
test("create a shortcut of an invalid item should throw", () =>
|
||||
databaseTest().then(async (db) => {
|
||||
await expect(() =>
|
||||
db.shorcuts.add({ item: { type: "HELLO!" } })
|
||||
db.shortcuts.add({ item: { type: "HELLO!" } })
|
||||
).rejects.toThrow(/cannot create a shortcut/i);
|
||||
}));
|
||||
|
||||
test("create a shortcut of notebook", () =>
|
||||
notebookTest().then(async ({ db, id }) => {
|
||||
await db.shorcuts.add({ item: { type: "notebook", id } });
|
||||
expect(db.shorcuts.exists(id)).toBe(true);
|
||||
expect(db.shorcuts.all[0].item.id).toBe(id);
|
||||
await db.shortcuts.add({ item: { type: "notebook", id } });
|
||||
expect(db.shortcuts.exists(id)).toBe(true);
|
||||
expect(db.shortcuts.all[0].item.id).toBe(id);
|
||||
}));
|
||||
|
||||
test("create a duplicate shortcut of notebook", () =>
|
||||
notebookTest().then(async ({ db, id }) => {
|
||||
await db.shorcuts.add({ item: { type: "notebook", id } });
|
||||
await db.shorcuts.add({ item: { type: "notebook", id } });
|
||||
await db.shortcuts.add({ item: { type: "notebook", id } });
|
||||
await db.shortcuts.add({ item: { type: "notebook", id } });
|
||||
|
||||
expect(db.shorcuts.all).toHaveLength(1);
|
||||
expect(db.shorcuts.all[0].item.id).toBe(id);
|
||||
expect(db.shortcuts.all).toHaveLength(1);
|
||||
expect(db.shortcuts.all[0].item.id).toBe(id);
|
||||
}));
|
||||
|
||||
test("create shortcut of a topic", () =>
|
||||
notebookTest().then(async ({ db, id }) => {
|
||||
const notebook = db.notebooks.notebook(id)._notebook;
|
||||
const topic = notebook.topics[0];
|
||||
await db.shorcuts.add({
|
||||
await db.shortcuts.add({
|
||||
item: { type: "topic", id: topic.id, notebookId: id }
|
||||
});
|
||||
|
||||
expect(db.shorcuts.all).toHaveLength(1);
|
||||
expect(db.shorcuts.all[0].item.id).toBe(topic.id);
|
||||
expect(db.shortcuts.all).toHaveLength(1);
|
||||
expect(db.shortcuts.all[0].item.id).toBe(topic.id);
|
||||
}));
|
||||
|
||||
test("pin a tag", () =>
|
||||
databaseTest().then(async (db) => {
|
||||
const tag = await db.tags.add("HELLO!");
|
||||
await db.shorcuts.add({ item: { type: "tag", id: tag.id } });
|
||||
await db.shortcuts.add({ item: { type: "tag", id: tag.id } });
|
||||
|
||||
expect(db.shorcuts.all).toHaveLength(1);
|
||||
expect(db.shorcuts.all[0].item.id).toBe(tag.id);
|
||||
expect(db.shortcuts.all).toHaveLength(1);
|
||||
expect(db.shortcuts.all[0].item.id).toBe(tag.id);
|
||||
}));
|
||||
|
||||
test("remove shortcut", () =>
|
||||
databaseTest().then(async (db) => {
|
||||
const tag = await db.tags.add("HELLO!");
|
||||
const shortcutId = await db.shorcuts.add({
|
||||
const shortcutId = await db.shortcuts.add({
|
||||
item: { type: "tag", id: tag.id }
|
||||
});
|
||||
|
||||
expect(db.shorcuts.all).toHaveLength(1);
|
||||
expect(db.shortcuts.all).toHaveLength(1);
|
||||
|
||||
await db.shorcuts.remove(shortcutId);
|
||||
expect(db.shorcuts.all).toHaveLength(0);
|
||||
await db.shortcuts.remove(shortcutId);
|
||||
expect(db.shortcuts.all).toHaveLength(0);
|
||||
}));
|
||||
|
||||
@@ -141,7 +141,7 @@ class Database {
|
||||
/**@type {NoteHistory} */
|
||||
this.noteHistory = await NoteHistory.new(this, "notehistory", false);
|
||||
/**@type {Shortcuts} */
|
||||
this.shorcuts = await Shortcuts.new(this, "shorcuts");
|
||||
this.shortcuts = await Shortcuts.new(this, "shortcuts");
|
||||
|
||||
this.trash = new Trash(this);
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ class Migrations {
|
||||
type: "settings"
|
||||
},
|
||||
{
|
||||
index: this._db.shorcuts.raw,
|
||||
dbCollection: this._db.shorcuts
|
||||
index: this._db.shortcuts.raw,
|
||||
dbCollection: this._db.shortcuts
|
||||
},
|
||||
{
|
||||
index: this._db.notes.raw,
|
||||
|
||||
@@ -38,7 +38,7 @@ class Collector {
|
||||
|
||||
const items = [
|
||||
...this._collect("note", this._db.notes.raw, isForceSync),
|
||||
...this._collect("shortcut", this._db.shorcuts.raw, isForceSync),
|
||||
...this._collect("shortcut", this._db.shortcuts.raw, isForceSync),
|
||||
...this._collect("notebook", this._db.notebooks.raw, isForceSync),
|
||||
...this._collect("content", await this._db.content.all(), isForceSync),
|
||||
...this._collect(
|
||||
|
||||
@@ -44,8 +44,8 @@ class Merger {
|
||||
set: (item) => this._db.notes.merge(item)
|
||||
},
|
||||
shortcut: {
|
||||
get: (id) => this._db.shorcuts.shortcut(id),
|
||||
set: (item) => this._db.shorcuts.merge(item)
|
||||
get: (id) => this._db.shortcuts.shortcut(id),
|
||||
set: (item) => this._db.shortcuts.merge(item)
|
||||
},
|
||||
notebook: {
|
||||
threshold: 1000,
|
||||
|
||||
@@ -165,7 +165,7 @@ export default class Notebooks extends Collection {
|
||||
const notebookData = qclone(notebook.data);
|
||||
await notebook.topics.delete(...notebook.data.topics);
|
||||
await this._collection.removeItem(id);
|
||||
await this._db.settings.unpin(id);
|
||||
await this._db.shortcuts.remove(id);
|
||||
await this._db.trash.add(notebookData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export default class Tags extends Collection {
|
||||
if (hasItem(note.tags, tag.title)) await note.untag(tag.title);
|
||||
}
|
||||
|
||||
await this._db.settings.unpin(tagId);
|
||||
await this._db.shortcuts.remove(tagId);
|
||||
await this._collection.deleteItem(tagId);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ export default class Tags extends Collection {
|
||||
|
||||
if (tag.noteIds.length > 0) await this._collection.addItem(tag);
|
||||
else {
|
||||
await this._db.settings.unpin(tag.id);
|
||||
await this._db.shortcuts.remove(tag.id);
|
||||
await this._collection.deleteItem(tag.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ export default class Topics {
|
||||
if (!topic) continue;
|
||||
|
||||
await topic.delete(...topic._topic.notes);
|
||||
await this._db.settings.unpin(topicId);
|
||||
await this._db.shortcuts.remove(topicId);
|
||||
|
||||
const topicIndex = allTopics.findIndex(
|
||||
(t) => t.id === topicId || t.title === topicId
|
||||
|
||||
@@ -171,7 +171,7 @@ export default class Backup {
|
||||
},
|
||||
{
|
||||
index: data["shortcuts"],
|
||||
dbCollection: this._db.shorcuts
|
||||
dbCollection: this._db.shortcuts
|
||||
},
|
||||
{
|
||||
index: data["notes"],
|
||||
|
||||
Reference in New Issue
Block a user