Merge pull request #21104 from calixteman/fix_focus

Fix integration tests failing because the focus isn't on the right element
This commit is contained in:
Tim van der Meij 2026-04-16 20:02:50 +02:00 committed by GitHub
commit 5ec6ab1ab8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 45 additions and 48 deletions

View File

@ -869,12 +869,37 @@ async function kbDeleteLastWord(page) {
} }
} }
async function kbFocusNext(page) { async function kbFocusNext(page, selector = null) {
const handle = await createPromise(page, resolve => { if (selector) {
window.addEventListener("focusin", resolve, { once: true }); await page.waitForSelector(selector, { visible: true });
}); }
await page.keyboard.press("Tab"); while (true) {
await awaitPromise(handle); const handle = await page.evaluateHandle(
sel => [
new Promise(resolve => {
const cb = e => {
if (!sel || document.querySelector(sel)?.contains(e.target)) {
window.removeEventListener("focusin", cb);
resolve(true);
} else {
resolve(false);
}
};
window.addEventListener("focusin", cb);
}),
],
selector
);
await page.keyboard.press("Tab");
const result = await awaitPromise(handle);
if (result) {
break;
}
}
if (selector) {
await page.waitForSelector(`${selector}:focus`, { visible: true });
}
} }
async function kbFocusPrevious(page) { async function kbFocusPrevious(page) {

View File

@ -167,21 +167,9 @@ describe("PDF Thumbnail View", () => {
await waitForThumbnailVisible(page, 2); await waitForThumbnailVisible(page, 2);
await waitForThumbnailVisible(page, 3); await waitForThumbnailVisible(page, 3);
await kbFocusNext(page); await kbFocusNext(page, "#viewsManagerSelectorButton");
await page.waitForSelector("#viewsManagerSelectorButton:focus", { await kbFocusNext(page, "#viewsManagerStatusActionButton");
visible: true, await kbFocusNext(page, `#thumbnailsView ${getThumbnailSelector(1)}`);
});
await kbFocusNext(page);
await page.waitForSelector("#viewsManagerStatusActionButton:focus", {
visible: true,
});
await kbFocusNext(page);
await page.waitForSelector(
`#thumbnailsView ${getThumbnailSelector(1)}:focus`,
{ visible: true }
);
await page.keyboard.press("ArrowDown"); await page.keyboard.press("ArrowDown");
await page.waitForSelector( await page.waitForSelector(
@ -260,11 +248,7 @@ describe("PDF Thumbnail View", () => {
await enableMenuItems(page); await enableMenuItems(page);
// Focus the manage button // Focus the manage button
await kbFocusNext(page); await kbFocusNext(page, "#viewsManagerStatusActionButton");
await kbFocusNext(page);
await page.waitForSelector("#viewsManagerStatusActionButton:focus", {
visible: true,
});
// Press Enter to open the menu // Press Enter to open the menu
await page.keyboard.press("Enter"); await page.keyboard.press("Enter");
@ -292,11 +276,7 @@ describe("PDF Thumbnail View", () => {
await enableMenuItems(page); await enableMenuItems(page);
// Focus the manage button // Focus the manage button
await kbFocusNext(page); await kbFocusNext(page, "#viewsManagerStatusActionButton");
await kbFocusNext(page);
await page.waitForSelector("#viewsManagerStatusActionButton:focus", {
visible: true,
});
// Press Space to open the menu // Press Space to open the menu
await page.keyboard.press(" "); await page.keyboard.press(" ");
@ -409,16 +389,11 @@ describe("PDF Thumbnail View", () => {
}); });
// Press Tab to move to the manage button (should close views menu) // Press Tab to move to the manage button (should close views menu)
await page.keyboard.press("Tab"); await kbFocusNext(page, "#viewsManagerStatusActionButton");
// Wait for views manager menu to be collapsed // Wait for views manager menu to be collapsed
await waitForMenu(page, "#viewsManagerSelectorButton", false); await waitForMenu(page, "#viewsManagerSelectorButton", false);
// Focus should be on manage button
await page.waitForSelector("#viewsManagerStatusActionButton:focus", {
visible: true,
});
// Open manage menu with Space key // Open manage menu with Space key
await page.keyboard.press(" "); await page.keyboard.press(" ");
@ -493,9 +468,7 @@ describe("PDF Thumbnail View", () => {
await waitForThumbnailVisible(page, 1); await waitForThumbnailVisible(page, 1);
// Focus the first thumbnail button // Focus the first thumbnail button
await kbFocusNext(page); await kbFocusNext(page, getThumbnailSelector(1));
await kbFocusNext(page);
await kbFocusNext(page);
// Verify we're on the first thumbnail // Verify we're on the first thumbnail
await page.waitForSelector(`${getThumbnailSelector(1)}:focus`, { await page.waitForSelector(`${getThumbnailSelector(1)}:focus`, {
@ -503,10 +476,9 @@ describe("PDF Thumbnail View", () => {
}); });
// Tab to checkbox // Tab to checkbox
await kbFocusNext(page); await kbFocusNext(
await page.waitForSelector( page,
`.thumbnail[page-number="1"] input[type="checkbox"]:focus`, `.thumbnail[page-number="1"] input[type="checkbox"]`
{ visible: true }
); );
}) })
); );
@ -520,10 +492,10 @@ describe("PDF Thumbnail View", () => {
await waitForThumbnailVisible(page, 2); await waitForThumbnailVisible(page, 2);
// Navigate to first checkbox // Navigate to first checkbox
await kbFocusNext(page); await kbFocusNext(
await kbFocusNext(page); page,
await kbFocusNext(page); `.thumbnail[page-number="1"] input[type="checkbox"]`
await kbFocusNext(page); );
// Verify first checkbox is focused // Verify first checkbox is focused
await page.waitForSelector( await page.waitForSelector(