panel: Allowance shows what's left; Remaining becomes Dues
The Members table's Allowance column printed the uniform $15 balance, which is the total, not what the member still has. It now computes max(balance - spend, 0) client-side from the two served fields (no series summed in the browser), keeps its allowance-only class so it still hides in All-time mode, and reads "Allowance left" with a title saying it is a budget, not OC dues. The Remaining column (allowance + credits - spend, a credit figure) is replaced by Dues: the member's current Open Collective contribution level, rendered $10/mo / $120/yr and '—' when the portal has no readable level. Dues sorts by dues_amount with unknowns last, and carries no balance-col, so it stays visible in both modes. tests/check-page-js.sh now stubs classList/parentElement so a harness can observe the mode toggle; admin-panel-dues-harness.js pins the subtraction, floor, dues text, null handling, sort and 10-cell column count in both modes; tests/test_member_table_columns.py pins the header/row alignment.
This commit is contained in:
1 parent
3c3fb0b921
commit
2ae9868966
4 files changed
+264
-7
No files matched your search
@@ -83,6 +83,10 @@ const mkEl = (id) => {
|
||||
const el = {
|
||||
id, style: {}, textContent: "", innerHTML: "", className: "",
|
||||
offsetWidth: 120, offsetHeight: 48,
|
||||
// classList/parentElement, because the tables toggle their mode class on
|
||||
// the table's PARENT (members-all-time / admins-all-time) and a harness
|
||||
// must be able to observe that toggle rather than crash on it.
|
||||
classList: null, parentElement: null, __classes: {},
|
||||
// Stateful attributes, like a real element: a stub that always answers null
|
||||
// cannot tell "wired once" from "wired on every call".
|
||||
getAttribute: (k) => (k in attrs ? attrs[k] : null),
|
||||
@@ -98,6 +102,13 @@ const mkEl = (id) => {
|
||||
// (buildMetricButtons inserts the SHARED metric list), so the stub has to
|
||||
// support it or the harness cannot exercise that path at all.
|
||||
el.insertAdjacentHTML = (pos, html) => { el.innerHTML += html; };
|
||||
el.classList = {
|
||||
toggle: (c, on) => { el.__classes[c] = (on === undefined ? !el.__classes[c] : !!on); },
|
||||
add: (c) => { el.__classes[c] = true; },
|
||||
remove: (c) => { el.__classes[c] = false; },
|
||||
contains: (c) => !!el.__classes[c],
|
||||
};
|
||||
el.parentElement = { classList: el.classList };
|
||||
return el;
|
||||
};
|
||||
globalThis.document = {
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#!/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 <th> 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 <td> 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 id="table-members">'):]
|
||||
table = table[:table.index("</table>")]
|
||||
thead = table[:table.index("</thead>")]
|
||||
headers = re.findall(r"<th[^>]*>(.*?)</th>", 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"'<td", body))
|
||||
check(tds == 10, f"the member row template emits 10 <td> 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")
|
||||
Reference in new issue
Block a user