"""HEL-842 controls: actual UI state, keyboard access and real saved configuration.""" import json from playwright.sync_api import expect def verify_controls(page, data, out): base = "http://127.0.0.1:18740" folder = out / "controls" folder.mkdir(exist_ok=True) checks = [] def shot(name): page.screenshot(path=str(folder / f"{name}.png")) checks.append(name) page.goto(base + "/library") page.locator(".lt").first.wait_for() for fill in [False, True]: for dense in [False, True]: fit = page.get_by_role( "button", name="铺满" if fill else "完整", exact=True ) fit.focus() page.keyboard.press("Enter") expect(fit).to_have_attribute("aria-pressed", "true") density = page.get_by_role( "button", name="紧凑网格,仅缩略图" if dense else "标准网格", exact=True ) density.focus() page.keyboard.press("Space") expect(density).to_have_attribute("aria-pressed", "true") grid = page.locator(".lgrid").first assert ("fill" in (grid.get_attribute("class") or "").split()) == fill assert ("dense" in (grid.get_attribute("class") or "").split()) == dense assert page.locator(".mat img").first.evaluate( "(n)=>getComputedStyle(n).objectFit" ) == ("cover" if fill else "contain") shot(f"library-fit-{fill}-dense-{dense}") select = page.get_by_role("button", name="选择", exact=True) select.focus() page.keyboard.press("Enter") expect(select).to_have_attribute("aria-pressed", "true") expect(page.locator(".lib-main")).to_have_class("lib-main selecting") shot("library-selection-keyboard") page.get_by_role("button", name="图片", exact=False).first.click() expect(page.locator(".lt video")).to_have_count(0) page.get_by_role("combobox", name="排序").select_option("size") search = page.get_by_role("textbox", name="文件名查找") search.fill("样本素材-01") expect(page.locator(".lt")).to_have_count(1) shot("library-filter-sort-search") page.goto(base + "/connections?tab=llm") page.locator(".mrow").first.wait_for() original_name = page.request.get(base + "/api/settings").json()["llm_profiles"][0][ "name" ] expect(page.locator(".mrow").nth(1).locator(".use")).to_contain_text("智能体 ×2") edit = page.locator(".mrow").first.get_by_role("button", name="编辑", exact=True) edit.focus() page.keyboard.press("Enter") page.locator(".md-b input").first.fill("HEL-842 保存验证") page.get_by_role("button", name="保存", exact=True).click() expect(page.locator(".mrow").first).to_contain_text("HEL-842 保存验证") page.reload() expect(page.locator(".mrow").first).to_contain_text("HEL-842 保存验证") page.locator(".mrow").first.get_by_role("button", name="编辑", exact=True).click() shot("model-save-reload") (data / "control.json").write_text(json.dumps({"delay": 0.8})) page.get_by_role("button", name="测试连接", exact=True).click() expect(page.locator(".md-f .loading")).to_be_visible() shot("model-testing") expect(page.locator(".testbox.ok")).to_be_visible() shot("model-test-success") (data / "control.json").write_text(json.dumps({"status": 401})) page.get_by_role("button", name="测试连接", exact=True).click() expect(page.locator(".testbox.err")).to_be_visible() page.locator(".testbox.err summary").click() shot("model-test-failed-raw") (data / "control.json").write_text("{}") # Leave original fixture values for the shared ABA/undo/attach regression suite. page.locator(".md-b input").first.fill(original_name) page.get_by_role("button", name="保存", exact=True).click() expect(page.locator(".mrow").first).to_contain_text(original_name) (out / "controls.json").write_text(json.dumps(checks, ensure_ascii=False, indent=2))