test: fix zone_ctl fixture, pattern assertions, and browser cleanup
Made-with: Cursor
This commit is contained in:
@@ -40,7 +40,7 @@ class BrowserTest:
|
||||
self.base_url = base_url
|
||||
self.driver = None
|
||||
self.headless = headless
|
||||
self.created_tabs: List[str] = []
|
||||
self.created_zones: List[str] = []
|
||||
self.created_profiles: List[str] = []
|
||||
self.created_presets: List[str] = []
|
||||
|
||||
@@ -161,8 +161,8 @@ class BrowserTest:
|
||||
except Exception as e:
|
||||
print(f" ⚠ Failed to cleanup preset {preset_id}: {e}")
|
||||
|
||||
# Delete created tabs by ID
|
||||
for zone_id in self.created_tabs:
|
||||
# Delete created zones by ID
|
||||
for zone_id in self.created_zones:
|
||||
try:
|
||||
response = session.delete(f"{self.base_url}/zones/{zone_id}")
|
||||
if response.status_code == 200:
|
||||
@@ -183,17 +183,17 @@ class BrowserTest:
|
||||
test_names = ['Browser Test Zone', 'Browser Test Profile', 'Browser Test Preset',
|
||||
'Preset 1', 'Preset 2', 'Preset 3', 'Edited Browser Zone']
|
||||
|
||||
# Cleanup tabs by name
|
||||
# Cleanup zones by name
|
||||
try:
|
||||
tabs_response = session.get(f"{self.base_url}/zones")
|
||||
if tabs_response.status_code == 200:
|
||||
tabs_data = tabs_response.json()
|
||||
tabs = tabs_data.get('zones', {})
|
||||
for zone_id, tab_data in zones.items():
|
||||
if isinstance(tab_data, dict) and tab_data.get('name') in test_names:
|
||||
zones_response = session.get(f"{self.base_url}/zones")
|
||||
if zones_response.status_code == 200:
|
||||
zones_data = zones_response.json()
|
||||
zones_map = zones_data.get('zones', {})
|
||||
for zone_id, zone_row in zones_map.items():
|
||||
if isinstance(zone_row, dict) and zone_row.get('name') in test_names:
|
||||
try:
|
||||
session.delete(f"{self.base_url}/zones/{zone_id}")
|
||||
print(f" ✓ Cleaned up zone by name: {tab_data.get('name')}")
|
||||
print(f" ✓ Cleaned up zone by name: {zone_row.get('name')}")
|
||||
except:
|
||||
pass
|
||||
except:
|
||||
@@ -232,7 +232,7 @@ class BrowserTest:
|
||||
pass
|
||||
|
||||
# Clear the lists
|
||||
self.created_tabs.clear()
|
||||
self.created_zones.clear()
|
||||
self.created_profiles.clear()
|
||||
self.created_presets.clear()
|
||||
except Exception as e:
|
||||
@@ -308,9 +308,9 @@ def test_browser_connection(browser: BrowserTest) -> bool:
|
||||
finally:
|
||||
browser.teardown()
|
||||
|
||||
def test_tabs_ui(browser: BrowserTest) -> bool:
|
||||
"""Test tabs UI in browser."""
|
||||
print("\n=== Testing Tabs UI in Browser ===")
|
||||
def test_zones_ui(browser: BrowserTest) -> bool:
|
||||
"""Test zones UI in browser."""
|
||||
print("\n=== Testing Zones UI in Browser ===")
|
||||
passed = 0
|
||||
total = 0
|
||||
|
||||
@@ -328,20 +328,20 @@ def test_tabs_ui(browser: BrowserTest) -> bool:
|
||||
browser.teardown()
|
||||
return False
|
||||
|
||||
# Test 2: Open tabs modal
|
||||
# Test 2: Open zones modal
|
||||
total += 1
|
||||
if browser.click_element(By.ID, 'zones-btn'):
|
||||
print("✓ Clicked Tabs button")
|
||||
print("✓ Clicked Zones button")
|
||||
# Wait for modal to appear
|
||||
time.sleep(0.5)
|
||||
modal = browser.wait_for_element(By.ID, 'zones-modal')
|
||||
if modal and 'active' in modal.get_attribute('class'):
|
||||
print("✓ Tabs modal opened")
|
||||
print("✓ Zones modal opened")
|
||||
passed += 1
|
||||
else:
|
||||
print("✗ Tabs modal didn't open")
|
||||
print("✗ Zones modal didn't open")
|
||||
else:
|
||||
print("✗ Failed to click Tabs button")
|
||||
print("✗ Failed to click Zones button")
|
||||
|
||||
# Test 3: Create a zone via UI
|
||||
total += 1
|
||||
@@ -367,7 +367,7 @@ def test_tabs_ui(browser: BrowserTest) -> bool:
|
||||
if 'Browser Test Zone' in row.text:
|
||||
zone_id = row.get_attribute('data-zone-id')
|
||||
if zone_id:
|
||||
browser.created_tabs.append(zone_id)
|
||||
browser.created_zones.append(zone_id)
|
||||
break
|
||||
except:
|
||||
pass # If we can't extract ID, cleanup will try by name
|
||||
@@ -375,13 +375,13 @@ def test_tabs_ui(browser: BrowserTest) -> bool:
|
||||
else:
|
||||
print("✗ Zone not found in list after creation")
|
||||
else:
|
||||
print("✗ Tabs list not found")
|
||||
print("✗ Zones list not found")
|
||||
else:
|
||||
print("✗ Failed to click create button")
|
||||
except Exception as e:
|
||||
print(f"✗ Failed to create zone via UI: {e}")
|
||||
|
||||
# Test 4: Edit a zone via UI (right-click in Tabs list)
|
||||
# Test 4: Edit a zone via UI (right-click in zones list)
|
||||
total += 1
|
||||
try:
|
||||
# First, close and reopen modal to refresh
|
||||
@@ -450,7 +450,7 @@ def test_tabs_ui(browser: BrowserTest) -> bool:
|
||||
browser.cleanup_test_data()
|
||||
browser.teardown()
|
||||
|
||||
print(f"\nBrowser tabs UI tests: {passed}/{total} passed")
|
||||
print(f"\nBrowser zones UI tests: {passed}/{total} passed")
|
||||
return passed == total
|
||||
|
||||
def test_profiles_ui(browser: BrowserTest) -> bool:
|
||||
@@ -778,14 +778,14 @@ def test_preset_drag_and_drop(browser: BrowserTest) -> bool:
|
||||
browser.teardown()
|
||||
return False
|
||||
|
||||
# Test 2: Open tabs modal and create/select a zone
|
||||
# Test 2: Open zones modal and create/select a zone
|
||||
total += 1
|
||||
browser.click_element(By.ID, 'zones-btn')
|
||||
time.sleep(0.5)
|
||||
|
||||
# Check if we have tabs, if not create one
|
||||
# Check if we have zones, if not create one
|
||||
tabs_list = browser.wait_for_element(By.ID, 'zones-list-modal')
|
||||
if tabs_list and 'No tabs found' in tabs_list.text:
|
||||
if tabs_list and 'No zones found' in tabs_list.text:
|
||||
# Create a zone
|
||||
browser.fill_input(By.ID, 'new-zone-name', 'Drag Test Zone')
|
||||
browser.click_element(By.ID, 'create-zone-btn')
|
||||
@@ -799,7 +799,7 @@ def test_preset_drag_and_drop(browser: BrowserTest) -> bool:
|
||||
print("✓ Selected a zone")
|
||||
passed += 1
|
||||
else:
|
||||
print("✗ No tabs available to select")
|
||||
print("✗ No zones available to select")
|
||||
browser.click_element(By.ID, 'zones-close-btn')
|
||||
browser.teardown()
|
||||
return False
|
||||
@@ -1012,7 +1012,7 @@ def main():
|
||||
|
||||
# Run browser tests
|
||||
results.append(("Browser Connection", test_browser_connection(browser)))
|
||||
results.append(("Tabs UI", test_tabs_ui(browser)))
|
||||
results.append(("Zones UI", test_zones_ui(browser)))
|
||||
results.append(("Profiles UI", test_profiles_ui(browser)))
|
||||
results.append(("Presets UI", test_presets_ui(browser)))
|
||||
results.append(("Color Palette UI", test_color_palette_ui(browser)))
|
||||
|
||||
Reference in New Issue
Block a user