42 lines
1.9 KiB
JavaScript
42 lines
1.9 KiB
JavaScript
const { test, expect } = require('@playwright/test');
|
|
const { login } = require('./helpers');
|
|
|
|
test('delayed new-upstream autofocus must not steal focus from the URL field', async ({ page }) => {
|
|
await login(page);
|
|
await page.goto('/wizard/');
|
|
await page.waitForFunction(() => window.CrankWizardReady === true);
|
|
|
|
await page.locator('[data-testid="wizard-protocol-rest"]').click();
|
|
await page.locator('#btn-continue').click();
|
|
await expect(page.locator('#upstream-new-trigger')).toBeVisible();
|
|
|
|
// Take manual control of page time before the new-upstream form is opened so
|
|
// the deferred autofocus timer scheduled by startNewUpstream cannot fire on
|
|
// its own while Playwright fills the two fields.
|
|
const installTime = new Date('2026-05-01T12:00:00.000Z');
|
|
await page.clock.install({ time: installTime });
|
|
await page.clock.pauseAt(new Date(installTime.getTime() + 1000));
|
|
|
|
await page.locator('#upstream-new-trigger').click();
|
|
|
|
await page.locator('#new-upstream-name').fill('focus-red-upstream');
|
|
await page.locator('#new-upstream-url').fill('http://127.0.0.1:3310');
|
|
|
|
// Both values landed exactly and focus is explicitly on the URL field before
|
|
// the deferred autofocus runs.
|
|
await expect(page.locator('#new-upstream-name')).toHaveValue('focus-red-upstream');
|
|
await expect(page.locator('#new-upstream-url')).toHaveValue('http://127.0.0.1:3310');
|
|
await expect(page.locator('#new-upstream-url')).toBeFocused();
|
|
|
|
// Explicitly execute the old 50ms autofocus timer.
|
|
await page.clock.runFor(100);
|
|
|
|
// The delayed autofocus must not move focus back to the name field.
|
|
await expect(page.locator('#new-upstream-url')).toBeFocused();
|
|
|
|
// Correct field still receives text after the timer ran; no network mutation.
|
|
await page.keyboard.insertText('-probe');
|
|
await expect(page.locator('#new-upstream-url')).toHaveValue('http://127.0.0.1:3310-probe');
|
|
await expect(page.locator('#new-upstream-name')).toHaveValue('focus-red-upstream');
|
|
});
|