chore(e2e): add test for dragging tabs

This commit is contained in:
Elian Doran 2025-01-11 00:13:46 +02:00
parent ef8708ab2b
commit 13d3429424
No known key found for this signature in database
3 changed files with 133 additions and 65 deletions

View File

@ -0,0 +1,29 @@
import { test, expect } from "@playwright/test";
import App from "../support/app";
test("Can drag tabs around", async ({ page }) => {
const app = new App(page);
await app.goto();
// [1]: Trilium Integration Test DB note
const noteTitle = "Trilium Integration Test DB";
await app.closeAllTabs();
await app.clickNoteOnNoteTreeByTitle(noteTitle);
await expect(app.getActiveTab()).toContainText(noteTitle);
// [1] [2] [3]
await app.addNewTab();
await app.addNewTab();
let tab = app.getTab(0);
// Drag the first tab at the end
await tab.dragTo(app.getTab(2), { targetPosition: { x: 50, y: 0 }});
tab = app.getTab(2);
await expect(tab).toContainText(noteTitle);
// Drag the tab to the left
await tab.dragTo(app.getTab(0), { targetPosition: { x: 50, y: 0 }});
await expect(app.getTab(0)).toContainText(noteTitle);
});

45
e2e/support/app.ts Normal file
View File

@ -0,0 +1,45 @@
import { Locator, Page, expect } from "@playwright/test";
export default class App {
readonly page: Page;
readonly tabBar: Locator;
readonly noteTree: Locator;
constructor(page: Page) {
this.page = page;
this.tabBar = page.locator(".tab-row-widget-container");
this.noteTree = page.locator(".tree-wrapper");
}
async goto() {
await this.page.goto("/", { waitUntil: "networkidle" });
// Wait for the page to load.
await expect(this.page.locator(".tree"))
.toContainText("Trilium Integration Test");
}
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 });
}
async addNewTab() {
await this.page.locator('[data-trigger-command="openNewTab"]').click();
}
async clickNoteOnNoteTreeByTitle(title: string) {
this.noteTree.getByText(title).click();
}
}

View File

@ -1,17 +1,18 @@
import { defineConfig, devices } from "@playwright/test"; import { defineConfig, devices } from '@playwright/test';
/** /**
* Read environment variables from file. * Read environment variables from file.
* https://github.com/motdotla/dotenv * https://github.com/motdotla/dotenv
*/ */
// import dotenv from 'dotenv'; // import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') }); // dotenv.config({ path: path.resolve(__dirname, '.env') });
/** /**
* See https://playwright.dev/docs/test-configuration. * See https://playwright.dev/docs/test-configuration.
*/ */
export default defineConfig({ export default defineConfig({
testDir: "./integration-tests", testDir: './e2e',
/* Run tests in files in parallel */ /* Run tests in files in parallel */
fullyParallel: true, fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */ /* Fail the build on CI if you accidentally left test.only in the source code. */
@ -21,39 +22,32 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */ /* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined, workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html", reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: { use: {
/* Base URL to use in actions like `await page.goto('/')`. */ /* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000', baseURL: 'http://127.0.0.1:8082',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry" trace: 'on-first-retry',
},
webServer: {
command: "npm run integration-mem-db",
url: "http://127.0.0.1:8082",
reuseExistingServer: true,
stdout: "ignore",
stderr: "pipe"
}, },
/* Configure projects for major browsers */ /* Configure projects for major browsers */
projects: [ projects: [
{ {
name: "setup", name: 'chromium',
testMatch: /.*\.setup\.ts/ use: { ...devices['Desktop Chrome'] },
}, },
{ {
name: "firefox", name: 'firefox',
use: { use: { ...devices['Desktop Firefox'] },
...devices["Desktop Firefox"], },
storageState: "playwright/.auth/user.json"
{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
}, },
dependencies: ["setup"]
}
/* Test against mobile viewports. */ /* Test against mobile viewports. */
// { // {
@ -74,7 +68,7 @@ export default defineConfig({
// name: 'Google Chrome', // name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// }, // },
] ],
/* Run your local dev server before starting the tests */ /* Run your local dev server before starting the tests */
// webServer: { // webServer: {