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

test('rendered', async ({ page }) => {
  await page.goto('/starter-partytown-test/');
  page.on('pageerror', (err) => expect(err).toEqual(undefined));
  page.on('console', (msg) => {
    if (msg.type() === 'error') {
      expect(msg.text()).toEqual(undefined);
    }
  });

  const state = page.locator('#state');

  // Partytown spins up a web worker to run the simulated async work; under parallel
  // test load the worker init can take well over the default 3s expect timeout.
  await expect(state).toHaveText('finished', { timeout: 15000 });
});

test('update text', async ({ page }) => {
  await page.goto('/starter-partytown-test/');
  page.on('pageerror', (err) => expect(err).toEqual(undefined));
  page.on('console', (msg) => {
    if (msg.type() === 'error') {
      expect(msg.text()).toEqual(undefined);
    }
  });

  await page.fill('input', 'QWIK');
  await page.dispatchEvent('input', 'keyup');
  await expect(page.locator('ol')).toContainText('Hello QWIK!');
});
