test: read folder counts in one snapshot so a draining badge cannot hang the poll #1194

This commit is contained in:
Linus Rath
2026-10-11 18:52:23 +02:00
parent 7401ea6658
commit a385c6e410
+11 -5
View File
@@ -279,11 +279,17 @@ export interface FolderCounts {
*/
export async function folderCounts(page: Page, sel: FolderSelector): Promise<FolderCounts> {
const row = folderRow(page, sel).first();
const counts = row.locator('[data-testid="folder-counts"]');
if ((await counts.count()) === 0) return { unread: 0, total: 0 };
const unread = await counts.getAttribute('data-unread');
const total = await counts.getAttribute('data-total');
return { unread: Number(unread ?? 0), total: Number(total ?? 0) };
// Read both attributes in one snapshot. The badge unmounts when a folder
// drains to zero, and a separate count() + getAttribute() can straddle that:
// getAttribute then waits for an element that never comes back and hangs the
// poll until its timeout (#1194). evaluateAll does not wait.
return row.locator('[data-testid="folder-counts"]').evaluateAll((els) => {
const el = els[0];
return {
unread: Number(el?.getAttribute('data-unread') ?? 0),
total: Number(el?.getAttribute('data-total') ?? 0),
};
});
}
/** Poll until a folder's unread count reaches `expected`. */