freshyo/tests/web/specs/admins.spec.ts
2026-10-05 11:46:47 +05:30

29 lines
1.4 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { loginAsSuperadmin, superadminUrl, stamp } from '../lib/helpers';
import { staffLogin } from '../lib/trpc';
test('create admin in a region, new admin can log in (tests 5.1/5.2-setup)', async ({ page }) => {
const name = `pw-admin-${stamp()}`;
const password = 'testAdmin123';
await loginAsSuperadmin(page);
await page.goto(`${superadminUrl()}/admins`, { waitUntil: 'networkidle' });
await page.waitForTimeout(1500);
await page.fill('input[placeholder^="e.g. ravi"]', name);
await page.fill('input[type="password"]', password);
const selects = await page.$$('select');
expect(selects).toHaveLength(2);
await selects[0].selectOption({ label: 'admin' });
// Pick the second region option (first is the placeholder).
const regionLabels: string[] = await selects[1].$$eval('option', els => els.map(e => (e.textContent || '').trim()));
const target = regionLabels.find(l => l && l !== 'Select a region');
expect(target, 'expected at least one region option').toBeDefined();
await selects[1].selectOption({ label: target! });
await page.click('button:has-text("Create Admin")');
await page.waitForTimeout(4000);
// New admin authenticates and carries a region.
const { staff } = await staffLogin(name, password);
expect(staff.regionId).toBeGreaterThan(0);
expect(staff.roleName).toBe('admin');
});