import React from 'react';
import { test, expect } from '@playwright/experimental-ct-react';

import { Default } from '@digigov/ui/form/TextInput/__stories__/Default';
import { WithErrorMessage } from '@digigov/ui/form/TextInput/__stories__/WithErrorMessage';

test('renders the Default Click and write', async ({ mount, page }) => {
  await mount(<Default />);
  await page.evaluate(() => document.fonts.ready);

  // Move the mouse to the top-left corner to avoid random hover issues
  await page.mouse.move(0, 0);

  await page.locator('#root>div>label>input').click();
  await page.keyboard.insertText('όνομα');

  const screenshot = await page.screenshot({
    fullPage: true,
    animations: 'disabled',
  });
  expect(screenshot).toMatchSnapshot();
});

test('renders the WithErrorMessage Keyboard navigation', async ({
  mount,
  page,
}) => {
  await mount(<WithErrorMessage />);
  await page.evaluate(() => document.fonts.ready);

  // Move the mouse to the top-left corner to avoid random hover issues
  await page.mouse.move(0, 0);

  await page.keyboard.press('Tab');
  const screenshot = await page.screenshot({
    fullPage: true,
    animations: 'disabled',
  });
  expect(screenshot).toMatchSnapshot();
});
