Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix tests

Abdullah Atta9e1a864f5489
diff --git a/apps/web/__e2e__/models/app.model.ts b/apps/web/__e2e__/models/app.model.ts
index 2e87849cf..d056fe845 100644
--- a/apps/web/__e2e__/models/app.model.ts
+++ b/apps/web/__e2e__/models/app.model.ts
@@ -123,12 +123,9 @@ export class AppModel {
);
}
- async waitForSync(
- state: "completed" | "synced" = "completed",
- text?: string
- ) {
+ async waitForSync(state: "completed" | "synced" = "completed") {
await this.page
- .locator(getTestId(`sync-status-${state}`), { hasText: text })
+ .locator(getTestId(`sync-status-${state}`))
.waitFor({ state: "visible" });
}
diff --git a/apps/web/__e2e__/models/editor.model.ts b/apps/web/__e2e__/models/editor.model.ts
index 776b8e053..25d8756d7 100644
--- a/apps/web/__e2e__/models/editor.model.ts
+++ b/apps/web/__e2e__/models/editor.model.ts
@@ -23,7 +23,7 @@ import { getTestId } from "../utils";
export class EditorModel {
private readonly page: Page;
private readonly title: Locator;
- private readonly content: Locator;
+ readonly content: Locator;
private readonly tags: Locator;
private readonly tagInput: Locator;
private readonly focusModeButton: Locator;
diff --git a/apps/web/__e2e__/notes.test.ts b/apps/web/__e2e__/notes.test.ts
index 051a0ed6d..91dc1a6d1 100644
--- a/apps/web/__e2e__/notes.test.ts
+++ b/apps/web/__e2e__/notes.test.ts
@@ -252,11 +252,14 @@ test("unlock a note for editing", async ({ page }) => {
await note?.contextMenu.lock(PASSWORD);
await note?.openLockedNote(PASSWORD);
- const content = "Edits 1 2 3 ";
+ const content = "Edits 1 2 3";
await notes.editor.setContent(content);
await page.waitForTimeout(150);
- const newContent = `${content}${NOTE.content}`;
+ await page.reload();
+ await page.waitForTimeout(500);
+
+ const newContent = `${NOTE.content}${content}`;
const editedNote = await notes.findNote({
title: NOTE.title,
content: newContent
@@ -278,6 +281,9 @@ test("change title of a locked note", async ({ page }) => {
await notes.editor.setTitle(title);
await page.waitForTimeout(150);
+ await page.reload();
+ await page.waitForTimeout(500);
+
const editedNote = await notes.findNote({ title, content: NOTE.content });
await editedNote?.openLockedNote(PASSWORD);
await notes.editor.waitForLoading();
diff --git a/apps/web/__e2e__/sync.test.ts b/apps/web/__e2e__/sync.test.ts
index 46ce4f1b3..4d9186766 100644
--- a/apps/web/__e2e__/sync.test.ts
+++ b/apps/web/__e2e__/sync.test.ts
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { test, Browser, expect } from "@playwright/test";
import { AppModel } from "./models/app.model";
import { USER } from "./utils";
+import exp from "constants";
async function createDevice(browser: Browser) {
// Create two isolated browser contexts
@@ -28,7 +29,7 @@ async function createDevice(browser: Browser) {
const app = new AppModel(page);
await app.auth.goto();
await app.auth.login(USER.CURRENT);
- await app.waitForSync();
+ await app.waitForSync("synced");
return app;
}
@@ -39,7 +40,7 @@ async function actAndSync<T>(
) {
const results = await Promise.all([
...actions.filter((a) => !!a),
- ...devices.map((d) => d.waitForSync("completed"))
+ ...devices.map((d) => d.waitForSync("synced"))
]);
await Promise.all(devices.map((d) => d.page.waitForTimeout(2000)));
@@ -71,14 +72,14 @@ test(`edits in a note opened on 2 devices should sync in real-time`, async ({
if ((await notesB.editor.getContent("text")) !== "")
await actAndSync([deviceA, deviceB], notesB.editor.clear());
- expect(await notesA.editor.getContent("text")).toBe("");
- expect(await notesB.editor.getContent("text")).toBe("");
+ await expect(notesA.editor.content).toHaveText("");
+ await expect(notesB.editor.content).toHaveText("");
await actAndSync([deviceA, deviceB], notesB.editor.setContent(newContent));
expect(noteA).toBeDefined();
expect(noteB).toBeDefined();
- expect(await notesA.editor.getContent("text")).toBe(newContent);
- expect(await notesB.editor.getContent("text")).toBe(newContent);
+ await expect(notesA.editor.content).toHaveText(newContent);
+ await expect(notesB.editor.content).toHaveText(newContent);
});
function makeid(length: number) {
diff --git a/apps/web/__e2e__/user.test.ts b/apps/web/__e2e__/user.test.ts
index a99f0897c..92c5ebc8c 100644
--- a/apps/web/__e2e__/user.test.ts
+++ b/apps/web/__e2e__/user.test.ts
@@ -72,9 +72,7 @@ test("login user & wait for sync", async ({ page }, info) => {
await app.auth.login(USER.CURRENT);
- await page
- .locator(getTestId("sync-status-completed"))
- .waitFor({ state: "visible" });
+ await app.waitForSync("synced");
expect(await app.isSynced()).toBeTruthy();
});