"""Render actual update-completion handlers in an isolated browser.""" from pathlib import Path import pytest from js_lift import JsSource from test_grid_highlight_escaping import browser # noqa: F401 -- fixture JS = JsSource(Path(__file__).resolve().parent.parent / "js") @pytest.mark.parametrize("status", ["success", "failed"]) def test_update_results_preserve_links_titles_and_missing_url_labels(status): playwright = pytest.importorskip("playwright.sync_api") helpers = JS.lift_declaration("common.js", "export function sanitizeHTML(") helpers += JS.lift_span( "common.js", "export const SAFE_URL_SCHEMES", "export const safeHref = (url) => sanitizeHTML(sanitizeUrl(url));", ).replace("export ", "") helpers += JS.lift_declaration("common.js", "export function show_message(") handler = JS.lift_declaration("comfyui-manager.js", "async function onQueueStatus(") url = "https://example.test/guide?q=O'Reilly&lang=en" title = "Guide & notes" fallback_id = "Pack " with playwright.sync_playwright() as driver: if not Path(driver.chromium.executable_path).exists(): pytest.skip("install Chromium with: playwright install chromium") browser = driver.chromium.launch() page = browser.new_page() page.route("**/*", lambda route: route.abort()) page.set_content('
') page.add_script_tag(content=""" let is_updating = true; const update_all_button = document.createElement('button'); function reset_action_buttons() {} function setNeedRestart() {} function infoToast() {} const app = {ui: {dialog: { element: document.getElementById('dialog'), show(message) { this.element.innerHTML = message; } }}}; """ + helpers + handler) page.evaluate("event => onQueueStatus(event)", {"detail": { "status": "done", "nodepack_result": { "comfyui": "skip", "pack-link": {"url": url, "title": title, "msg": status}, fallback_id: {"msg": status}, }, }}) items = page.locator("#dialog li") assert items.all_text_contents() == [title, fallback_id] assert items.nth(0).locator("a").get_attribute("href") == url assert set(items.nth(0).locator("a").evaluate("node => node.getAttributeNames()")) == { "href", "target", "rel", } assert items.nth(0).locator("a").get_attribute("rel") == "noopener noreferrer" assert items.nth(1).locator("a").count() == 0 assert page.locator("#dialog draft").count() == 0 browser.close() @pytest.mark.parametrize("status", ["in_progress", "done"]) def test_a_queue_report_before_the_manager_menu_exists_is_ignored(browser, status): # noqa: F811 handler = JS.lift_declaration("comfyui-manager.js", "async function set_inprogress_mode(") handler += JS.lift_declaration("comfyui-manager.js", "async function reset_action_buttons(") handler += JS.lift_declaration("comfyui-manager.js", "async function onQueueStatus(") page = browser.new_page() errors = [] page.on("pageerror", lambda error: errors.append(str(error))) page.add_script_tag(content=""" let is_updating = false; let update_all_button = null, update_comfyui_button = null, switch_comfyui_button = null; """ + handler) page.evaluate("event => onQueueStatus(event)", {"detail": { "status": status, "nodepack_result": {}, "done_count": 0, "total_count": 1, }}) page.wait_for_timeout(100) assert errors == [] page.close()