Notes/e2e/support/app.ts

79 lines
2.4 KiB
TypeScript
Raw Normal View History

import { expect, Locator, Page } from "@playwright/test";
import type { BrowserContext } from "@playwright/test";
interface GotoOpts {
isMobile?: boolean;
}
2025-01-11 00:13:46 +02:00
export default class App {
readonly page: Page;
readonly context: BrowserContext;
2025-01-11 00:13:46 +02:00
readonly tabBar: Locator;
readonly noteTree: Locator;
2025-01-11 12:48:59 +02:00
readonly currentNoteSplit: Locator;
readonly sidebar: Locator;
2025-01-11 00:13:46 +02:00
constructor(page: Page, context: BrowserContext) {
2025-01-11 00:13:46 +02:00
this.page = page;
this.context = context;
2025-01-11 00:13:46 +02:00
this.tabBar = page.locator(".tab-row-widget-container");
this.noteTree = page.locator(".tree-wrapper");
2025-01-11 12:48:59 +02:00
this.currentNoteSplit = page.locator(".note-split:not(.hidden-ext)")
this.sidebar = page.locator("#right-pane");
2025-01-11 00:13:46 +02:00
}
async goto(opts: GotoOpts = {}) {
await this.context.addCookies([
{
url: "http://127.0.0.1:8082",
name: "trilium-device",
value: opts.isMobile ? "mobile" : "desktop"
}
]);
2025-01-11 00:13:46 +02:00
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();
2025-01-11 00:13:46 +02:00
}
2025-01-11 12:48:59 +02:00
async goToNoteInNewTab(noteTitle: string) {
const autocomplete = this.currentNoteSplit.locator(".note-autocomplete");
await autocomplete.fill(noteTitle);
await autocomplete.press("ArrowDown");
await autocomplete.press("Enter");
}
async goToSettings() {
await this.page.locator(".launcher-button.bx-cog").click();
}
2025-01-11 00:13:46 +02:00
getTab(tabIndex: number) {
return this.tabBar.locator(".note-tab-wrapper").nth(tabIndex);
}
getActiveTab() {
return this.tabBar.locator(".note-tab[active]");
}
async closeAllTabs() {
await this.getTab(0).click({ button: "right" });
await this.page.waitForTimeout(500); // TODO: context menu won't dismiss otherwise
await this.page.getByText("Close all tabs").click({ force: true });
await this.page.waitForTimeout(500); // TODO: context menu won't dismiss otherwise
2025-01-11 00:13:46 +02:00
}
async addNewTab() {
await this.page.locator('[data-trigger-command="openNewTab"]').click();
}
async clickNoteOnNoteTreeByTitle(title: string) {
this.noteTree.getByText(title).click();
}
}