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

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

async function loadCube(page: import('@playwright/test').Page) {
  await page.locator('#file-input').setInputFiles(resolve(__dirname, '../fixtures/cube.obj'));
  await page.waitForTimeout(3000);
}

test.describe('Colorize via Menu', () => {
  test('Color filters accessible from Filters menu', async ({ page }) => {
    await page.goto('/');
    await page.locator('canvas').first().waitFor({ state: 'visible', timeout: 10000 });
    await page.click('[data-testid="menu-Filters"]');
    await expect(page.locator('[data-testid="menu-bar"]').locator('text=Color Creation').first()).toBeVisible();
  });

  test('Gaussian curvature filter via menu', async ({ page }) => {
    await page.goto('/');
    await page.locator('canvas').first().waitFor({ state: 'visible', timeout: 10000 });
    await loadCube(page);
    await page.click('[data-testid="menu-Filters"]');
    await page.locator('[data-testid="menu-bar"]').locator('text=Color Creation').click();
    await page.click('text=Colorize by Gaussian Curvature');
    await expect(page.locator('[data-testid="filter-dialog"]')).toBeVisible();
    await page.click('[data-testid="filter-apply"]');
    await page.waitForTimeout(1500);
    await page.click('[data-testid="filter-close"]');
    await expect(page.locator('[data-testid="status-message"]')).toContainText('colorize_gaussian_curvature');
  });
});
