aboutsummaryrefslogtreecommitdiff
path: root/tests/integration/test_ui.py
blob: f86c74bf367166d527050a21b47bf42e74744102 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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()