35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { Page, expect } from '@playwright/test';
|
|
|
|
export const superadminUrl = () => process.env.SUPERADMIN_URL || 'http://localhost:4175';
|
|
export const superadminName = () => process.env.SUPERADMIN_NAME || 'shafi';
|
|
export const superadminPassword = () => {
|
|
const pw = process.env.SUPERADMIN_PASSWORD;
|
|
if (!pw) throw new Error('SUPERADMIN_PASSWORD is required (see tests/web/.env.example)');
|
|
return pw;
|
|
};
|
|
|
|
/** Log in through the UI; ends on /dashboard. */
|
|
export async function loginAsSuperadmin(page: Page, name?: string, password?: string) {
|
|
await page.goto(`${superadminUrl()}/login`, { waitUntil: 'networkidle' });
|
|
await page.fill('input[placeholder="Enter your name"]', name ?? superadminName());
|
|
await page.fill('input[placeholder="Enter your password"]', password ?? superadminPassword());
|
|
await page.click('button:has-text("Login")');
|
|
await page.waitForURL('**/dashboard**', { timeout: 20_000 });
|
|
await expect(page).toHaveURL(/\/dashboard/);
|
|
}
|
|
|
|
/** Unique suffix so reruns never collide with earlier test entities. */
|
|
export const stamp = () => Date.now().toString(36);
|
|
|
|
/** Small isolated polygon around a point (lng/lat box, degrees). */
|
|
export const boxPolygon = (lng: number, lat: number, size = 0.005) =>
|
|
JSON.stringify({
|
|
type: 'Polygon',
|
|
coordinates: [[
|
|
[lng, lat],
|
|
[lng + size, lat],
|
|
[lng + size, lat + size],
|
|
[lng, lat + size],
|
|
[lng, lat],
|
|
]],
|
|
});
|