import { expect, test } from '@playwright/test';

test('viewer2d resolves DWG WASM, font, and sample under a production subpath', async ({
  page,
}) => {
  const failedRequests: string[] = [];
  const responseUrls: string[] = [];
  page.on('requestfailed', (request) => failedRequests.push(request.url()));
  page.on('response', (response) => responseUrls.push(response.url()));

  await page.goto(
    'http://127.0.0.1:45173/viewer-2d/?model=/viewer-2d/samples/BasicSample.dwg',
  );
  await expect(page.locator('#status')).toContainText('7309 entities', { timeout: 20_000 });
  await expect.poll(
    () =>
      ({
        font: responseUrls.some((url) =>
          url.endsWith('/viewer-2d/fonts/NanumGothic-Regular.ttf'),
        ),
        sample: responseUrls.some((url) =>
          url.endsWith('/viewer-2d/samples/BasicSample.dwg'),
        ),
        wasm: responseUrls.some(
          (url) => url.includes('/viewer-2d/assets/') && url.endsWith('.wasm'),
        ),
      }),
    { timeout: 20_000 },
  ).toEqual({ font: true, sample: true, wasm: true });
  expect(failedRequests).toEqual([]);
});
