diff --git a/src/nvdaTest.ts b/src/nvdaTest.ts index 1a4a8e0..74b82da 100644 --- a/src/nvdaTest.ts +++ b/src/nvdaTest.ts @@ -62,14 +62,27 @@ type FocusBrowserParams = { pageTitle: string; }; +const cleanString = (str: string): string => + str + .toLowerCase() + // REF: https://github.com/nvaccess/nvda/blob/master/source/locale/en/symbols.dic + .replace(/[|¦:;'"`\-‐–—·_()[\]{}\\^~]/g, " ") + .replace(/\s+/g, " ") + .trim(); + const hasFocus = ({ applicationName, pageTitle, windowTitle, }: FocusBrowserParams & { windowTitle: string }) => { + const cleanedApplicationName = cleanString(applicationName); + const cleanedPageTitle = cleanString(pageTitle); + const cleanedWindowTitle = cleanString(windowTitle); + return ( - (pageTitle.length && windowTitle.startsWith(pageTitle)) || - windowTitle.includes(applicationName) + (cleanedPageTitle.length && + cleanedWindowTitle.startsWith(cleanedPageTitle)) || + cleanedWindowTitle.includes(cleanedApplicationName) ); }; @@ -161,7 +174,10 @@ export const nvdaTest = test.extend<{ const pageTitle = await page.title(); // Ensure application is brought to front and focused. - await focusBrowser({ applicationName, pageTitle }); + await focusBrowser({ + applicationName, + pageTitle, + }); // Ensure the document is ready and focused. await page.bringToFront();