- Updated test functions in various test files to enhance code clarity by formatting long lines and improving indentation. - Adjusted assertions to use multi-line formatting for better readability. - Added new test cases for theme settings API to ensure proper functionality. - Ensured consistent use of line breaks and spacing across test files for uniformity.
59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
from uuid import uuid4
|
|
|
|
from playwright.sync_api import Page, expect
|
|
|
|
|
|
def test_maintenance_form_loads(page: Page):
|
|
"""Verify the maintenance form page loads correctly."""
|
|
page.goto("/ui/maintenance")
|
|
expect(page).to_have_title("Maintenance · CalMiner")
|
|
expect(page.locator("h2:has-text('Add Maintenance Entry')")).to_be_visible()
|
|
|
|
|
|
def test_create_maintenance_item(page: Page):
|
|
"""Test creating a new maintenance item through the UI."""
|
|
# First, create a scenario and an equipment item.
|
|
page.goto("/ui/scenarios")
|
|
scenario_name = f"Maintenance Test Scenario {uuid4()}"
|
|
page.fill("input[name='name']", scenario_name)
|
|
page.click("button[type='submit']")
|
|
with page.expect_response("**/api/scenarios/"):
|
|
pass
|
|
|
|
page.goto("/ui/equipment")
|
|
equipment_name = f"Excavator EX-12 {uuid4()}"
|
|
page.select_option("#equipment-form-scenario", label=scenario_name)
|
|
page.fill("#equipment-form-name", equipment_name)
|
|
page.click("button[type='submit']")
|
|
with page.expect_response("**/api/equipment/"):
|
|
pass
|
|
|
|
# Now, navigate to the maintenance page and add an item.
|
|
page.goto("/ui/maintenance")
|
|
|
|
# Create a maintenance item.
|
|
maintenance_desc = "Scheduled engine overhaul"
|
|
page.select_option("#maintenance-form-scenario", label=scenario_name)
|
|
page.select_option("#maintenance-form-equipment", label=equipment_name)
|
|
page.fill("#maintenance-form-date", "2025-12-01")
|
|
page.fill("#maintenance-form-description", maintenance_desc)
|
|
page.fill("#maintenance-form-cost", "12000")
|
|
page.click("button[type='submit']")
|
|
|
|
with page.expect_response("**/api/maintenance/") as response_info:
|
|
pass
|
|
assert response_info.value.status == 201
|
|
|
|
# Verify the new item appears in the table.
|
|
page.select_option("#maintenance-scenario-filter", label=scenario_name)
|
|
expect(
|
|
page.locator("#maintenance-table-body tr").filter(
|
|
has_text=maintenance_desc
|
|
)
|
|
).to_be_visible()
|
|
|
|
# Verify the feedback message.
|
|
expect(page.locator("#maintenance-feedback")).to_have_text(
|
|
"Maintenance entry saved."
|
|
)
|