#!/usr/bin/env python3 """Structural guard for the admin panel's MEMBERS table columns. WHY THIS EXISTS A column was removed from the body once while its header stayed, and every column after it sat under the wrong heading (reset dates rendered under "Remaining"). The interface must keep header cells and row cells in step, and the retired "Remaining" column must not creep back. Pins: * the members thead has exactly 10 cells, and the loading row spans 10; * the headers read "Allowance left" and "Dues", and no "Remaining" header; * the member row template emits exactly 10 cells; * Allowance sorts by the computed allowance-left value, Dues by dues_amount; * the Allowance cell computes `balance - memberSpend`, never `m.balance`. python3 tests/test_member_table_columns.py """ import pathlib import re import sys SRC = (pathlib.Path(__file__).resolve().parent.parent / "app" / "main.py").read_text() FAILS = [] def check(cond, msg): print((" ok " if cond else " FAIL ") + msg) if not cond: FAILS.append(msg) table = SRC[SRC.index(''):] table = table[:table.index("
")] thead = table[:table.index("")] headers = re.findall(r"]*>(.*?)", thead, re.S) header_text = [re.sub(r"<[^>]*>", "", h).strip() for h in headers] check(len(headers) == 10, f"members table has 10 header cells (got {len(headers)})") check(header_text == ["Member", "Status", "Activated", "Source", "Allowance left", "Credits", "Spend", "Dues", "Reset", "Adjust"], f"headers are exactly the expected 10 (got {header_text})") check("Remaining" not in " ".join(header_text), "no 'Remaining' header remains") check('colspan="10"' in table, 'the loading row spans all 10 columns') check("sortMembers('allowance_left')" in thead, "Allowance sorts by the computed allowance-left value, not the raw balance") check("sortMembers('dues_amount')" in thead, "Dues sorts by dues_amount") check('class="sortable balance-col allowance-only"' in thead and 'class="sortable" onclick="sortMembers(\'dues_amount\')"' in thead, "Allowance keeps balance-col allowance-only; Dues carries no balance-col") body = SRC[SRC.index("function renderMembers()"):] body = body[:body.index("clearArrows('members', memberSort)")] tds = len(re.findall(r"' cells (got {tds})") check("remaining-col" not in body, "no member cell carries the retired remaining-col class") check("fmt(m.balance)" not in body, "the Allowance cell no longer prints the uniform balance") check("fmt(m.remaining)" not in body, "the Remaining cell no longer prints the credit figure") check("fmt(allowanceLeft(m))" in body, "the Allowance cell prints allowanceLeft(m)") check("function allowanceLeft(m)" in SRC and "Math.max(Number(m.balance ?? 0) - memberSpend(m), 0)" in SRC, "allowanceLeft is max(balance - spend, 0)") check("duesCell(m)" in body and "function duesCell(m)" in SRC, "the Dues cell renders from the portal's dues fields") print() if FAILS: print(f"member table columns: {len(FAILS)} FAILURE(S)") sys.exit(1) print("member table columns: all checks passed")