redoc/playwright/page-objects/click-through-menu.ts
Alex Varchuk 10400113fb
feat: initialize release candidate for v3.0.0
Co-authored-by: Roman Hotsiy <gotsijroman@gmail.com>
Co-authored-by: Alex Varchuk <olexandr.varchuk@gmail.com>
Co-authored-by: Oprysk Vyacheslav <vyacheslav@redocly.com>
Co-authored-by: Ivan Kropyvnytskyi <130547411+ivankropyvnytskyi@users.noreply.github.com>
Co-authored-by: Yevhen Pylyp <yevhen.pylyp@redocly.com>
Co-authored-by: Vladyslav Makarenko <vladyslav.makarenko@redocly.com>
Co-authored-by: Yevhenii Medviediev <yevhenii.medviediev@redocly.com>
Co-authored-by: Oleksii Horbachevskyi <oleksii.horbachevskyi@redocly.com>
Co-authored-by: volodymyr-rutskyi <rutskyi.v@gmail.com>
Co-authored-by: Adam Altman <adam@redoc.ly>
Co-authored-by: Andrew Tatomyr <andrew.tatomyr@redocly.com>
Co-authored-by: Anastasiia Derymarko <anastasiia@redocly.com>
Co-authored-by: Roman Marshevskyy <roman.marshevskyy@redoc.ly>
Co-authored-by: Lorna Mitchell <lorna.mitchell@redocly.com>
Co-authored-by: Taylor Krusen <taylor.krusen@redocly.com>
2025-10-24 17:55:59 +02:00

37 lines
1.3 KiB
TypeScript

import type { Page } from '@playwright/test';
export async function clickThroughMenu(page: Page, ...paths: string[]) {
for (const path of paths) {
const selector = `[data-component-name="Menu/MenuItem"] [data-testid="menu-item-label"] :text-is("${path}")`;
const element = page.locator(selector).first();
await element.waitFor({ state: 'visible' });
const elementHandle = await element.elementHandle();
const isClosedGroup =
(await elementHandle?.evaluate((el: HTMLElement) => {
const menuItem = el.closest('[data-component-name="Menu/MenuItem"]');
const chevronRight = menuItem?.querySelector(
'[data-component-name="icons/ChevronRightIcon/ChevronRightIcon"]',
);
return Boolean(chevronRight);
})) ?? false;
if (isClosedGroup) {
const waitForExpand = page.evaluate(() => {
return new Promise<void>((resolve) => {
const expandListener = () => {
document.body.removeEventListener('menu:expand-end', expandListener);
resolve();
};
document.body.addEventListener('menu:expand-end', expandListener);
});
});
await element.click();
await waitForExpand;
} else {
await element.click();
}
}
}