""" e2e tests for the Fieldkit pages. Safety note: we do NOT actually fire the killswitch in any test — doing so would destroy the session-scoped data directory and break all subsequent tests. We verify the UI renders correctly and the form fields are present, but we do not submit the final "Execute Purge" action. """ from __future__ import annotations import pytest from playwright.sync_api import Page, expect @pytest.mark.e2e def test_fieldkit_status_page_loads(live_server: str, authenticated_page: Page) -> None: """The /fieldkit/ status dashboard loads and shows expected sections.""" page = authenticated_page page.goto(f"{live_server}/fieldkit/") page.wait_for_load_state("networkidle") # Two key sections: dead man's switch and killswitch expect(page.locator("body")).to_contain_text("Dead Man") expect(page.locator("body")).to_contain_text("Killswitch") @pytest.mark.e2e def test_fieldkit_status_shows_disarmed_deadman( live_server: str, authenticated_page: Page ) -> None: """With deadman disabled in test config, the switch shows 'Disarmed'.""" page = authenticated_page page.goto(f"{live_server}/fieldkit/") page.wait_for_load_state("networkidle") # The conftest configures deadman_enabled=False so the badge must be Disarmed deadman_section = page.locator("body") expect(deadman_section).to_contain_text("Disarmed") @pytest.mark.e2e def test_killswitch_page_loads(live_server: str, authenticated_page: Page) -> None: """The /fieldkit/killswitch page loads and shows the confirmation form.""" page = authenticated_page page.goto(f"{live_server}/fieldkit/killswitch") page.wait_for_load_state("networkidle") # Must have the text confirmation input expect(page.locator("input[name='confirm']")).to_be_visible() # Must have the password confirmation input expect(page.locator("input[name='password']")).to_be_visible() # The destructive submit button must be present but we do NOT click it expect(page.locator("button[type='submit']")).to_be_visible() @pytest.mark.e2e def test_killswitch_requires_admin(live_server: str, page: Page) -> None: """The killswitch page requires authentication; unauthenticated access is redirected.""" page.goto(f"{live_server}/fieldkit/killswitch") page.wait_for_load_state("networkidle") assert "/login" in page.url or "/setup" in page.url, ( f"Expected auth redirect for killswitch, got {page.url}" ) @pytest.mark.e2e def test_fieldkit_link_from_status(live_server: str, authenticated_page: Page) -> None: """The 'Killswitch Panel' link on the status page navigates correctly.""" page = authenticated_page page.goto(f"{live_server}/fieldkit/") page.wait_for_load_state("networkidle") link = page.locator("a[href*='killswitch']") expect(link).to_be_visible() link.click() page.wait_for_load_state("networkidle") assert "killswitch" in page.url, f"Expected killswitch URL, got {page.url}" expect(page.locator("input[name='confirm']")).to_be_visible()