fix: highlight active portal navigation

This commit is contained in:
QiuSW
2026-07-04 10:47:35 +08:00
parent 898329e047
commit de92a584ad
5 changed files with 75 additions and 10 deletions
+39
View File
@@ -110,6 +110,20 @@ class PortalAccountFlowTests(TestCase):
ai_model=ai_model,
)
def assert_nav_link_active(self, response, *, href: str, label: str):
html = response.content.decode("utf-8")
self.assertIn(
f'<a class="btn btn-sm btn-primary" aria-current="page" href="{href}">{label}</a>',
html,
)
def assert_nav_link_inactive(self, response, *, href: str, label: str):
html = response.content.decode("utf-8")
self.assertIn(
f'<a class="btn btn-sm btn-outline-secondary" href="{href}">{label}</a>',
html,
)
def test_signup_creates_unverified_user_wallet_with_zero_points_and_no_ledger(self):
suffix = uuid.uuid4().hex[:8]
email = f"signup-{suffix}@example.com"
@@ -250,6 +264,31 @@ class PortalAccountFlowTests(TestCase):
self.assertNotContains(response, "api_key_encrypted")
self.assertNotContains(response, "extra_body")
def test_authenticated_nav_highlights_current_page_only(self):
user = self.create_verified_user()
self.client.force_login(user)
cases = (
("/dashboard", "/dashboard", "控制台"),
("/recharge", "/recharge", "充值"),
("/apikeys", "/apikeys", "API Key"),
("/models", "/models", "可用模型"),
("/records/recharge", "/records/recharge", "充值记录"),
("/records/usage", "/records/usage", "消费记录"),
)
for path, href, label in cases:
with self.subTest(path=path):
response = self.client.get(path)
self.assertEqual(response.status_code, 200)
self.assert_nav_link_active(response, href=href, label=label)
if path != "/recharge":
self.assert_nav_link_inactive(
response,
href="/recharge",
label="充值",
)
def test_create_api_key_shows_plaintext_once_and_stores_only_hash(self):
user = self.create_verified_user()
self.client.force_login(user)