super-productivity/e2e/utils/time-input-helper.ts
Johannes Millan 11d85208e5 refactor(e2e): replace waitForTimeout with condition-based waits
- Replace ~100 waitForTimeout calls with proper condition-based waits
- Extract shared utilities for time input and task scheduling
- Add timeout constants for consistent wait times
- Add new selectors for reminder dialogs and detail panels

Files refactored across 25+ test files including:
- Plugin tests (lifecycle, upload, loading, enable, structure)
- Reminder tests (view-task, schedule-page, default-options)
- Work view, planner, focus mode, and app feature tests
- Task dragdrop, autocomplete, and daily summary tests

New utilities created:
- e2e/utils/time-input-helper.ts - Robust time input filling
- e2e/utils/schedule-task-helper.ts - Task scheduling helpers
- e2e/constants/timeouts.ts - Standardized timeout values
2026-01-03 15:29:38 +01:00

59 lines
1.9 KiB
TypeScript

import { type Page, expect } from '@playwright/test';
/**
* Fills a time input field with the specified time.
* Handles both mat-form-field wrapped inputs and plain time inputs.
* Uses retry logic to ensure the value is properly set.
*
* @param page - Playwright page object
* @param scheduleTime - Date object or timestamp for the desired time
*/
export const fillTimeInput = async (
page: Page,
scheduleTime: Date | number,
): Promise<void> => {
const d = new Date(scheduleTime);
const timeValue = `${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}`;
// Try multiple selectors for the time input
const timeInput = page
.locator('mat-dialog-container input[type="time"]')
.or(page.locator('mat-form-field input[type="time"]'))
.or(page.locator('input[type="time"]'))
.first();
await timeInput.waitFor({ state: 'visible', timeout: 10000 });
// Click and focus the input
await timeInput.click();
// Clear and fill with small delays for stability
await timeInput.clear();
await timeInput.fill(timeValue);
// Verify with retry - if fill() didn't work, use evaluate fallback
const inputValue = await timeInput.inputValue();
if (inputValue !== timeValue) {
await page.evaluate(
({ value }: { value: string }) => {
const timeInputEl = document.querySelector(
'mat-form-field input[type="time"]',
) as HTMLInputElement;
if (timeInputEl) {
timeInputEl.value = value;
timeInputEl.dispatchEvent(new Event('input', { bubbles: true }));
timeInputEl.dispatchEvent(new Event('change', { bubbles: true }));
}
},
{ value: timeValue },
);
}
// Verify the value was set
await expect(async () => {
const value = await timeInput.inputValue();
expect(value).toBe(timeValue);
}).toPass({ timeout: 5000 });
// Tab out to commit the value
await page.keyboard.press('Tab');
};