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: add tests for new tabs
Abdullah Attaf31df9a6cc28
diff --git a/apps/web/__e2e__/models/base-item.model.ts b/apps/web/__e2e__/models/base-item.model.tsindex 919ff0bf8..c719df9d3 100644--- a/apps/web/__e2e__/models/base-item.model.ts+++ b/apps/web/__e2e__/models/base-item.model.ts@@ -39,10 +39,12 @@ export class BaseItemModel {return await this.locator.evaluate((el) => el === document.activeElement);}- async click() {+ async click(options?: { middleClick?: boolean }) {if (!(await this.locator.isVisible()))await this.locator.scrollIntoViewIfNeeded();- await this.locator.click();+ await this.locator.click({+ button: options?.middleClick ? "middle" : "left"+ });}async getId() {diff --git a/apps/web/__e2e__/models/editor.model.ts b/apps/web/__e2e__/models/editor.model.tsindex 729d89696..1082a1b7e 100644--- a/apps/web/__e2e__/models/editor.model.ts+++ b/apps/web/__e2e__/models/editor.model.ts@@ -36,6 +36,8 @@ export class EditorModel {private readonly dateEditedText: Locator;private readonly searchButton: Locator;private readonly tabsList: Locator;+ private readonly goBackButton: Locator;+ private readonly goForwardButton: Locator;readonly savedIcon: Locator;readonly notSavedIcon: Locator;@@ -59,6 +61,8 @@ export class EditorModel {this.savedIcon = page.locator(getTestId("editor-save-state-saved"));this.notSavedIcon = page.locator(getTestId("editor-save-state-notsaved"));this.tabsList = page.locator(getTestId("tabs"));+ this.goBackButton = page.locator(getTestId("go-back"));+ this.goForwardButton = page.locator(getTestId("go-forward"));}async waitForLoading(title?: string, content?: string) {@@ -243,6 +247,22 @@ export class EditorModel {}}+ async getTabs() {+ const tabs: TabItemModel[] = [];+ for await (const item of iterateList(this.tabsList.locator(".tab"))) {+ tabs.push(new TabItemModel(item, this.page));+ }+ return tabs;+ }++ async goBack() {+ await this.goBackButton.click();+ }++ async goForward() {+ await this.goForwardButton.click();+ }+async attachImage() {await this.page.context()diff --git a/apps/web/__e2e__/models/note-properties.model.ts b/apps/web/__e2e__/models/note-properties.model.tsindex b167cfa92..576bf5d92 100644--- a/apps/web/__e2e__/models/note-properties.model.ts+++ b/apps/web/__e2e__/models/note-properties.model.ts@@ -211,6 +211,11 @@ export class NoteContextMenuModel extends BaseProperties {this.menu = new ContextMenuModel(page);}+ async openInNewTab() {+ await this.open();+ await this.menu.clickOnItem("openinnewtab");+ }+async isColored(color: string): Promise<boolean> {await this.open();await this.menu.clickOnItem("colors");diff --git a/apps/web/__e2e__/models/tab-item.model.ts b/apps/web/__e2e__/models/tab-item.model.tsindex c760f1f17..4ede833eb 100644--- a/apps/web/__e2e__/models/tab-item.model.ts+++ b/apps/web/__e2e__/models/tab-item.model.ts@@ -30,6 +30,9 @@ export class TabItemModel {const testId = await this.locator.getAttribute("data-test-id");return testId?.replace("tab-", "");}+ async title() {+ return this.locator.locator(getTestId("tab-title")).textContent();+ }close() {return this.closeButton.click();}diff --git a/apps/web/__e2e__/tabs.test.ts b/apps/web/__e2e__/tabs.test.tsnew file mode 100644index 000000000..3b22b1081--- /dev/null+++ b/apps/web/__e2e__/tabs.test.ts@@ -0,0 +1,113 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++import { test, expect } from "@playwright/test";+import { AppModel } from "./models/app.model";++test("notes should open in the same tab", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ await notes.createNote({ title: "Note 1" });+ await notes.createNote({ title: "Note 2" });+ await notes.createNote({ title: "Note 3" });+ await page.reload();++ const note = await notes.findNote({ title: "Note 2" });+ await note?.click();++ const tabs = await notes.editor.getTabs();+ expect(tabs.length).toBe(1);+});++test("new note should open in the same tab", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ await notes.createNote({ title: "Note 1" });++ await notes.newNote();++ const tabs = await notes.editor.getTabs();+ expect(tabs.length).toBe(1);+});++test("open note in new tab (using context menu)", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ await notes.createNote({ title: "Note 1" });+ await notes.createNote({ title: "Note 2" });+ await notes.createNote({ title: "Note 3" });++ const note = await notes.findNote({ title: "Note 2" });+ await note?.contextMenu.openInNewTab();++ const tabs = await notes.editor.getTabs();+ expect(tabs.length).toBe(2);+ expect(await tabs[1].title()).toBe("Note 2");+});++test("open note in new tab (using middle click)", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ await notes.createNote({ title: "Note 1" });+ await notes.createNote({ title: "Note 2" });+ await notes.createNote({ title: "Note 3" });++ const note = await notes.findNote({ title: "Note 2" });+ await note?.click({ middleClick: true });++ const tabs = await notes.editor.getTabs();+ expect(tabs.length).toBe(2);+ expect(await tabs[1].title()).toBe("Note 2");+});++test("go back should open previous note", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ const tabs = await notes.editor.getTabs();+ await notes.createNote({ title: "Note 1" });+ await notes.createNote({ title: "Note 2" });+ await notes.createNote({ title: "Note 3" });++ await notes.editor.goBack();+ expect(await tabs[0].title()).toBe("Note 2");+ await notes.editor.goBack();+ expect(await tabs[0].title()).toBe("Note 1");+});++test("go forward should open next note", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ const tabs = await notes.editor.getTabs();+ await notes.createNote({ title: "Note 1" });+ await notes.createNote({ title: "Note 2" });+ await notes.createNote({ title: "Note 3" });++ await notes.editor.goBack();+ await notes.editor.goBack();+ await notes.editor.goForward();+ expect(await tabs[0].title()).toBe("Note 2");+ await notes.editor.goForward();+ expect(await tabs[0].title()).toBe("Note 3");+});diff --git a/apps/web/src/components/editor/action-bar.tsx b/apps/web/src/components/editor/action-bar.tsxindex a498d1b3c..66fa0deca 100644--- a/apps/web/src/components/editor/action-bar.tsx+++ b/apps/web/src/components/editor/action-bar.tsx@@ -325,6 +325,7 @@ function TabStrip() {onClick={() => useEditorStore.getState().goBack()}variant="secondary"sx={{ p: 1, bg: "transparent" }}+ data-test-id="go-back"><ArrowLeft size={15} /></Button>@@ -333,6 +334,7 @@ function TabStrip() {onClick={() => useEditorStore.getState().goForward()}variant="secondary"sx={{ p: 1, bg: "transparent" }}+ data-test-id="go-forward"><ArrowRight size={15} /></Button>@@ -610,6 +612,7 @@ function Tab(props: TabProps) {}/><Text+ data-test-id="tab-title"variant="body"sx={{whiteSpace: "nowrap",diff --git a/apps/web/src/components/note/index.tsx b/apps/web/src/components/note/index.tsxindex e8e86bafe..66447cca7 100644--- a/apps/web/src/components/note/index.tsx+++ b/apps/web/src/components/note/index.tsx@@ -146,7 +146,7 @@ function Note(props: NoteProps) {menuItems={menuItems}onClick={() => useEditorStore.getState().openSession(note)}onMiddleClick={() =>- useEditorStore.getState().openSession(note, { newSession: true })+ useEditorStore.getState().openSession(note, { openInNewTab: true })}header={<Flex@@ -331,6 +331,14 @@ const menuItems: (// const isSynced = db.notes.note(note.id)?.synced();return [+ {+ type: "button",+ key: "openinnewtab",+ title: strings.openInNewTab(),+ icon: OpenInNew.path,+ onClick: () =>+ useEditorStore.getState().openSession(note.id, { openInNewTab: true })+ },{type: "button",key: "pin",diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex 8225498f6..c9ccc3208 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -608,9 +608,12 @@ class EditorStore extends BaseStore<EditorStore> {force?: boolean;activeBlockId?: string;silent?: boolean;+ openInNewTab?: boolean;} = {}): Promise<void> => {- const tabId = this.get().activeTabId ?? this.addTab();+ const tabId = options.openInNewTab+ ? this.addTab()+ : this.get().activeTabId ?? this.addTab();const { getSession, openDiffSession } = this.get();const noteId = typeof noteOrId === "string" ? noteOrId : noteOrId.id;@@ -1122,12 +1125,11 @@ class EditorStore extends BaseStore<EditorStore> {return session as SessionTypeMap[T[number]];};- addTab = (tab?: Omit<Partial<TabItem>, "id">) => {+ addTab = () => {const id = getId();const sessionId = tabSessionHistory.add(id);this.set((state) => {state.tabs.push({- ...tab,id,sessionId});