import { expect } from "@playwright/test";
const DEFAULT_UI_TIMEOUT_MS = 1e4;
async function fillControlledInput(input, value, timeoutMs = DEFAULT_UI_TIMEOUT_MS) {
  const deadline = Date.now() + timeoutMs;
  let lastError = null;
  while (Date.now() < deadline) {
    try {
      await input.scrollIntoViewIfNeeded().catch(() => {
      });
      await input.click({ timeout: 2e3 });
      await input.fill(value);
      await expect(input).toHaveValue(value, { timeout: 1500 });
      return;
    } catch (error) {
      lastError = error;
      await input.page().waitForTimeout(150);
    }
  }
  if (lastError instanceof Error) {
    throw lastError;
  }
  throw new Error(`Unable to fill controlled input with value "${value}"`);
}
async function waitForApiMutation(page, pathFragment, action, method = "POST", timeoutMs = DEFAULT_UI_TIMEOUT_MS) {
  const responsePromise = page.waitForResponse(
    (response) => response.request().method() === method && response.url().includes(pathFragment),
    { timeout: timeoutMs }
  );
  await action();
  return responsePromise;
}
export {
  fillControlledInput,
  waitForApiMutation
};
//# sourceMappingURL=ui.js.map
