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

43 lines
1.5 KiB
TypeScript

import { test, expect } from '@playwright/test';
import { trpcCall } from '../lib/trpc';
// Read-only resolution matrix (docs/region-test-cases.txt §2). Coordinates
// target the Mahabubnagar seed polygons (Mbnr-1 priority 1, Mbnr-2 priority 2).
async function resolve(lat: number, lng: number) {
const r = await trpcCall(null, 'common.resolveRegionForLocation', { lat, lng });
if (r.error) throw new Error(`resolve failed: ${r.error.message}`);
return r.result.data;
}
test('2.1 point inside Mbnr-1', async () => {
const d = await resolve(16.745, 78.01);
expect(d.regionId).toBe(1);
expect(d.boundName).toBe('Mbnr-1');
});
test('2.3 point outside every polygon', async () => {
const d = await resolve(17.4, 78.48);
expect(d.regionId).toBeNull();
expect(d.boundId).toBeNull();
});
test('2.4 polygon vertex is inside (boundary inclusive)', async () => {
const d = await resolve(16.7224827, 77.9802307);
expect(d.regionId).toBe(1);
});
test('2.5 overlapping Mbnr-1/Mbnr-2: priority 1 wins', async () => {
const d = await resolve(16.718, 78.014);
expect(d.regionId).toBe(1);
expect(d.boundName).toBe('Mbnr-1');
});
test('2.11 swapped lat/lng does not false-match', async () => {
const d = await resolve(78.01, 16.745);
expect(d.regionId).toBeNull();
});
test('2.12 procedure returns region+bound or nulls', async () => {
const d = await resolve(16.745, 78.01);
expect(d).toEqual(expect.objectContaining({ regionId: 1, regionName: 'Mahabubnagar', boundId: 1, boundName: 'Mbnr-1' }));
});