from uuid import uuid4 from playwright.sync_api import Page, expect def test_production_form_loads(page: Page): """Verify the production form page loads correctly.""" page.goto("/ui/production") expect(page).to_have_title("CalMiner Production") expect(page.locator("h1")).to_have_text("Production") def test_create_production_item(page: Page): """Test creating a new production item through the UI.""" # First, create a scenario to associate the production with. page.goto("/ui/scenarios") scenario_name = f"Production 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 production page and add an item. page.goto("/ui/production") # Create a production item. production_desc = "Ore extracted - Grade A" page.select_option("select[name='scenario_id']", label=scenario_name) page.fill("input[name='description']", production_desc) page.fill("input[name='amount']", "1500") page.click("button[type='submit']") with page.expect_response("**/api/production/") as response_info: pass assert response_info.value.status == 201 # Verify the new item appears in the table. expect(page.locator(f"tr:has-text('{production_desc}')")).to_be_visible() # Verify the feedback message. expect(page.locator("#production-feedback") ).to_have_text("Production output saved.")