1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 03:36:48 +00:00
webvirtcloud/computes/tests/test_host_nav.py
catborise 86c708ed68 refactor(computes): the host pages share one section nav
Eleven host pages (overview, instances, storages, networks, interfaces,
nwfilters, secrets and their item pages) each carried their own copy of
the links to the host's sections, as a breadcrumb: the sections are
siblings, not a path, and on a phone the separators were left at the
start of wrapped lines. The item pages marked no section at all.

computes/host_nav.html is the one nav, labelled "Host sections": pills
that wrap, the page's section marked active, with aria-current="page"
on the section's own page and "true" on an item of it.
2026-10-27 14:51:18 +03:00

25 lines
1.1 KiB
Python

"""The host pages' shared section links."""
from django.template.loader import render_to_string
from django.test import TestCase
from lxml import html
from computes.models import Compute
class HostNavTestCase(TestCase):
def setUp(self):
self.compute = Compute.objects.create(name="c", hostname="192.0.2.1", login="u", password="p", type=1)
def links(self, **context):
nav = html.fromstring(render_to_string("computes/host_nav.html", {"compute": self.compute, **context}))
return {link.text_content().strip(): (link.get("class"), link.get("aria-current")) for link in nav.iter("a")}
def test_the_section_s_own_page_is_the_current_page(self):
links = self.links(section="storages")
self.assertEqual(len(links), 7)
self.assertEqual(links["Storages"], ("nav-link active", "page"))
self.assertEqual(links["Overview"], ("nav-link", None))
def test_an_item_of_a_section_marks_the_section_without_being_its_page(self):
self.assertEqual(self.links(section="networks", detail=True)["Networks"], ("nav-link active", "true"))