()
| 2070 | |
| 2071 | |
| 2072 | def test_add_style_foreach(): |
| 2073 | class StyledComponent(Component): |
| 2074 | tag = "StyledComponent" |
| 2075 | ix: Var[int] |
| 2076 | |
| 2077 | def add_style(self): |
| 2078 | return Style({"color": "red"}) |
| 2079 | |
| 2080 | page = rx.vstack(rx.foreach(Var.range(3), lambda i: StyledComponent.create(i))) |
| 2081 | page._add_style_recursive(Style()) |
| 2082 | |
| 2083 | # Expect only a single child of the foreach on the python side |
| 2084 | assert len(page.children[0].children) == 1 |
| 2085 | |
| 2086 | # Expect the style to be added to the child of the foreach |
| 2087 | assert 'css:({ ["color"] : "red" })' in str(page.children[0].children[0]) |
| 2088 | |
| 2089 | # Expect only one instance of this CSS dict in the rendered page |
| 2090 | assert str(page).count('css:({ ["color"] : "red" })') == 1 |
| 2091 | |
| 2092 | |
| 2093 | class TriggerState(rx.State): |
nothing calls this directly
no test coverage detected