|
| 1 | +import re |
| 2 | +from typing import Any, Callable, Dict |
| 3 | + |
| 4 | +from conftest import create_example_fixture |
| 5 | +from playwright.sync_api import Locator, Page, expect |
| 6 | + |
| 7 | +from shiny.playwright import controller |
| 8 | +from shiny.run import ShinyAppProc |
| 9 | + |
| 10 | +app = create_example_fixture("brand") |
| 11 | + |
| 12 | + |
| 13 | +def test_brand_yml_kitchensink(page: Page, app: ShinyAppProc) -> None: |
| 14 | + page.goto(app.url) |
| 15 | + |
| 16 | + expected_styles = { |
| 17 | + "value_box_primary": { |
| 18 | + "background-color": "rgb(111, 66, 193)", |
| 19 | + "color": "rgb(248, 248, 248)", |
| 20 | + "font-family": re.compile(r"Monda.*"), |
| 21 | + }, |
| 22 | + "value_box_secondary": { |
| 23 | + "background-color": "rgb(64, 64, 64)", |
| 24 | + "color": "rgb(248, 248, 248)", |
| 25 | + "font-family": re.compile(r"Monda.*"), |
| 26 | + }, |
| 27 | + "value_box_info": { |
| 28 | + "background-color": "rgb(23, 162, 184)", |
| 29 | + "color": "rgb(26, 26, 26)", |
| 30 | + "font-family": re.compile(r"Monda.*"), |
| 31 | + }, |
| 32 | + "switch1": { |
| 33 | + "background-color": "rgba(0, 0, 0, 0)", |
| 34 | + "color": "rgb(26, 26, 26)", |
| 35 | + "font-family": re.compile(r"Monda.*"), |
| 36 | + }, |
| 37 | + "out_text1": { |
| 38 | + "background-color": "rgb(26, 26, 26)", |
| 39 | + "color": "rgb(40, 167, 69)", |
| 40 | + "font-family": re.compile(r"Share Tech Mono.*"), |
| 41 | + }, |
| 42 | + "btn_default": { |
| 43 | + "background-color": "rgba(0, 0, 0, 0)", |
| 44 | + "color": "rgb(64, 64, 64)", |
| 45 | + "font-family": re.compile(r"Monda.*"), |
| 46 | + }, |
| 47 | + "btn_primary": { |
| 48 | + "background-color": "rgb(111, 66, 193)", |
| 49 | + "color": "rgb(248, 248, 248)", |
| 50 | + "font-family": re.compile(r"Monda.*"), |
| 51 | + }, |
| 52 | + "btn_secondary": { |
| 53 | + "background-color": "rgb(64, 64, 64)", |
| 54 | + "color": "rgb(248, 248, 248)", |
| 55 | + "font-family": re.compile(r"Monda.*"), |
| 56 | + }, |
| 57 | + "btn_success": { |
| 58 | + "background-color": "rgb(40, 167, 69)", |
| 59 | + "color": "rgb(26, 26, 26)", |
| 60 | + "font-family": re.compile(r"Monda.*"), |
| 61 | + }, |
| 62 | + "btn_danger": { |
| 63 | + "background-color": "rgb(255, 127, 80)", |
| 64 | + "color": "rgb(26, 26, 26)", |
| 65 | + "font-family": re.compile(r"Monda.*"), |
| 66 | + }, |
| 67 | + "btn_warning": { |
| 68 | + "background-color": "rgb(255, 215, 0)", |
| 69 | + "color": "rgb(26, 26, 26)", |
| 70 | + "font-family": re.compile(r"Monda.*"), |
| 71 | + }, |
| 72 | + "btn_info": { |
| 73 | + "background-color": "rgb(23, 162, 184)", |
| 74 | + "color": "rgb(26, 26, 26)", |
| 75 | + "font-family": re.compile(r"Monda.*"), |
| 76 | + }, |
| 77 | + } |
| 78 | + |
| 79 | + component_mapping = { |
| 80 | + "value_box_primary": controller.ValueBox, |
| 81 | + "value_box_secondary": controller.ValueBox, |
| 82 | + "value_box_info": controller.ValueBox, |
| 83 | + "switch1": controller.InputSwitch, |
| 84 | + "out_text1": controller.OutputText, |
| 85 | + "btn_default": controller.InputActionButton, |
| 86 | + "btn_primary": controller.InputActionButton, |
| 87 | + "btn_secondary": controller.InputActionButton, |
| 88 | + "btn_success": controller.InputActionButton, |
| 89 | + "btn_danger": controller.InputActionButton, |
| 90 | + "btn_warning": controller.InputActionButton, |
| 91 | + "btn_info": controller.InputActionButton, |
| 92 | + } |
| 93 | + |
| 94 | + locator_mapping: Dict[type[Any], Callable[[Any], Locator]] = { |
| 95 | + controller.ValueBox: lambda component: component.loc_container, |
| 96 | + controller.InputSwitch: lambda component: component.loc_label, |
| 97 | + controller.OutputText: lambda component: component.loc, |
| 98 | + controller.InputActionButton: lambda component: component.loc, |
| 99 | + } |
| 100 | + |
| 101 | + # Iterate over expected styles and perform assertions |
| 102 | + for component_name, styles in expected_styles.items(): |
| 103 | + component_class = component_mapping[component_name] |
| 104 | + component = component_class(page, component_name) |
| 105 | + locator = locator_mapping[component_class](component) |
| 106 | + for property_name, expected_value in styles.items(): |
| 107 | + expect(locator).to_have_css(property_name, expected_value) |
| 108 | + |
| 109 | + # inline-code block |
| 110 | + expect(page.get_by_text("@reactive.effect")).to_have_css( |
| 111 | + "background-color", "rgba(26, 26, 26, 0.867)" |
| 112 | + ) |
| 113 | + expect(page.get_by_text("@reactive.effect")).to_have_css( |
| 114 | + "color", "rgb(255, 215, 0)" |
| 115 | + ) |
| 116 | + expect(page.get_by_text("@reactive.effect")).to_have_css( |
| 117 | + "font-family", re.compile(r"Share Tech Mono.*") |
| 118 | + ) |
0 commit comments