diff options
Diffstat (limited to 'tests/integration/test_ui.py')
| -rw-r--r-- | tests/integration/test_ui.py | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/tests/integration/test_ui.py b/tests/integration/test_ui.py new file mode 100644 index 0000000..f86c74b --- /dev/null +++ b/tests/integration/test_ui.py @@ -0,0 +1,136 @@ +""" +UI interaction tests for the application. +""" +import pytest +from selenium.webdriver.common.by import By +from selenium.webdriver.common.action_chains import ActionChains +from selenium.webdriver.common.keys import Keys +import time +import sys +import os + +# Import helper from conftest +sys.path.insert(0, os.path.dirname(__file__)) +from conftest import assert_no_javascript_errors + +pytestmark = [pytest.mark.nondestructive] + + +@pytest.mark.ui +def test_canvas_interaction(app): + """Test basic canvas interaction (click).""" + canvas = app.find_element(By.ID, "canvas") + + # Click on the canvas + ActionChains(app).move_to_element(canvas).click().perform() + + # Wait a moment for any click handlers + time.sleep(0.5) + + # Debug: Check what's in the error arrays + amulet_errors = app.execute_script("return window.amuletErrors;") + browser_logs = app.get_log("browser") + print(f"\n=== DEBUG INFO ===") + print(f"Amulet errors count: {len(amulet_errors) if amulet_errors else 0}") + if amulet_errors and len(amulet_errors) > 0: + print(f"Amulet errors: {amulet_errors}") + print(f"Browser log count: {len(browser_logs)}") + for log in browser_logs: + if log['level'] in ['SEVERE', 'WARNING']: + print(f" [{log['level']}] {log['message'][:200]}") + print(f"==================\n") + + # Check for JavaScript errors + assert_no_javascript_errors(app) + + # Verify canvas is still functional + assert canvas.is_displayed() + + +@pytest.mark.ui +def test_canvas_mouse_movement(app): + """Test mouse movement over canvas.""" + canvas = app.find_element(By.ID, "canvas") + + # Move mouse across canvas + actions = ActionChains(app) + actions.move_to_element_with_offset(canvas, 50, 50) + actions.move_by_offset(100, 100) + actions.perform() + + time.sleep(0.5) + assert_no_javascript_errors(app) + assert canvas.is_displayed() + + +@pytest.mark.ui +def test_keyboard_input(app): + """Test keyboard input to the application.""" + canvas = app.find_element(By.ID, "canvas") + + # Click canvas to focus + canvas.click() + time.sleep(0.3) + + # Send some keyboard input + actions = ActionChains(app) + actions.send_keys("w") + actions.send_keys("a") + actions.send_keys("s") + actions.send_keys("d") + actions.perform() + + time.sleep(0.5) + assert_no_javascript_errors(app) + assert canvas.is_displayed() + + +@pytest.mark.ui +def test_right_click_prevention(app): + """Test that right-click context menu is prevented on canvas.""" + canvas = app.find_element(By.ID, "canvas") + + # Attempt right-click (context menu should be prevented) + ActionChains(app).context_click(canvas).perform() + + time.sleep(0.3) + assert_no_javascript_errors(app) + + # Canvas should still be functional + assert canvas.is_displayed() + + +@pytest.mark.ui +def test_window_resize(app): + """Test that canvas handles window resize.""" + original_size = app.get_window_size() + + # Resize window + app.set_window_size(1280, 720) + time.sleep(0.5) + + canvas = app.find_element(By.ID, "canvas") + assert canvas.is_displayed() + assert_no_javascript_errors(app) + + # Restore original size + app.set_window_size(original_size["width"], original_size["height"]) + time.sleep(0.5) + + +@pytest.mark.ui +def test_canvas_drag(app): + """Test drag operations on canvas.""" + canvas = app.find_element(By.ID, "canvas") + + # Perform drag operation + actions = ActionChains(app) + actions.move_to_element_with_offset(canvas, 100, 100) + actions.click_and_hold() + actions.move_by_offset(50, 50) + actions.release() + actions.perform() + + time.sleep(0.5) + assert_no_javascript_errors(app) + assert canvas.is_displayed() |
