Files
ppr-ng/tests/e2e/test_admin_menus.py
2026-06-20 10:43:08 -04:00

74 lines
3.2 KiB
Python

import re
import pytest
from playwright.sync_api import expect
from helpers import app_url, login_as_admin, skip_without_admin_credentials
def open_admin_dropdown(page):
page.locator("#adminDropdownBtn").click()
admin_menu = page.locator("#adminDropdownMenu")
expect(admin_menu).to_have_class(re.compile("active"))
return admin_menu
def open_admin_page(page):
skip_without_admin_credentials(pytest)
page.goto(app_url("/admin"))
expect(page).to_have_title(re.compile("PPR Admin Interface"))
expect(page.get_by_role("heading", name=re.compile("Swansea Tower"))).to_be_visible()
login_as_admin(page)
def test_actions_and_admin_dropdowns_toggle_exclusively(page):
open_admin_page(page)
actions_menu = page.locator("#actionsDropdownMenu")
admin_menu = page.locator("#adminDropdownMenu")
expect(actions_menu).not_to_have_class(re.compile("active"))
expect(admin_menu).not_to_have_class(re.compile("active"))
page.locator("#actionsDropdownBtn").click()
expect(actions_menu).to_have_class(re.compile("active"))
expect(admin_menu).not_to_have_class(re.compile("active"))
expect(actions_menu.get_by_role("link", name=re.compile("New PPR"))).to_be_visible()
expect(actions_menu.get_by_role("link", name=re.compile("Book Out"))).to_be_visible()
expect(actions_menu.get_by_role("link", name=re.compile("Book In"))).to_be_visible()
expect(actions_menu.get_by_role("link", name=re.compile("Overflight"))).to_be_visible()
admin_menu = open_admin_dropdown(page)
expect(actions_menu).not_to_have_class(re.compile("active"))
expect(admin_menu.get_by_role("link", name=re.compile("Admin View"))).to_be_visible()
expect(admin_menu.get_by_role("link", name=re.compile("ATC View"))).to_be_visible()
expect(admin_menu.get_by_role("link", name=re.compile("Reports"))).to_be_visible()
expect(admin_menu.get_by_role("link", name=re.compile("Drone Requests"))).to_be_visible()
expect(admin_menu.get_by_role("link", name=re.compile("Journal Log"))).to_be_visible()
page.locator(".container").click()
expect(admin_menu).not_to_have_class(re.compile("active"))
def test_admin_menu_links_navigate_to_expected_pages(page):
open_admin_page(page)
menu_expectations = [
("Admin View", re.compile(r"/admin$"), re.compile("PPR Admin Interface"), "title"),
("ATC View", re.compile(r"/atc$"), re.compile("ATC Management Interface"), "title"),
("Reports", re.compile(r"/reports$"), re.compile("PPR Reports"), "heading"),
("Drone Requests", re.compile(r"/drone-requests$"), re.compile("Drone Flight Requests"), "heading"),
("Journal Log", re.compile(r"/journal$"), re.compile("Journal Log"), "heading"),
]
for label, url_pattern, expected_text, assertion_type in menu_expectations:
page.goto(app_url("/admin"))
login_as_admin(page)
admin_menu = open_admin_dropdown(page)
admin_menu.get_by_role("link", name=re.compile(label)).click()
expect(page).to_have_url(url_pattern)
if assertion_type == "title":
expect(page).to_have_title(expected_text)
else:
expect(page.get_by_role("heading", name=expected_text)).to_be_visible()