"""Navigatia: doua taburi principale (Cantarire, Setari) si subnavigatia de administrare.""" from __future__ import annotations MAIN_TABS = ("Cântărire", "Setări") ADMIN_LINKS = ( ("/componente", "Componente"), ("/retete", "Produse finite"), ("/sabloane", "Șabloane"), ("/campuri", "Câmpuri"), ("/istoric", "Istoric"), ("/monitor", "Monitor serial"), ) def _html(client, path): return client.get(path).get_data(as_text=True) def _flat(html: str) -> str: """Colapseaza spatiile, ca sa nu depinda de indentarea Jinja.""" return " ".join(html.split()) def test_dashboard_has_only_two_main_tabs(client): html = _html(client, "/") assert 'class="nav"' in html for label in MAIN_TABS: assert f">{label}" in _flat(html) # sectiunile de administrare nu mai sunt in bara principala nav = _flat(html).split('class="nav"', 1)[1].split("", 1)[0] for _href, label in ADMIN_LINKS: assert f">{label}" not in nav # dashboard-ul nu arata subnavigatia assert 'class="subnav"' not in html def test_settings_page_is_hub_and_shows_subnav(client): html = _html(client, "/setari") flat = _flat(html) assert 'class="subnav"' in html # cardurile din hub assert 'class="hub-grid"' in html for href, label in ADMIN_LINKS: assert f'href="{href}"' in flat assert label in flat # ambele taburi principale sunt prezente, Setari e activ for label in MAIN_TABS: assert f">{label}" in flat assert 'class="active">Setări' in flat def test_admin_pages_keep_subnav_and_mark_active(client): for path, label in ADMIN_LINKS: html = _flat(_html(client, path)) assert 'class="subnav"' in html, path assert f'class="active">{label}' in html, path def test_designer_page_is_under_templates_tab(client): response = client.post("/sabloane/designer/nou", data={"name": "Nav test"}, follow_redirects=True) flat = _flat(response.get_data(as_text=True)) assert 'class="subnav"' in flat assert 'class="active">Șabloane' in flat # "Cantarire" nu e activ aici assert 'class="active">Cântărire' not in flat