diff --git a/e2e/i18n.spec.ts b/e2e/i18n.spec.ts index 1ca65edf8..b4c9a0842 100644 --- a/e2e/i18n.spec.ts +++ b/e2e/i18n.spec.ts @@ -1,16 +1,24 @@ import { test, expect, Page } from "@playwright/test"; import App from "./support/app"; -test("Displays translation on desktop", async ({ page }) => { - const app = new App(page); +test("Displays translation on desktop", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); await expect(page.locator("#left-pane .quick-search input")) .toHaveAttribute("placeholder", "Quick search"); }); -test("Displays translations in Settings", async ({ page }) => { - const app = new App(page); +test("Displays translation on mobile", async ({ page, context }) => { + const app = new App(page, context); + await app.goto({ isMobile: true }); + + await expect(page.locator("#mobile-sidebar-wrapper .quick-search input")) + .toHaveAttribute("placeholder", "Quick search"); +}); + +test("Displays translations in Settings", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); await app.closeAllTabs(); await app.goToSettings(); @@ -20,8 +28,8 @@ test("Displays translations in Settings", async ({ page }) => { await expect(app.currentNoteSplit).toContainText("Language"); }); -test("User can change language from settings", async ({ page }) => { - const app = new App(page); +test("User can change language from settings", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); await app.closeAllTabs(); diff --git a/e2e/layout/tab_bar.spec.ts b/e2e/layout/tab_bar.spec.ts index 4d214b8dc..99391c115 100644 --- a/e2e/layout/tab_bar.spec.ts +++ b/e2e/layout/tab_bar.spec.ts @@ -3,8 +3,8 @@ import App from "../support/app"; const NOTE_TITLE = "Trilium Integration Test DB"; -test("Can drag tabs around", async ({ page }) => { - const app = new App(page); +test("Can drag tabs around", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); // [1]: Trilium Integration Test DB note @@ -29,8 +29,8 @@ test("Can drag tabs around", async ({ page }) => { await expect(app.getTab(0)).toContainText(NOTE_TITLE); }); -test("Can drag tab to new window", async ({ page }) => { - const app = new App(page); +test("Can drag tab to new window", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); await app.closeAllTabs(); @@ -54,6 +54,6 @@ test("Can drag tab to new window", async ({ page }) => { // Wait for the popup to show const popup = await popupPromise; - const popupApp = new App(popup); + const popupApp = new App(popup, context); await expect(popupApp.getActiveTab()).toHaveText(NOTE_TITLE); }); diff --git a/e2e/note_types/code.spec.ts b/e2e/note_types/code.spec.ts index 4f63588ee..6473b6849 100644 --- a/e2e/note_types/code.spec.ts +++ b/e2e/note_types/code.spec.ts @@ -1,8 +1,8 @@ import { test, expect, Page } from "@playwright/test"; import App from "../support/app"; -test("Displays lint warnings for backend script", async ({ page }) => { - const app = new App(page); +test("Displays lint warnings for backend script", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); await app.closeAllTabs(); await app.goToNoteInNewTab("Backend script with lint warnings"); @@ -21,8 +21,8 @@ test("Displays lint warnings for backend script", async ({ page }) => { await expectTooltip(page, "'world' is defined but never used."); }); -test("Displays lint errors for backend script", async ({ page }) => { - const app = new App(page); +test("Displays lint errors for backend script", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); await app.closeAllTabs(); await app.goToNoteInNewTab("Backend script with lint errors"); diff --git a/e2e/note_types/text.spec.ts b/e2e/note_types/text.spec.ts index 2a8880f18..d7b878724 100644 --- a/e2e/note_types/text.spec.ts +++ b/e2e/note_types/text.spec.ts @@ -1,8 +1,8 @@ import { test, expect, Page } from "@playwright/test"; import App from "../support/app"; -test("Table of contents is displayed", async ({ page }) => { - const app = new App(page); +test("Table of contents is displayed", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); await app.closeAllTabs(); await app.goToNoteInNewTab("Table of contents"); @@ -36,8 +36,8 @@ test("Table of contents is displayed", async ({ page }) => { await expect(rootList.locator("> ol").nth(1).locator("> ol > ol > ol")).toHaveCount(1); }); -test("Highlights list is displayed", async ({ page }) => { - const app = new App(page); +test("Highlights list is displayed", async ({ page, context }) => { + const app = new App(page, context); await app.goto(); await app.closeAllTabs(); await app.goToNoteInNewTab("Highlights list"); diff --git a/e2e/support/app.ts b/e2e/support/app.ts index 40546acae..08d1ebb77 100644 --- a/e2e/support/app.ts +++ b/e2e/support/app.ts @@ -1,27 +1,44 @@ -import { Locator, Page, expect } from "@playwright/test"; +import { expect, Locator, Page } from "@playwright/test"; +import type { BrowserContext } from "@playwright/test"; + +interface GotoOpts { + isMobile?: boolean; +} export default class App { readonly page: Page; + readonly context: BrowserContext; readonly tabBar: Locator; readonly noteTree: Locator; readonly currentNoteSplit: Locator; readonly sidebar: Locator; - constructor(page: Page) { + constructor(page: Page, context: BrowserContext) { this.page = page; + this.context = context; + this.tabBar = page.locator(".tab-row-widget-container"); this.noteTree = page.locator(".tree-wrapper"); this.currentNoteSplit = page.locator(".note-split:not(.hidden-ext)") this.sidebar = page.locator("#right-pane"); } - async goto() { + async goto(opts: GotoOpts = {}) { + await this.context.addCookies([ + { + url: "http://127.0.0.1:8082", + name: "trilium-device", + value: opts.isMobile ? "mobile" : "desktop" + } + ]); + await this.page.goto("/", { waitUntil: "networkidle" }); // Wait for the page to load. await expect(this.page.locator(".tree")) .toContainText("Trilium Integration Test"); + await this.closeAllTabs(); } async goToNoteInNewTab(noteTitle: string) { diff --git a/integration-tests/i18n.spec.ts b/integration-tests/i18n.spec.ts deleted file mode 100644 index 4cf7e31c2..000000000 --- a/integration-tests/i18n.spec.ts +++ /dev/null @@ -1,13 +0,0 @@ -import test, { expect } from "@playwright/test"; - -test("Restores language on start-up on mobile", async ({ page, context }) => { - await context.addCookies([ - { - url: "http://localhost:8082", - name: "trilium-device", - value: "mobile" - } - ]); - await page.goto("http://localhost:8082"); - await expect(page.locator("#launcher-pane div").first()).toContainText("Open New Window"); -});