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

import { WithLoader } from '@digigov/ui/content/Table/__stories__/WithLoader';
import { WithSortFilters } from '@digigov/ui/content/Table/__stories__/WithSortFilters';
const SCREENSHOT_DELAY = 2_000;
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

test('renders the WithLoader Toggle Loading', async ({ mount, page }) => {
  await mount(<WithLoader />);
  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 delay(SCREENSHOT_DELAY);
  await page.locator('#root>button').click();
  const screenshot = await page.screenshot({
    fullPage: true,
    animations: 'disabled',
  });
  expect(screenshot).toMatchSnapshot();
});

test('renders the WithSortFilters Click on header cell', async ({
  mount,
  page,
}) => {
  await mount(<WithSortFilters />);
  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 delay(SCREENSHOT_DELAY);
  await page
    .locator('#root>div>table>thead>tr>th:nth-child(1)>details>summary')
    .click();
  const screenshot = await page.screenshot({
    fullPage: true,
    animations: 'disabled',
  });
  expect(screenshot).toMatchSnapshot();
});
