A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: test notes deletion when deleting notebook/topic
Abdullah Atta1fa020365159
diff --git a/apps/web/__e2e__/models/app.model.ts b/apps/web/__e2e__/models/app.model.tsindex b6386657c..1392e9192 100644--- a/apps/web/__e2e__/models/app.model.ts+++ b/apps/web/__e2e__/models/app.model.ts@@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { Page, Locator } from "@playwright/test";+import { Page } from "@playwright/test";import { getTestId } from "../utils";import { AuthModel } from "./auth.model";import { CheckoutModel } from "./checkout.model";@@ -50,6 +50,11 @@ export class AppModel {await this.getRouteHeader();}+ goBack() {+ const goBackButton = this.page.locator(getTestId("go-back"));+ return goBackButton.click();+ }+async goToNotes() {await this.navigateTo("Notes");return new NotesViewModel(this.page, "home");@@ -92,8 +97,11 @@ export class AppModel {await this.page.waitForTimeout(1000);}- getRouteHeader() {- return this.page.locator(getTestId("routeHeader")).inputValue();+ async getRouteHeader() {+ const routeHeader = this.page.locator(getTestId("routeHeader"));+ if (!(await routeHeader.isVisible())) return;++ return await routeHeader.inputValue();}async isSynced() {diff --git a/apps/web/__e2e__/models/item.model.ts b/apps/web/__e2e__/models/item.model.tsindex d451973dc..77e2a0341 100644--- a/apps/web/__e2e__/models/item.model.ts+++ b/apps/web/__e2e__/models/item.model.ts@@ -22,7 +22,7 @@ import { BaseItemModel } from "./base-item.model";import { ContextMenuModel } from "./context-menu.model";import { NotesViewModel } from "./notes-view.model";import { Item } from "./types";-import { fillItemDialog } from "./utils";+import { confirmDialog, denyDialog, fillItemDialog } from "./utils";export class ItemModel extends BaseItemModel {private readonly contextMenu: ContextMenuModel;@@ -36,12 +36,14 @@ export class ItemModel extends BaseItemModel {return new NotesViewModel(this.page, "notes");}- async delete() {+ async delete(deleteContainedNotes = false) {await this.contextMenu.open(this.locator);- await Promise.all([- this.contextMenu.clickOnItem("delete"),- this.waitFor("detached")- ]);+ await this.contextMenu.clickOnItem("delete");++ if (deleteContainedNotes) await confirmDialog(this.page);+ else await denyDialog(this.page);++ await this.waitFor("detached");}async editItem(item: Item) {diff --git a/apps/web/__e2e__/models/notebook-item.model.ts b/apps/web/__e2e__/models/notebook-item.model.tsindex 9ebd3201a..2c92233d2 100644--- a/apps/web/__e2e__/models/notebook-item.model.ts+++ b/apps/web/__e2e__/models/notebook-item.model.ts@@ -23,7 +23,7 @@ import { ContextMenuModel } from "./context-menu.model";import { ToggleModel } from "./toggle.model";import { ItemsViewModel } from "./items-view.model";import { Notebook } from "./types";-import { fillNotebookDialog } from "./utils";+import { confirmDialog, denyDialog, fillNotebookDialog } from "./utils";export class NotebookItemModel extends BaseItemModel {private readonly contextMenu: ContextMenuModel;@@ -44,12 +44,14 @@ export class NotebookItemModel extends BaseItemModel {await fillNotebookDialog(this.page, notebook, true);}- async moveToTrash() {+ async moveToTrash(deleteContainedNotes = false) {await this.contextMenu.open(this.locator);- await Promise.all([- this.contextMenu.clickOnItem("movetotrash"),- this.waitFor("detached")- ]);+ await this.contextMenu.clickOnItem("movetotrash");++ if (deleteContainedNotes) await confirmDialog(this.page);+ else await denyDialog(this.page);++ await this.waitFor("detached");}async pin() {diff --git a/apps/web/__e2e__/models/utils.ts b/apps/web/__e2e__/models/utils.tsindex ef973ee89..68f30ce92 100644--- a/apps/web/__e2e__/models/utils.ts+++ b/apps/web/__e2e__/models/utils.ts@@ -77,6 +77,12 @@ export async function confirmDialog(page: Page) {// await dialogConfirm.waitFor({ state: "detached" });}+export async function denyDialog(page: Page) {+ const dialogConfirm = page.locator(getTestId("dialog-no"));+ await dialogConfirm.click();+ // await dialogConfirm.waitFor({ state: "detached" });+}+export async function waitToHaveText(page: Page, id: string) {await page.waitForFunction(({ id }) => {diff --git a/apps/web/__e2e__/notebooks.test.ts b/apps/web/__e2e__/notebooks.test.tsindex 32df4d2d3..e286bcb6f 100644--- a/apps/web/__e2e__/notebooks.test.ts+++ b/apps/web/__e2e__/notebooks.test.ts@@ -165,6 +165,29 @@ test("remove shortcut of a notebook", async ({ page }) => {expect(allShortcuts.includes(NOTEBOOK.title)).toBeFalsy();});+test("delete all notes within a notebook", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notebooks = await app.goToNotebooks();+ const notebook = await notebooks.createNotebook(NOTEBOOK);+ const topics = await notebook?.openNotebook();+ const topic = await topics?.findItem({ title: NOTEBOOK.topics[0] });+ let notes = await topic?.open();+ for (let i = 0; i < 2; ++i) {+ await notes?.createNote({+ title: `Note ${i}`,+ content: NOTE.content+ });+ }+ await app.goBack();+ await app.goBack();++ await notebook?.moveToTrash(true);++ notes = await app.goToNotes();+ expect(await notes.isEmpty()).toBe(true);+});+test(`sort notebooks`, async ({ page }, info) => {info.setTimeout(2 * 60 * 1000);diff --git a/apps/web/__e2e__/topics.test.ts b/apps/web/__e2e__/topics.test.tsindex b96b4d27d..e931672ca 100644--- a/apps/web/__e2e__/topics.test.ts+++ b/apps/web/__e2e__/topics.test.ts@@ -24,7 +24,8 @@ import {groupByOptions,NOTEBOOK,sortByOptions,- orderByOptions+ orderByOptions,+ NOTE} from "./utils";test("create shortcut of a topic", async ({ page }) => {@@ -92,6 +93,28 @@ test("edit topics individually", async ({ page }) => {}});+test("delete all notes within a topic", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notebooks = await app.goToNotebooks();+ const notebook = await notebooks.createNotebook(NOTEBOOK);+ const topics = await notebook?.openNotebook();+ const topic = await topics?.findItem({ title: NOTEBOOK.topics[0] });+ let notes = await topic?.open();+ for (let i = 0; i < 2; ++i) {+ await notes?.createNote({+ title: `Note ${i}`,+ content: NOTE.content+ });+ }+ await app.goBack();++ await topic?.delete(true);++ notes = await app.goToNotes();+ expect(await notes.isEmpty()).toBe(true);+});+test(`sort topics`, async ({ page }, info) => {info.setTimeout(2 * 60 * 1000);diff --git a/apps/web/src/components/notebook/index.js b/apps/web/src/components/notebook/index.jsindex 99f02f414..d381764d4 100644--- a/apps/web/src/components/notebook/index.js+++ b/apps/web/src/components/notebook/index.js@@ -152,20 +152,20 @@ const menuItems = [icon: Icon.Trash,onClick: async ({ items }) => {const shouldDeleteNotes = await confirm({- title: `Delete Contained Notes?`,- message: `Do you also want to delete notes within ${items.length > 1 ? "this notebook" : "these notebooks"}?`,+ title: `Delete contained notes?`,+ message: `Do you also want to delete notes within ${+ items.length > 1 ? "this notebook" : "these notebooks"+ }?`,yesText: `Yes`,noText: "No"});- let notes = [];if (shouldDeleteNotes) {+ const notes = [];for (const item of items) {const topics = db.notebooks.notebook(item.id).topics;for (const topic of topics.all) {- for (const note of topics.topic(topic.id).all) {- notes.push(note);- }+ notes.push(...topics.topic(topic.id).all);}}await Multiselect.moveNotesToTrash(notes, false);diff --git a/apps/web/src/components/topic/index.js b/apps/web/src/components/topic/index.jsindex 6b7e5b65a..1fcdc0223 100644--- a/apps/web/src/components/topic/index.js+++ b/apps/web/src/components/topic/index.js@@ -89,21 +89,20 @@ const menuItems = [color: "error",iconColor: "error",onClick: async ({ items, notebookId }) => {- let showDeleteNotesDialog = confirm({- title: `Delete Contained Notes?`,- message: `Do you also want to delete notes within ${items.length > 1 ? "this topic" : "these topics"}?`,+ const shouldDeleteNotes = confirm({+ title: `Delete contained notes?`,+ message: `Do you also want to delete notes within ${+ items.length > 1 ? "this topic" : "these topics"+ }?`,yesText: `Yes`,noText: "No"});- let notes = [];- if (await showDeleteNotesDialog) {+ if (shouldDeleteNotes) {+ const notes = [];for (const item of items) {- for (const note of db.notebooks- .notebook(notebookId)- .topics.topic(item.id).all) {- notes.push(note);- }+ const topic = db.notebooks.notebook(notebookId).topics.topic(item.id);+ notes.push(...topic.all);}await Multiselect.moveNotesToTrash(notes, false);}