from uuid import uuid4 from playwright.sync_api import Page, expect def test_equipment_form_loads(page: Page): """Verify the equipment form page loads correctly.""" page.goto("/ui/equipment") expect(page).to_have_title("CalMiner Equipment") expect(page.locator("h1")).to_have_text("Equipment") def test_create_equipment_item(page: Page): """Test creating a new equipment item through the UI.""" # First, create a scenario to associate the equipment with. page.goto("/ui/scenarios") scenario_name = f"Equipment Test Scenario {uuid4()}" page.fill("input[name='name']", scenario_name) page.click("button[type='submit']") with page.expect_response("**/api/scenarios/"): pass # Wait for the scenario to be created # Now, navigate to the equipment page and add an item. page.goto("/ui/equipment") # Create an equipment item. equipment_name = "Haul Truck HT-05" equipment_desc = "Primary haul truck for ore transport." page.select_option("select[name='scenario_id']", label=scenario_name) page.fill("input[name='name']", equipment_name) page.fill("textarea[name='description']", equipment_desc) page.click("button[type='submit']") with page.expect_response("**/api/equipment/") as response_info: pass assert response_info.value.status == 200 # Verify the new item appears in the table. expect(page.locator(f"tr:has-text('{equipment_name}')")).to_be_visible() # Verify the feedback message. expect(page.locator("#equipment-feedback") ).to_have_text("Equipment saved.")