Skip to content

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

web: improve tests reliability

Abdullah Attac85c51ec08cb
diff --git a/apps/web/__e2e__/backups.test.ts b/apps/web/__e2e__/backups.test.ts
index fcbf0c395..d444f1f2c 100644
--- a/apps/web/__e2e__/backups.test.ts
+++ b/apps/web/__e2e__/backups.test.ts
@@ -37,6 +37,7 @@ test("restore an unencrypted backup", async ({ page }) => {
const settings = await app.goToSettings();
await settings.restoreData("backup.nnbackup");
+ await app.toasts.waitForToast("Backup restored");
await settings.close();
const notes = await app.goToNotes();
@@ -66,6 +67,7 @@ test("restore an encrypted backup", async ({ page }) => {
const settings = await app.goToSettings();
await settings.restoreData("encrypted.nnbackup", USER.CURRENT.password);
+ await app.toasts.waitForToast("Backup restored");
await settings.close();
const notes = await app.goToNotes();
diff --git a/apps/web/__e2e__/editor.test.ts b/apps/web/__e2e__/editor.test.ts
index c87c4aa3e..dbf10bf6a 100644
--- a/apps/web/__e2e__/editor.test.ts
+++ b/apps/web/__e2e__/editor.test.ts
@@ -79,7 +79,7 @@ test("creating a new note should clear the editor contents & title", async ({
await notes.newNote();
expect(await notes.editor.isUnloaded()).toBeTruthy();
- expect(await notes.editor.getTitle()).toBe("");
+ await expect(notes.editor.title).toHaveValue("");
expect(await notes.editor.getContent("text")).toBe("");
});
@@ -113,7 +113,7 @@ test("opening an empty titled note should empty out editor contents", async ({
await onlyTitle?.openNote();
expect(await notes.editor.getContent("text")).toBe("");
- expect(await notes.editor.getTitle()).toBe(TITLE_ONLY_NOTE.title);
+ await expect(notes.editor.title).toHaveValue(TITLE_ONLY_NOTE.title);
});
test("focus should not jump to editor while typing in title input", async ({
@@ -126,7 +126,7 @@ test("focus should not jump to editor while typing in title input", async ({
await notes.editor.typeTitle("Hello", 200);
- expect(await notes.editor.getTitle()).toBe("Hello");
+ await expect(notes.editor.title).toHaveValue("Hello");
expect(await notes.editor.getContent("text")).toBe("");
});
@@ -142,21 +142,21 @@ test("when title format is set to headline, title should be generated from headl
const notes = await app.goToNotes();
await notes.createNote({ content: "my precious" });
- expect(await notes.editor.getTitle()).toBe("my precious");
+ await expect(notes.editor.title).toHaveValue("my precious");
await notes.editor.setContent(", my precious note");
await notes.editor.waitForSaving();
- expect(await notes.editor.getTitle()).toBe("my precious, my precious note");
+ await expect(notes.editor.title).toHaveValue("my precious, my precious note");
await notes.editor.setTitle("not precious");
- expect(await notes.editor.getTitle()).toBe("not precious");
+ await expect(notes.editor.title).toHaveValue("not precious");
await notes.editor.setContent(", but...");
await notes.editor.waitForSaving();
- expect(await notes.editor.getTitle()).toBe("not precious");
+ await expect(notes.editor.title).toHaveValue("not precious");
});
test("select all & backspace should clear all content in editor", async ({
@@ -177,7 +177,7 @@ test("select all & backspace should clear all content in editor", async ({
test("editing a note and switching immediately to another note and making an edit shouldn't overlap both notes", async ({
page
}, test) => {
- test.setTimeout(45 * 1000);
+ test.setTimeout(3 * 60 * 1000);
const app = new AppModel(page);
await app.goto();
@@ -216,7 +216,7 @@ test("editing a note and switching immediately to another note and making an edi
test("editing a note and switching immediately to another note and editing the title shouldn't overlap both notes", async ({
page
}, test) => {
- test.setTimeout(45 * 1000);
+ test.setTimeout(3 * 60 * 1000);
const app = new AppModel(page);
await app.goto();
@@ -332,7 +332,6 @@ test("disable autosave when note crosses MAX_AUTO_SAVEABLE_WORDS", async ({
"Auto-save is disabled for large notes. Press Ctrl + S to save."
)
).toBe(true);
- await expect(notes.editor.notSavedIcon).toBeVisible();
});
test("when autosave is disabled, pressing ctrl+s should save the note", async ({
@@ -469,12 +468,12 @@ test("control + alt + right arrow should go to next note", async ({ page }) => {
await note2?.openNote(true);
await page.keyboard.press("ControlOrMeta+Alt+ArrowRight");
- expect(await notes.editor.getTitle()).toBe("Note 1");
+ await expect(notes.editor.title).toHaveValue("Note 1");
expect(await notes.editor.getContent("text")).toBe("Note 1 content");
await page.keyboard.press("ControlOrMeta+Alt+ArrowRight");
- expect(await notes.editor.getTitle()).toBe("Note 2");
+ await expect(notes.editor.title).toHaveValue("Note 2");
expect(await notes.editor.getContent("text")).toBe("Note 2 content");
});
@@ -497,11 +496,11 @@ test("control + alt + left arrow should go to previous note", async ({
await note2?.openNote(true);
await page.keyboard.press("ControlOrMeta+Alt+ArrowLeft");
- expect(await notes.editor.getTitle()).toBe("Note 1");
+ await expect(notes.editor.title).toHaveValue("Note 1");
expect(await notes.editor.getContent("text")).toBe("Note 1 content");
await page.keyboard.press("ControlOrMeta+Alt+ArrowLeft");
- expect(await notes.editor.getTitle()).toBe("Note 2");
+ await expect(notes.editor.title).toHaveValue("Note 2");
expect(await notes.editor.getContent("text")).toBe("Note 2 content");
});
diff --git a/apps/web/__e2e__/models/editor.model.ts b/apps/web/__e2e__/models/editor.model.ts
index cc35e9378..f3460773c 100644
--- a/apps/web/__e2e__/models/editor.model.ts
+++ b/apps/web/__e2e__/models/editor.model.ts
@@ -24,7 +24,7 @@ import { iterateList } from "./utils";
export class EditorModel {
private readonly page: Page;
- private readonly title: Locator;
+ readonly title: Locator;
readonly content: Locator;
private readonly tags: Locator;
private readonly tagInput: Locator;
@@ -88,8 +88,9 @@ export class EditorModel {
{ expected: title }
);
- if (content !== undefined)
- await this.content.locator(":scope", { hasText: content }).waitFor();
+ if (content !== undefined) {
+ await this.waitForContent(content);
+ }
}
async waitForUnloading() {
@@ -109,6 +110,22 @@ export class EditorModel {
await this.wordCountText.waitFor();
}
+ async waitForContent(text: string) {
+ await this.page.waitForFunction(
+ ({ expected }) => {
+ const contentElement = document.querySelector(
+ `.active .ProseMirror`
+ ) as HTMLElement | null;
+ if (contentElement)
+ return contentElement.innerText
+ .replace(/\s+/g, "")
+ .includes(expected.replace(/\s+/g, ""));
+ return false;
+ },
+ { expected: text }
+ );
+ }
+
async isUnloaded() {
return (
(await this.tagInput.isDisabled()) &&
@@ -128,7 +145,7 @@ export class EditorModel {
await this.title.focus();
await this.title.selectText();
await this.title.press("ArrowRight");
- await this.title.type(text, { delay });
+ await this.title.pressSequentially(text, { delay });
});
}
@@ -136,6 +153,7 @@ export class EditorModel {
await this.editAndWait(async () => {
await this.content.focus();
await this.content.pressSequentially(text);
+ await this.waitForContent(text);
});
}
@@ -143,6 +161,7 @@ export class EditorModel {
await this.editAndWait(async () => {
await this.selectAll();
await this.content.press("Backspace");
+ await this.waitForContent("");
});
}
diff --git a/apps/web/__e2e__/models/notes-view.model.ts b/apps/web/__e2e__/models/notes-view.model.ts
index 790d2b8c4..0968a8b07 100644
--- a/apps/web/__e2e__/models/notes-view.model.ts
+++ b/apps/web/__e2e__/models/notes-view.model.ts
@@ -53,6 +53,7 @@ export class NotesViewModel extends BaseViewModel {
if (note.content) await this.editor.setContent(note.content);
await this.editor.waitForSaving();
+ if (note.content) await this.editor.waitForContent(note.content);
if (note.title) await this.waitForItem(note.title);
return await this.findNote(note);
}
diff --git a/apps/web/__e2e__/models/settings-view.model.ts b/apps/web/__e2e__/models/settings-view.model.ts
index f1fa8b6d5..690e42be3 100644
--- a/apps/web/__e2e__/models/settings-view.model.ts
+++ b/apps/web/__e2e__/models/settings-view.model.ts
@@ -141,8 +141,6 @@ export class SettingsViewModel {
await uploadFile(this.page, restoreBackup, filename);
if (password) await fillPasswordDialog(this.page, password);
-
- await waitForDialog(this.page, "Restoring backup");
}
async selectImageCompression(option: { value: string; label: string }) {
diff --git a/apps/web/playwright.config.ts b/apps/web/playwright.config.ts
index 74731374e..03ce9c7c6 100644
--- a/apps/web/playwright.config.ts
+++ b/apps/web/playwright.config.ts
@@ -31,7 +31,10 @@ const config: PlaywrightTestConfig = {
// Look for test files in thcleare "tests" directory, relative to this configuration file
testDir: "__e2e__",
- timeout: IS_CI ? 60 * 1000 : 30 * 1000,
+ timeout: IS_CI ? 60 * 1000 : 60 * 1000,
+ expect: {
+ timeout: 20 * 1000
+ },
workers: IS_CI ? 2 : 2,
reporter: "list",
retries: IS_CI ? 1 : 0,