import base64 import io import json import os import runpy import zipfile from pathlib import Path from fastapi.testclient import TestClient import docslib from docslib import HeaderButton, __version__, build from docslib.components import H1, Image, P from docslib.hooks import Page from docslib.server import create_app def test_loader_renders_indexeddb_before_background_sync(): templates = Path(docslib.__file__).with_name("templates") loader = (templates / "loader.js").read_text(encoding="utf-8") client = (templates / "client.js").read_text(encoding="utf-8") assert "const cached = await cacheGet();" in loader assert "return cached;" in loader assert "await cachePut(embedded);" in loader assert "fetch(" not in loader assert "renderAll();\n announceRendered();\n syncManifest();" in client assert "manifest = remote" not in client def test_accessibility_ui_is_generated_by_runtime_for_existing_html(): templates = Path(docslib.__file__).with_name("templates") index = (templates / "index.html").read_text(encoding="utf-8") client = (templates / "client.js").read_text(encoding="utf-8") css = (templates / "client.css").read_text(encoding="utf-8") assert 'id="accessibility-button"' not in index assert 'id="mobile-accessibility-button"' not in index assert 'id="accessibility-view"' not in index assert "function ensureAccessibilityUi()" in client assert 'createAccessibilityButton("accessibility-button"' in client assert 'createAccessibilityButton("mobile-accessibility-button"' in client assert 'viewBox="0 -960 960 960" fill="currentColor"' in client assert "M423.5-743.5Q400-767" in client assert 'Knowledge base<" not in html assert ">Search<" not in html assert ">Ctrl K<" not in html assert ">Up to date<" not in html assert "manifestIdentity" in html assert "100dvh" in html assert "100vh" not in html assert "html, body { width: 100%; height: 100dvh" in html assert "min-height: calc(100dvh - 240px)" not in html assert "overflow-y: auto" in html assert "flex: 1 1 auto; flex-direction: column" in html assert "padding: 0 18px; background: var(--shell)" in html assert "--desktop-sidebar-width: clamp(270px, 25vw, 400px)" in html assert "--selection-bg: #111111" in html assert "--selection-bg: #f0f0f0" in html assert ".mobile-menu-view .tree-link.active { color: var(--selection-text); background: var(--selection-bg); }" in html assert "--elevated: #d4d4d4" in html assert "--shadow: 0 24px 70px rgba(0, 0, 0, .4)" in html assert "elements.pageSurface.scrollTo" in html assert "font-family: var(--accessibility-font-family); font-size: 16px" in html assert ".glyph-button, .refresh-glyph { font-family: Arial" in html assert ".nav-arrow { display: block; width: 10px; height: 10px; flex: 0 0 10px; border: 0 solid currentColor; transform: rotate(45deg); }" in html assert ".nav-arrow-previous { border-bottom-width: 2px; border-left-width: 2px; }" in html assert ".nav-arrow-next { border-top-width: 2px; border-right-width: 2px; }" in html assert 'arrow.textContent = direction' not in html assert "globalThis.PrintFullDocumentation = PrintFullDocumentation" in system_js assert 'printable.id = "docslib-full-print"' in system_js assert "manifest.pages.forEach((page) =>" in system_js assert 'window.addEventListener("afterprint", removeFullPrintDocument)' in system_js assert "async function PrintFullDocumentation()" in system_js assert "await waitForPrintAssets(printable)" in system_js assert 'if (eager) element.loading = "eager"' in system_js assert "hydrateAssets(article, { eager: true })" in system_js assert 'image.addEventListener("load", resolve, { once: true })' in system_js assert 'await image.decode().catch(() => {})' in system_js assert "await document.fonts.ready" in system_js system_css = manifest["client"]["css"]["system"] assert 'body.docslib-print-all > .full-print-document { display: block; }' in system_css assert 'color: #000 !important; background: #fff !important;' in system_css assert ".print-page { break-after: page; page-break-after: always; }" in system_css assert ".print-loading-overlay { position: fixed; inset: 0; z-index: 2147483647; display: grid; width: 100vw; height: 100dvh" in system_css assert ".print-page-heading h1 { margin: 0; color: #000 !important; font-size: 1.35rem !important" in system_css assert ".print-page-content h1 { font-size: 1.8rem !important" in system_css assert "--shell: #000000" in html assert 'id="desktop-search-input"' in html assert '
' in html assert 'id="page-transition" class="page-transition"' in html assert 'id="desktop-sidebar-toggle"' in html assert 'aria-label="☰" aria-expanded="true">☰' in html assert '