import pytest from playwright.sync_api import Page, expect # A list of UI routes to check, with their URL, expected title, and a key heading text. UI_ROUTES = [ ("/", "Dashboard · CalMiner", "Operations Overview"), ("/ui/dashboard", "Dashboard · CalMiner", "Operations Overview"), ( "/ui/scenarios", "Scenario Management · CalMiner", "Create a New Scenario", ), ("/ui/parameters", "Process Parameters · CalMiner", "Scenario Parameters"), ("/ui/settings", "Settings · CalMiner", "Settings"), ("/ui/costs", "Costs · CalMiner", "Cost Overview"), ("/ui/consumption", "Consumption · CalMiner", "Consumption Tracking"), ("/ui/production", "Production · CalMiner", "Production Output"), ("/ui/equipment", "Equipment · CalMiner", "Equipment Inventory"), ("/ui/maintenance", "Maintenance · CalMiner", "Maintenance Schedule"), ("/ui/simulations", "Simulations · CalMiner", "Monte Carlo Simulations"), ("/ui/reporting", "Reporting · CalMiner", "Scenario KPI Summary"), ("/ui/currencies", "Currencies · CalMiner", "Currency Overview"), ] @pytest.mark.parametrize("url, title, heading", UI_ROUTES) def test_ui_pages_load_correctly( page: Page, url: str, title: str, heading: str ): """Verify that all UI pages load with the correct title and a visible heading.""" page.goto(url) expect(page).to_have_title(title) # The app uses a mix of h1 and h2 for main page headings. heading_locator = page.locator( f"h1:has-text('{heading}'), h2:has-text('{heading}')" ) expect(heading_locator.first).to_be_visible() def test_settings_theme_form_interaction(page: Page): page.goto("/theme-settings") expect(page).to_have_title("Theme Settings · CalMiner") env_rows = page.locator("#theme-env-overrides tbody tr") disabled_inputs = page.locator( "#theme-settings-form input.color-value-input[disabled]" ) env_row_count = env_rows.count() disabled_count = disabled_inputs.count() assert disabled_count == env_row_count color_input = page.locator( "#theme-settings-form input[name='--color-primary']" ) expect(color_input).to_be_visible() expect(color_input).to_be_enabled() original_value = color_input.input_value() candidate_values = ("#114455", "#225566") new_value = ( candidate_values[0] if original_value != candidate_values[0] else candidate_values[1] ) color_input.fill(new_value) page.click("#theme-settings-form button[type='submit']") feedback = page.locator("#theme-settings-feedback") expect(feedback).to_contain_text("updated successfully") computed_color = page.evaluate( "() => getComputedStyle(document.documentElement).getPropertyValue('--color-primary').trim()" ) assert computed_color.lower() == new_value.lower() page.reload() expect(color_input).to_have_value(new_value) color_input.fill(original_value) page.click("#theme-settings-form button[type='submit']") expect(feedback).to_contain_text("updated successfully") page.reload() expect(color_input).to_have_value(original_value)