Files
Oxicloud/tests/e2e/scenarios/helpers.ts
T
Edouard Vanbelle 891ff89a5d test(playwright): add playwright report to track changes + correct playwright parameters
ci: fix actions/checkout@v6 → @v4 (v6 does not exist)

GitHub started rejecting invalid action versions at parse time,
causing every CI run to fail with 0s / 'workflow file issue'
before any jobs could start.

 * test(e2e): only no retry
 * test(e2e): use static name in tests to facilitate screenshot comparaison
 * test(e2e): update linux screenshots
 * test(e2e): adapt test due to user-vignette generation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-27 11:29:58 +02:00

49 lines
2.0 KiB
TypeScript

import { Page, expect } from '@playwright/test';
export const TEST_ADMIN = {
username: 'admin',
email: 'testadmin@example.com',
password: 'TestPassword1!',
};
/**
* Log in as the test admin and wait until the main app is fully initialized.
*
* We wait for two things after the login redirect:
* 1. `#sidebar` — confirms the main HTML has loaded.
* 2. `#user-avatar-btn .user-vignette` — confirms that `setupUserMenu()` has
* run and mounted the avatar vignette. This is the earliest reliable
* signal that the click-handler on the avatar button is attached, so any
* subsequent test that opens the user menu will not race against JS startup.
*
* Without (2), CI (Ubuntu + Xvfb) occasionally clicks the button before the
* event listener is registered because the JS runtime is slower than on macOS.
*/
export async function loginAsAdmin(page: Page) {
await goToLoginPage(page);
await page.locator('#login-username').fill(TEST_ADMIN.username);
await page.locator('#login-password').fill(TEST_ADMIN.password);
await page.locator('#login-panel button[type="submit"]').click();
await expect(page.locator('#sidebar')).toBeVisible({ timeout: 15_000 });
// Wait for the JS app to initialise: avatar vignette present ⟹ click handler attached.
await expect(page.locator('#user-avatar-btn .user-vignette')).toBeAttached({ timeout: 10_000 });
}
/**
* Navigate to `/` and land on the login panel, handling the language selector
* if it appears (fresh localStorage). The admin account is guaranteed to exist
* because globalSetup created it before any test ran.
*/
export async function goToLoginPage(page: Page) {
await page.goto('/');
// Both panels start with .hidden — wait for JS to reveal one.
await page.waitForSelector('#language-panel:not(.hidden), #login-panel:not(.hidden)');
if (await page.locator('#language-panel').isVisible()) {
await page.locator('#language-continue').click();
}
await expect(page.locator('#login-panel')).toBeVisible();
}