diff --git a/l4d2web/tests/e2e/test_editor.py b/l4d2web/tests/e2e/test_editor.py new file mode 100644 index 0000000..a5a87ed --- /dev/null +++ b/l4d2web/tests/e2e/test_editor.py @@ -0,0 +1,58 @@ +"""End-to-end test for the textarea code editor. + +Logs in as the seed user, navigates to the blueprint detail page, types +`sv_che` into the editor, asserts the autocomplete popup appears with +`sv_cheats`, accepts via Tab, and asserts the underlying textarea now +contains `sv_cheats`. +""" + +import pytest +from playwright.sync_api import expect, sync_playwright + + +@pytest.mark.e2e +def test_editor_autocomplete_inserts_cvar(live_server) -> None: + base = live_server["base_url"] + blueprint_id = live_server["blueprint_id"] + + with sync_playwright() as p: + browser = p.chromium.launch() + ctx = browser.new_context() + page = ctx.new_page() + + # Log in. + page.goto(f"{base}/login") + page.fill('input[name="username"]', "alice") + page.fill('input[name="password"]', "secret") + page.click('button[type="submit"]') + expect(page).to_have_url(f"{base}/dashboard", timeout=5000) + + # Navigate to the seeded blueprint. + page.goto(f"{base}/blueprints/{blueprint_id}") + + # Editor mounts on DOMContentLoaded; the contenteditable replaces + # the textarea visually. Wait for it. + editor = page.locator(".editor-code").first + expect(editor).to_be_visible(timeout=5000) + + # Focus the editor and type a cvar prefix. + editor.click() + page.keyboard.type("sv_che") + + # The popup should appear and contain sv_cheats. + popup = page.locator(".editor-popup") + expect(popup).to_be_visible(timeout=2000) + expect(popup).to_contain_text("sv_cheats") + + # Accept via Tab. Verifies Task 9's capture-phase keydown fix: + # CodeJar would otherwise consume Tab and insert 2 spaces + # before our popup handler ran. + page.keyboard.press("Tab") + + # The hidden textarea (form field) must now contain the cvar. + textarea_value = page.evaluate( + "() => document.querySelector('textarea[name=config]').value" + ) + assert "sv_cheats" in textarea_value + + browser.close()