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 more tests
Abdullah Attac9a3f31e8f74
diff --git a/apps/web/__e2e__/models/tab-item.model.ts b/apps/web/__e2e__/models/tab-item.model.tsindex 4ede833eb..f18db1b8e 100644--- a/apps/web/__e2e__/models/tab-item.model.ts+++ b/apps/web/__e2e__/models/tab-item.model.ts@@ -30,9 +30,15 @@ export class TabItemModel {const testId = await this.locator.getAttribute("data-test-id");return testId?.replace("tab-", "");}++ async click() {+ return this.locator.click();+ }+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.tsindex 15ce49803..5ed7d3540 100644--- a/apps/web/__e2e__/tabs.test.ts+++ b/apps/web/__e2e__/tabs.test.ts@@ -124,3 +124,43 @@ test("new tab button should open a new tab", async ({ page }) => {expect(await tabs[0].title()).toBe("Note 1");expect(await tabs[1].title()).toBe("Untitled");});++test("changes in a note opened in multiple tabs should sync", async ({+ page+}) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ const note = await notes.createNote({ title: "Note 1" });+ await note?.contextMenu.openInNewTab();++ await notes.editor.editAndWait(async () => {+ await notes.editor.setContent("This change should sync.");+ });++ const tabs = await notes.editor.getTabs();+ await tabs[0].click();+ expect(await notes.editor.getContent("text")).toBe(+ "This change should sync."+ );+});++test("open same note in 2 tabs and refresh page", async ({ page }) => {+ const app = new AppModel(page);+ await app.goto();+ const notes = await app.goToNotes();+ const note = await notes.createNote({+ title: "Note 1",+ content: "Some edits."+ });+ await note?.contextMenu.openInNewTab();+ await notes.editor.waitForLoading();++ await page.reload();+ await notes.waitForList();++ const tabs = await notes.editor.getTabs();+ await tabs[0].click();+ await notes.editor.waitForLoading();+ expect(await notes.editor.getContent("text")).toBe("Some edits.");+});diff --git a/apps/web/src/components/editor/index.tsx b/apps/web/src/components/editor/index.tsxindex 9b2415a1c..fafbdd179 100644--- a/apps/web/src/components/editor/index.tsx+++ b/apps/web/src/components/editor/index.tsx@@ -352,10 +352,16 @@ function EditorView({}onContentChange={() => (lastChangedTime.current = Date.now())}onSave={(content, ignoreEdit) => {- const noteId = "note" in session ? session.note.id : null;+ const currentSession = useEditorStore+ .getState()+ .getSession(session.id);+ const noteId =+ currentSession && "note" in currentSession+ ? currentSession.note.id+ : null;const sessions = noteId? useEditorStore.getState().getSessionsForNote(noteId)- : [session];+ : [currentSession];const currentSessionId = session.id;const data = content();diff --git a/apps/web/src/stores/editor-store.ts b/apps/web/src/stores/editor-store.tsindex c9ccc3208..8b1931c11 100644--- a/apps/web/src/stores/editor-store.ts+++ b/apps/web/src/stores/editor-store.ts@@ -481,27 +481,27 @@ class EditorStore extends BaseStore<EditorStore> {});- const {- openSession,- openDiffSession,- activateSession,- activeTabId,- getSession,- newSession- } = this.get();+ const { rehydrateTab, activeTabId, newSession } = this.get();if (activeTabId) {- const tab = this.get().tabs.find((t) => t.id === activeTabId);- if (!tab) return;- const session = getSession(tab.sessionId);- if (!session) return;-- if (session.type === "diff" || session.type === "conflicted")- openDiffSession(session.note.id, session.id);- else if (session.type === "new") activateSession(session.id);- else openSession(session.note);+ rehydrateTab(activeTabId);} else newSession();};+ private rehydrateTab = (tabId: string) => {+ const { openSession, openDiffSession, activateSession, getSession } =+ this.get();++ const tab = this.get().tabs.find((t) => t.id === tabId);+ if (!tab) return;+ const session = getSession(tab.sessionId);+ if (!session || !session.needsHydration) return;++ if (session.type === "diff" || session.type === "conflicted")+ openDiffSession(session.note.id, session.id);+ else if (session.type === "new") activateSession(session.id);+ else openSession(session.note);+ };+updateSession = <T extends SessionType[] = SessionType[]>(id: string,types: T | undefined,@@ -1156,6 +1156,8 @@ class EditorStore extends BaseStore<EditorStore> {canGoBack: tabSessionHistory.canGoBack(id),canGoForward: tabSessionHistory.canGoForward(id)});++ this.rehydrateTab(id);};}