Skip to content

Commit f1e95c8

Browse files
Hongzhi Wenclaude
andcommitted
test: scope autostart retention style contract assertions
之前断言 4 个 CSS 属性是对全文件子串匹配,而这些属性实际归属 .modal-header / .modal-footer / .modal-btn:not(.modal-btn-link):hover, 没一个在 .modal-btn-link 块里,测试名 _is_scoped 名不副实。 改成按选择器提取规则 body,在各自块里断言对应属性;同时给 .modal-btn-link 块补上它自己的契约 (position: absolute; right: 0; bottom: 0),即「不再提示」绝对定位到右下角的真实交付。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 56c5a38 commit f1e95c8

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

tests/unit/test_common_dialogs.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,12 +677,40 @@ def test_autostart_retention_prompt_supports_link_button_variant():
677677
}
678678

679679

680+
def _rule_bodies(source: str, selector: str) -> list[str]:
681+
pattern = re.compile(re.escape(selector) + r"[^{]*\{(?P<body>[^}]*)\}", re.S)
682+
bodies = [m.group("body") for m in pattern.finditer(source)]
683+
assert bodies, f"selector not found in common_dialogs.js: {selector}"
684+
return bodies
685+
686+
687+
def _assert_in_any(bodies: list[str], prop: str, selector: str) -> None:
688+
assert any(prop in b for b in bodies), (
689+
f"property `{prop}` not declared under `{selector}`"
690+
)
691+
692+
680693
@pytest.mark.unit
681694
def test_autostart_retention_button_style_contract_is_scoped():
682695
source = COMMON_DIALOGS_PATH.read_text(encoding="utf-8")
683696

684-
assert ".modal-dialog-autostart-retention .modal-btn-link" in source
685-
assert "flex-wrap: wrap;" in source
686-
assert "padding: 22px 0 0;" in source
687-
assert "padding: 38px 0 34px;" in source
688-
assert "translateY(-2px)" in source
697+
header_sel = ".modal-dialog-autostart-retention .modal-header"
698+
header = _rule_bodies(source, header_sel)
699+
_assert_in_any(header, "padding: 22px 0 0;", header_sel)
700+
701+
footer_sel = ".modal-dialog-autostart-retention .modal-footer"
702+
footer = _rule_bodies(source, footer_sel)
703+
_assert_in_any(footer, "flex-wrap: wrap;", footer_sel)
704+
_assert_in_any(footer, "padding: 38px 0 34px;", footer_sel)
705+
706+
link_sel = ".modal-dialog-autostart-retention .modal-btn-link"
707+
link = _rule_bodies(source, link_sel)
708+
_assert_in_any(link, "position: absolute;", link_sel)
709+
_assert_in_any(link, "right: 0;", link_sel)
710+
_assert_in_any(link, "bottom: 0;", link_sel)
711+
712+
hover_sel = (
713+
".modal-dialog-autostart-retention .modal-btn:not(.modal-btn-link):hover"
714+
)
715+
hover = _rule_bodies(source, hover_sel)
716+
_assert_in_any(hover, "translateY(-2px)", hover_sel)

0 commit comments

Comments
 (0)