diff --git a/packages/gitbook/e2e/util.ts b/packages/gitbook/e2e/util.ts index 15d8bb99a..6a16a975b 100644 --- a/packages/gitbook/e2e/util.ts +++ b/packages/gitbook/e2e/util.ts @@ -146,6 +146,11 @@ export const headerLinks: CustomizationHeaderItem[] = [ }, ]; +type IconURLState = { state: 'pending'; uri: null } | { state: 'loaded'; uri: string }; +type IconStateWindow = Window & { + __ICONS_STATES__?: Record; +}; + export async function waitForCookiesDialog(page: Page) { const dialog = page.getByTestId('cookies-dialog'); await expect(dialog).toBeVisible({ @@ -396,11 +401,9 @@ export function getCustomizationURL(partial: DeepPartial { - const urlStates: Record< - string, - { state: 'pending'; uri: null } | { state: 'loaded'; uri: string } - > = (window as any).__ICONS_STATES__ || {}; - (window as any).__ICONS_STATES__ = urlStates; + const iconWindow = window as IconStateWindow; + const urlStates: Record = iconWindow.__ICONS_STATES__ || {}; + iconWindow.__ICONS_STATES__ = urlStates; const fetchSvgAsDataUri = async (url: string): Promise => { const response = await fetch(url); @@ -435,7 +438,16 @@ export async function waitForIcons(page: Page) { const svgSymbol = icon.querySelector('[data-testid="symbol-use"]'); if (svgSymbol) { - return icon.dataset.gbIIconSymbolState === 'loaded'; + if (icon.dataset.gbIconSymbolState === 'loaded') { + return true; + } + + const href = svgSymbol.getAttribute('href') ?? svgSymbol.getAttribute('xlink:href'); + if (!href?.startsWith('#')) { + return false; + } + + return document.getElementById(href.slice(1)) instanceof SVGElement; } const state = icon.getAttribute('data-argos-state');