mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
fix(e2e): leaks if language fails
This commit is contained in:
parent
89d700d5ed
commit
b69cad2298
@ -1,6 +1,12 @@
|
|||||||
import { test, expect, Page } from "@playwright/test";
|
import { test, expect, Page } from "@playwright/test";
|
||||||
import App from "./support/app";
|
import App from "./support/app";
|
||||||
|
|
||||||
|
test.afterEach(async ({ page, context }) => {
|
||||||
|
const app = new App(page, context);
|
||||||
|
// Ensure English is set after each locale change to avoid any leaks to other tests.
|
||||||
|
await app.setOption("locale", "en");
|
||||||
|
});
|
||||||
|
|
||||||
test("Displays translation on desktop", async ({ page, context }) => {
|
test("Displays translation on desktop", async ({ page, context }) => {
|
||||||
const app = new App(page, context);
|
const app = new App(page, context);
|
||||||
await app.goto();
|
await app.goto();
|
||||||
|
@ -5,6 +5,8 @@ interface GotoOpts {
|
|||||||
isMobile?: boolean;
|
isMobile?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BASE_URL = "http://127.0.0.1:8082";
|
||||||
|
|
||||||
export default class App {
|
export default class App {
|
||||||
readonly page: Page;
|
readonly page: Page;
|
||||||
readonly context: BrowserContext;
|
readonly context: BrowserContext;
|
||||||
@ -27,7 +29,7 @@ export default class App {
|
|||||||
async goto(opts: GotoOpts = {}) {
|
async goto(opts: GotoOpts = {}) {
|
||||||
await this.context.addCookies([
|
await this.context.addCookies([
|
||||||
{
|
{
|
||||||
url: "http://127.0.0.1:8082",
|
url: BASE_URL,
|
||||||
name: "trilium-device",
|
name: "trilium-device",
|
||||||
value: opts.isMobile ? "mobile" : "desktop"
|
value: opts.isMobile ? "mobile" : "desktop"
|
||||||
}
|
}
|
||||||
@ -92,4 +94,17 @@ export default class App {
|
|||||||
}, command);
|
}, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setOption(key: string, value: string) {
|
||||||
|
const csrfToken = await this.page.evaluate(() => {
|
||||||
|
return (window as any).glob.csrfToken;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(csrfToken).toBeTruthy();
|
||||||
|
await expect(await this.page.request.put(`${BASE_URL}/api/options/${key}/${value}`, {
|
||||||
|
headers: {
|
||||||
|
"x-csrf-token": csrfToken
|
||||||
|
}
|
||||||
|
})).toBeOK();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user