fix: apply ruff formatting and add null guard for tab lookup in test

- Apply ruff auto-format to test_frontend_css.py, test_frontend_html.py,
  test_frontend_js.py (whitespace/line-length normalization)
- Add assert-not-None guard before tab.get() in settings tabs test,
  matching the pattern already used for display_tab (fixes pyright error)

Co-authored-by: Amplifier <amplifier@amplified.dev>
This commit is contained in:
Brian Krabach
2026-03-30 02:54:07 -07:00
parent bac23f26dc
commit 6f598524a9
3 changed files with 40 additions and 42 deletions
+30 -23
View File
@@ -1370,10 +1370,10 @@ def test_css_new_session_input_has_outline_none() -> None:
def test_css_new_session_input_placeholder_rule_exists() -> None:
""".new-session-input::placeholder CSS rule must exist."""
css = read_css()
assert ".new-session-input::placeholder" in css or \
".new-session-input::-webkit-input-placeholder" in css, (
".new-session-input::placeholder CSS rule must exist"
)
assert (
".new-session-input::placeholder" in css
or ".new-session-input::-webkit-input-placeholder" in css
), ".new-session-input::placeholder CSS rule must exist"
def test_css_new_session_input_placeholder_color() -> None:
@@ -1407,6 +1407,7 @@ def test_css_sidebar_footer_rule_exists() -> None:
def test_css_sidebar_footer_padding() -> None:
""".sidebar-footer must have padding: 8px."""
import re
css = read_css()
match = re.search(
r"\.sidebar-footer\s*\{([^}]*)\}",
@@ -1422,6 +1423,7 @@ def test_css_sidebar_footer_padding() -> None:
def test_css_sidebar_footer_border_top() -> None:
""".sidebar-footer must have border-top."""
import re
css = read_css()
match = re.search(
r"\.sidebar-footer\s*\{([^}]*)\}",
@@ -1436,6 +1438,7 @@ def test_css_sidebar_footer_border_top() -> None:
def test_css_sidebar_footer_flex_shrink_0() -> None:
""".sidebar-footer must have flex-shrink: 0."""
import re
css = read_css()
match = re.search(
r"\.sidebar-footer\s*\{([^}]*)\}",
@@ -1457,6 +1460,7 @@ def test_css_sidebar_new_btn_rule_exists() -> None:
def test_css_sidebar_new_btn_width_100() -> None:
""".sidebar-new-btn must have width: 100%."""
import re
css = read_css()
match = re.search(
r"\.sidebar-new-btn\s*\{([^}]*)\}",
@@ -1472,6 +1476,7 @@ def test_css_sidebar_new_btn_width_100() -> None:
def test_css_sidebar_new_btn_dashed_border() -> None:
""".sidebar-new-btn must have a dashed border."""
import re
css = read_css()
match = re.search(
r"\.sidebar-new-btn\s*\{([^}]*)\}",
@@ -1505,24 +1510,26 @@ def test_css_fab_class_exists() -> None:
def test_css_fab_display_none_by_default() -> None:
""".new-session-fab must have display:none as default (hidden on desktop)."""
import re
css = read_css()
# Find the .new-session-fab block (non-media-query context)
# Match the block that is NOT inside a @media rule
# Look for .new-session-fab { ... display: none ... } outside of @media
# Simple check: the rule body should contain 'display' before the first @media containing it
match = re.search(r'\.new-session-fab\s*\{([^}]*)\}', css)
match = re.search(r"\.new-session-fab\s*\{([^}]*)\}", css)
assert match, ".new-session-fab rule not found"
body = match.group(1)
assert "display" in body and ("none" in body or "display:none" in body.replace(" ", "")), (
f".new-session-fab must have display:none by default, got body: {body!r}"
)
assert "display" in body and (
"none" in body or "display:none" in body.replace(" ", "")
), f".new-session-fab must have display:none by default, got body: {body!r}"
def test_css_fab_position_fixed() -> None:
""".new-session-fab must be position:fixed."""
import re
css = read_css()
match = re.search(r'\.new-session-fab\s*\{([^}]*)\}', css)
match = re.search(r"\.new-session-fab\s*\{([^}]*)\}", css)
assert match, ".new-session-fab rule not found"
body = match.group(1)
assert "position" in body and "fixed" in body, (
@@ -1533,8 +1540,9 @@ def test_css_fab_position_fixed() -> None:
def test_css_fab_size_56px() -> None:
""".new-session-fab must be 56px width and height."""
import re
css = read_css()
match = re.search(r'\.new-session-fab\s*\{([^}]*)\}', css)
match = re.search(r"\.new-session-fab\s*\{([^}]*)\}", css)
assert match, ".new-session-fab rule not found"
body = match.group(1)
assert "56px" in body, (
@@ -1545,24 +1553,22 @@ def test_css_fab_size_56px() -> None:
def test_css_fab_border_radius_50_percent() -> None:
""".new-session-fab must have border-radius:50% for circular shape."""
import re
css = read_css()
match = re.search(r'\.new-session-fab\s*\{([^}]*)\}', css)
match = re.search(r"\.new-session-fab\s*\{([^}]*)\}", css)
assert match, ".new-session-fab rule not found"
body = match.group(1)
assert "50%" in body, (
f".new-session-fab must have border-radius:50%, got: {body!r}"
)
assert "50%" in body, f".new-session-fab must have border-radius:50%, got: {body!r}"
def test_css_fab_mobile_media_query_shows_flex() -> None:
"""At max-width: 959px, .new-session-fab must be shown as display:flex."""
import re
css = read_css()
# Find the 959px media query and check that .new-session-fab uses display:flex
match = re.search(
r'@media\s*\([^)]*max-width\s*:\s*959px[^)]*\)\s*\{([^@]*)\}',
css,
re.DOTALL
r"@media\s*\([^)]*max-width\s*:\s*959px[^)]*\)\s*\{([^@]*)\}", css, re.DOTALL
)
assert match, "Missing @media (max-width: 959px) block"
media_body = match.group(1)
@@ -1570,7 +1576,7 @@ def test_css_fab_mobile_media_query_shows_flex() -> None:
"@media (max-width: 959px) block must contain .new-session-fab rule"
)
# Find the .new-session-fab rule within the media query
fab_match = re.search(r'\.new-session-fab\s*\{([^}]*)\}', media_body)
fab_match = re.search(r"\.new-session-fab\s*\{([^}]*)\}", media_body)
assert fab_match, ".new-session-fab rule not found in 959px media query"
fab_body = fab_match.group(1)
assert "flex" in fab_body, (
@@ -1581,11 +1587,10 @@ def test_css_fab_mobile_media_query_shows_flex() -> None:
def test_css_fab_mobile_media_query_hides_new_session_btn() -> None:
"""At max-width: 959px, #new-session-btn must be hidden."""
import re
css = read_css()
match = re.search(
r'@media\s*\([^)]*max-width\s*:\s*959px[^)]*\)\s*\{([^@]*)\}',
css,
re.DOTALL
r"@media\s*\([^)]*max-width\s*:\s*959px[^)]*\)\s*\{([^@]*)\}", css, re.DOTALL
)
assert match, "Missing @media (max-width: 959px) block"
media_body = match.group(1)
@@ -1593,7 +1598,7 @@ def test_css_fab_mobile_media_query_hides_new_session_btn() -> None:
"@media (max-width: 959px) block must contain #new-session-btn rule to hide it"
)
# Find the #new-session-btn rule and verify it has display:none
btn_match = re.search(r'#new-session-btn\s*\{([^}]*)\}', media_body)
btn_match = re.search(r"#new-session-btn\s*\{([^}]*)\}", media_body)
assert btn_match, "#new-session-btn rule not found in 959px media query"
btn_body = btn_match.group(1)
assert "none" in btn_body, (
@@ -1615,7 +1620,9 @@ def test_css_fab_focus_visible_outline_not_accent() -> None:
match = re.search(r"\.new-session-fab:focus-visible\s*\{([^}]*)\}", css)
assert match, "Missing .new-session-fab:focus-visible rule in style.css"
body = match.group(1)
assert "outline" in body, ".new-session-fab:focus-visible must have an outline property"
assert "outline" in body, (
".new-session-fab:focus-visible must have an outline property"
)
# The FAB background IS var(--accent), so using the same color as outline gives zero visible ring.
# Must use var(--bg) or var(--text) for sufficient contrast.
assert "var(--accent)" not in body, (
+6 -7
View File
@@ -458,6 +458,7 @@ def test_html_settings_tabs() -> None:
# All tabs must have settings-tab class
for tab_value in expected_tabs:
tab = tabs_container.find("button", attrs={"data-tab": tab_value})
assert tab is not None, f"Missing tab button with data-tab='{tab_value}'"
tab_classes = tab.get("class") or []
assert "settings-tab" in tab_classes, (
f"Tab data-tab='{tab_value}' must have class 'settings-tab', has: {tab_classes}"
@@ -902,7 +903,9 @@ def test_html_sidebar_footer_after_sidebar_list() -> None:
footer_idx = i
assert list_idx is not None, "#sidebar-list must be in #session-sidebar children"
assert footer_idx is not None, "div.sidebar-footer must be in #session-sidebar children"
assert footer_idx is not None, (
"div.sidebar-footer must be in #session-sidebar children"
)
assert list_idx < footer_idx, (
f"div.sidebar-footer must appear after #sidebar-list, "
f"got list_idx={list_idx}, footer_idx={footer_idx}"
@@ -965,9 +968,7 @@ def test_html_fab_exists() -> None:
soup = _SOUP
fab = soup.find(id="new-session-fab")
assert fab is not None, "Missing #new-session-fab"
assert fab.name == "button", (
f"#new-session-fab must be a <button>, got: {fab.name}"
)
assert fab.name == "button", f"#new-session-fab must be a <button>, got: {fab.name}"
classes = fab.get("class") or []
assert "new-session-fab" in classes, (
f"#new-session-fab must have class 'new-session-fab', has: {classes}"
@@ -976,9 +977,7 @@ def test_html_fab_exists() -> None:
f"#new-session-fab must have aria-label='New session', got: {fab.get('aria-label')!r}"
)
text = fab.get_text(strip=True)
assert text == "+", (
f"#new-session-fab text must be '+', got: {text!r}"
)
assert text == "+", f"#new-session-fab text must be '+', got: {text!r}"
def test_html_fab_before_toast() -> None:
+4 -12
View File
@@ -1666,9 +1666,7 @@ def test_show_new_session_input_handles_blur_with_delay() -> None:
assert match, "showNewSessionInput function not found"
body = match.group(1)
assert "blur" in body, "showNewSessionInput must handle blur event"
assert "150" in body, (
"showNewSessionInput must use 150ms delay on blur"
)
assert "150" in body, "showNewSessionInput must use 150ms delay on blur"
def test_create_new_session_posts_to_api_sessions() -> None:
@@ -1775,9 +1773,7 @@ def test_exports_create_new_session() -> None:
)
assert match, "module.exports block not found"
exports = match.group(1)
assert "createNewSession" in exports, (
"module.exports must export createNewSession"
)
assert "createNewSession" in exports, "module.exports must export createNewSession"
# ============================================================
@@ -1850,9 +1846,7 @@ def test_js_close_session_restores_fab() -> None:
assert "new-session-fab" in body, (
"closeSession must reference 'new-session-fab' to restore FAB when session closed"
)
assert "remove" in body, (
"closeSession must call classList.remove('hidden') on FAB"
)
assert "remove" in body, "closeSession must call classList.remove('hidden') on FAB"
def test_js_fab_exported() -> None:
@@ -2210,9 +2204,7 @@ def test_render_grid_applies_alphabetical_sort_with_locale_compare() -> None:
)
assert match, "renderGrid function not found in app.js"
body = match.group(1)
assert "alphabetical" in body, (
"renderGrid must check for 'alphabetical' sort order"
)
assert "alphabetical" in body, "renderGrid must check for 'alphabetical' sort order"
assert "localeCompare" in body, (
"renderGrid must use localeCompare for alphabetical sort"
)