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

test('viewer3d resolves Draco and IFC decoders 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()));

  for (const fixture of ['Duck.optimized.glb', 'Cube.ifc']) {
    await page.goto(
      `http://127.0.0.1:43174/viewer-3d/?model=/viewer-3d/samples/${fixture}`,
    );
    await page.waitForFunction(
      () =>
        Boolean(
          (
            window as Window & {
              __viewer?: { current?: object };
            }
          ).__viewer?.current,
        ),
      undefined,
      { timeout: 20_000 },
    );
  }

  expect(responseUrls.some((url) => url.includes('/viewer-3d/draco/'))).toBe(true);
  expect(responseUrls.some((url) => url.endsWith('/viewer-3d/web-ifc/web-ifc.wasm'))).toBe(true);
  expect(failedRequests).toEqual([]);
});
