import { test, expect } from '@playwright/test';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));

test.describe('USDA Format', () => {
  test('loads USDA file and shows vertex count', async ({ page }) => {
    await page.goto('/');
    await page.locator('canvas').first().waitFor({ state: 'visible', timeout: 10000 });

    await page.locator('#file-input').setInputFiles(resolve(__dirname, '../fixtures/cube.usda'));
    await page.waitForTimeout(3000);

    await expect(page.locator('[data-testid="vertex-count"]')).toContainText('8');
  });
});

test.describe('USD Export Menu', () => {
  test('File menu has USDA export option', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-File"]');
    await page.click('text=Export Mesh As...');
    await expect(page.locator('text=USDA (.usda)').first()).toBeVisible();
  });

  test('File menu has USDZ export option', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-File"]');
    await page.click('text=Export Mesh As...');
    await expect(page.locator('text=USDZ (.usdz)').first()).toBeVisible();
  });
});

test.describe('Format Count', () => {
  test('About dialog shows 20 Formats', async ({ page }) => {
    await page.goto('/');
    await page.click('[data-testid="menu-Help"]');
    await page.click('text=About MeshLab Web');
    await expect(page.locator('[data-testid="about-dialog"]')).toContainText('20 Formats');
  });
});
