From 99dbcaff7d6ff65062c00799c68dfa87e85d1e2a Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 24 Feb 2025 12:19:21 +0500 Subject: [PATCH] web: make tabs tests more resilient --- apps/web/__e2e__/models/tab-item.model.ts | 6 +++-- apps/web/__e2e__/tabs.test.ts | 29 ++++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/apps/web/__e2e__/models/tab-item.model.ts b/apps/web/__e2e__/models/tab-item.model.ts index 88f29ab3e..a328102be 100644 --- a/apps/web/__e2e__/models/tab-item.model.ts +++ b/apps/web/__e2e__/models/tab-item.model.ts @@ -24,10 +24,12 @@ import { ContextMenuModel } from "./context-menu.model"; export class TabItemModel { private readonly closeButton: Locator; readonly contextMenu: TabContextMenuModel; + readonly titleElement: Locator; - constructor(private readonly locator: Locator, page: Page) { + constructor(readonly locator: Locator, page: Page) { this.closeButton = locator.locator(getTestId("tab-close-button")); this.contextMenu = new TabContextMenuModel(page, locator); + this.titleElement = locator.locator(getTestId("tab-title")); } async getId() { @@ -40,7 +42,7 @@ export class TabItemModel { } async title() { - return this.locator.locator(getTestId("tab-title")).textContent(); + return this.titleElement.textContent(); } async isActive() { diff --git a/apps/web/__e2e__/tabs.test.ts b/apps/web/__e2e__/tabs.test.ts index a0526be35..fbf2a6765 100644 --- a/apps/web/__e2e__/tabs.test.ts +++ b/apps/web/__e2e__/tabs.test.ts @@ -63,7 +63,7 @@ test("open note in new tab (using context menu)", async ({ page }) => { const tabs = await notes.editor.getTabs(); expect(tabs.length).toBe(2); - expect(await tabs[1].title()).toBe("Note 2"); + await expect(tabs[1].titleElement).toHaveText("Note 2"); }); test("open note in new tab (using middle click)", async ({ page }) => { @@ -80,7 +80,7 @@ test("open note in new tab (using middle click)", async ({ page }) => { const tabs = await notes.editor.getTabs(); expect(tabs.length).toBe(2); - expect(await tabs[1].title()).toBe("Note 2"); + await expect(tabs[1].titleElement).toHaveText("Note 2"); }); test("go back should open previous note", async ({ page }) => { @@ -93,9 +93,9 @@ test("go back should open previous note", async ({ page }) => { await notes.createNote({ title: "Note 3" }); await notes.editor.goBack(); - expect(await tabs[0].title()).toBe("Note 2"); + await expect(tabs[0].titleElement).toHaveText("Note 2"); await notes.editor.goBack(); - expect(await tabs[0].title()).toBe("Note 1"); + await expect(tabs[0].titleElement).toHaveText("Note 1"); }); test("go forward should open next note", async ({ page }) => { @@ -110,9 +110,9 @@ test("go forward should open next note", async ({ page }) => { await notes.editor.goBack(); await notes.editor.goBack(); await notes.editor.goForward(); - expect(await tabs[0].title()).toBe("Note 2"); + await expect(tabs[0].titleElement).toHaveText("Note 2"); await notes.editor.goForward(); - expect(await tabs[0].title()).toBe("Note 3"); + await expect(tabs[0].titleElement).toHaveText("Note 3"); }); test("new tab button should open a new tab", async ({ page }) => { @@ -124,8 +124,8 @@ test("new tab button should open a new tab", async ({ page }) => { await notes.editor.newTab(); const tabs = await notes.editor.getTabs(); - expect(await tabs[0].title()).toBe("Note 1"); - expect(await tabs[1].title()).toBe("Untitled"); + await expect(tabs[0].titleElement).toHaveText("Note 1"); + await expect(tabs[1].titleElement).toHaveText("Untitled"); }); test("content changes in a note opened in multiple tabs should sync", async ({ @@ -173,6 +173,7 @@ test("reloading with a note diff open in a tab", async ({ page }) => { const history = await note?.properties.getSessionHistory(); const preview = await history?.[0].open(); await preview!.firstEditor.waitFor({ state: "visible" }); + await page.waitForTimeout(1000); await page.reload(); await preview!.firstEditor.waitFor({ state: "visible" }); @@ -227,7 +228,7 @@ test("clicking on a note that's already opened in another tab should focus the t await note?.openNote(); const tabs = await notes.editor.getTabs(); - expect(await tabs[0].isActive()).toBe(true); + await expect(tabs[0].locator).toHaveClass(/active/); }); test("open a note in 2 tabs then open another note and navigate back", async ({ @@ -248,8 +249,8 @@ test("open a note in 2 tabs then open another note and navigate back", async ({ await notes.editor.goBack(); const tabs = await notes.editor.getTabs(); - expect(await tabs[1].isActive()).toBe(true); - expect(await tabs[1].title()).toBe("Note 1"); + await expect(tabs[1].locator).toHaveClass(/active/); + await expect(tabs[1].titleElement).toHaveText("Note 1"); }); test("shouldn't be possible to open a note in a pinned tab", async ({ @@ -272,8 +273,8 @@ test("shouldn't be possible to open a note in a pinned tab", async ({ tabs = await notes.editor.getTabs(); expect(tabs.length).toBe(2); - expect(await tabs[1].isActive()).toBe(true); - expect(await tabs[1].title()).toBe("Note 1"); + await expect(tabs[1].locator).toHaveClass(/active/); + await expect(tabs[1].titleElement).toHaveText("Note 1"); }); test("shouldn't be possible to create a new note in a pinned tab", async ({ @@ -292,7 +293,7 @@ test("shouldn't be possible to create a new note in a pinned tab", async ({ tabs = await notes.editor.getTabs(); expect(tabs.length).toBe(2); - expect(await tabs[1].isActive()).toBe(true); + await expect(tabs[1].locator).toHaveClass(/active/); }); test("notes open in multiple tabs should sync tags when tags are added", async ({