import { test, expect } from '@playwright/test'; import { loginAsSuperadmin, superadminUrl, stamp, boxPolygon } from '../lib/helpers'; const botToken = () => process.env.TEST_BOT_TOKEN || '8410461852:AAGXQCwRPFbndqwTgLJh8kYxST4Z0vgh72U'; const chatId = () => process.env.TEST_CHAT_ID || `51477600${stamp().slice(-2)}`; test('regions list loads (regression: admin getRegions 500)', async ({ page }) => { await loginAsSuperadmin(page); await page.goto(`${superadminUrl()}/regions`, { waitUntil: 'networkidle' }); await expect(page.getByText('Add Region')).toBeVisible(); // The list query must not render the error state (region_bounds drift bug). await expect(page.getByText('Error loading regions')).not.toBeVisible(); }); test('create region with two bounds + telegram cred (test 1)', async ({ page }) => { const name = `PW-Region-${stamp()}`; await loginAsSuperadmin(page); await page.goto(`${superadminUrl()}/regions/new`, { waitUntil: 'networkidle' }); await page.fill('input[placeholder="e.g. Mahabubnagar Town"]', name); await page.fill('textarea[placeholder="Optional description"]', 'Playwright-created test region'); // Bound 1 (default card). await page.fill('input[placeholder="e.g. Mbnr-1"]', 'PW-Core'); await page.fill('input[placeholder="e.g. 1"]', '1'); await page.fill('input[placeholder="e.g. Town core coverage area"]', 'isolated core'); await page.fill('textarea[placeholder^="Paste GeoJSON"]', boxPolygon(78.482, 17.38)); // Bound 2. await page.click('button:has-text("Add Bound")'); const names = await page.$$('input[placeholder="e.g. Mbnr-1"]'); const pris = await page.$$('input[placeholder="e.g. 1"]'); const descs = await page.$$('input[placeholder="e.g. Town core coverage area"]'); const geos = await page.$$('textarea[placeholder^="Paste GeoJSON"]'); expect(names).toHaveLength(2); await names[1].fill('PW-Overlap'); await pris[1].fill('2'); await descs[1].fill('overlap probe'); await geos[1].fill(boxPolygon(78.055, 16.748)); // Telegram cred (at least one required). await page.fill('input[placeholder^="e.g. 123456"]', botToken()); await page.fill('input[placeholder^="e.g. 5147760058"]', chatId()); await page.click('button:has-text("Create Region")'); await page.waitForURL('**/regions', { timeout: 20_000 }); await expect(page.getByText(name)).toBeVisible({ timeout: 20_000 }); });