Add budget block review with monthly comparison

This commit is contained in:
JKuijperM 2026-10-21 19:28:40 +02:00
parent e46a1e3668
commit b967d218b7

View File

@ -1,3 +1,4 @@
import re
import pytest
from datetime import date
from decimal import Decimal
@ -215,3 +216,33 @@ def test_goal_list_ignores_invalid_kind_param(auth_client, user, category):
assert response.status_code == 200
assert [g.name for g in response.context["goals"]] == ["Pago"]
assert response.context["selected_kind"] == ""
@pytest.mark.parametrize("route", ["goal_list", "dashboard", "home"])
def test_progressbar_aria_valuenow_stays_within_valuemax_when_over_target(
auth_client, user, account, category, route
):
# Presupuesto al 150 %. aria-valuemax es 100, así que aria-valuenow tiene
# que ir capado (bar_width), no el porcentaje real: si no, el lector de
# pantalla recibe un valor fuera de rango. El 150 % ya se dice en el texto.
Goal.objects.create(
owner=user, name="Presupuesto", kind=Goal.KIND_BUDGET, category=category,
target_amount=Decimal("100"), period=Goal.PERIOD_MONTH, show_on_home=True,
)
Expense.objects.create(
owner=user, account=account, category=category,
amount=Decimal("150"), date=date.today(),
)
# Otro objetivo al 37,5 %: el capado de arriba da el entero 100, sin
# decimales, así que solo este delata un |unlocalize que falte (saldría
# "37,5", que no es un número válido para aria-valuenow).
Goal.objects.create(
owner=user, name="Pago", kind=Goal.KIND_PAYMENT, category=category,
target_amount=Decimal("400"), show_on_home=True,
)
content = auth_client.get(reverse(route)).content.decode()
values = re.findall(r'role="progressbar"[^>]*?aria-valuenow="([^"]*)"', content, re.S)
assert len(values) == 2, "faltan barras de progreso en %s: %s" % (route, values)
assert sorted(float(value) for value in values) == [37.5, 100], values