|
13 | 13 |
|
14 | 14 | from django_bird.params import Param |
15 | 15 | from django_bird.params import Params |
| 16 | +from django_bird.params import Value |
16 | 17 | from django_bird.templatetags.tags.bird import END_TAG |
17 | 18 | from django_bird.templatetags.tags.bird import TAG |
18 | 19 | from django_bird.templatetags.tags.bird import BirdNode |
@@ -48,17 +49,37 @@ def test_missing_argument(self): |
48 | 49 | @pytest.mark.parametrize( |
49 | 50 | "params,expected_params", |
50 | 51 | [ |
51 | | - ("class='btn'", Params(attrs=[Param(name="class", value="btn")])), |
| 52 | + ( |
| 53 | + "class='btn'", |
| 54 | + Params(attrs=[Param(name="class", value=Value("btn", quoted=True))]), |
| 55 | + ), |
52 | 56 | ( |
53 | 57 | "class='btn' id='my-btn'", |
54 | 58 | Params( |
55 | 59 | attrs=[ |
56 | | - Param(name="class", value="btn"), |
57 | | - Param(name="id", value="my-btn"), |
| 60 | + Param(name="class", value=Value("btn", quoted=True)), |
| 61 | + Param(name="id", value=Value("my-btn", quoted=True)), |
| 62 | + ] |
| 63 | + ), |
| 64 | + ), |
| 65 | + ("disabled", Params(attrs=[Param(name="disabled", value=Value(True))])), |
| 66 | + ( |
| 67 | + "class=dynamic_class", |
| 68 | + Params( |
| 69 | + attrs=[ |
| 70 | + Param(name="class", value=Value("dynamic_class", quoted=False)) |
| 71 | + ] |
| 72 | + ), |
| 73 | + ), |
| 74 | + ( |
| 75 | + "class=item.name id=user.id", |
| 76 | + Params( |
| 77 | + attrs=[ |
| 78 | + Param(name="class", value=Value("item.name", quoted=False)), |
| 79 | + Param(name="id", value=Value("user.id", quoted=False)), |
58 | 80 | ] |
59 | 81 | ), |
60 | 82 | ), |
61 | | - ("disabled", Params(attrs=[Param(name="disabled", value=True)])), |
62 | 83 | ], |
63 | 84 | ) |
64 | 85 | def test_node_params(self, params, expected_params): |
@@ -157,6 +178,30 @@ def test_rendered_name( |
157 | 178 | {"slot": "Click me"}, |
158 | 179 | "<button>Click me</button>", |
159 | 180 | ), |
| 181 | + ( |
| 182 | + "<button {{ attrs }}>Click me</button>", |
| 183 | + "{% bird button class=dynamic_class %}Click me{% endbird %}", |
| 184 | + {"dynamic_class": "btn-primary"}, |
| 185 | + '<button class="btn-primary">Click me</button>', |
| 186 | + ), |
| 187 | + ( |
| 188 | + "<button {{ attrs }}>Click me</button>", |
| 189 | + "{% bird button class='dynamic_class' %}Click me{% endbird %}", |
| 190 | + {"dynamic_class": "btn-primary"}, |
| 191 | + '<button class="dynamic_class">Click me</button>', |
| 192 | + ), |
| 193 | + ( |
| 194 | + "<button {{ attrs }}>Click me</button>", |
| 195 | + "{% bird button class=btn.class %}Click me{% endbird %}", |
| 196 | + {"btn": {"class": "btn-success"}}, |
| 197 | + '<button class="btn-success">Click me</button>', |
| 198 | + ), |
| 199 | + ( |
| 200 | + "<button {{ attrs }}>Click me</button>", |
| 201 | + "{% bird button class='btn.class' %}Click me{% endbird %}", |
| 202 | + {"btn": {"class": "btn-success"}}, |
| 203 | + '<button class="btn.class">Click me</button>', |
| 204 | + ), |
160 | 205 | ], |
161 | 206 | ) |
162 | 207 | def test_rendered_attrs( |
@@ -305,6 +350,36 @@ def get_template_libraries(self, libraries): |
305 | 350 | {}, |
306 | 351 | '<button class="btn-primary" data-attr="button" disabled>Click me</button>', |
307 | 352 | ), |
| 353 | + ( |
| 354 | + "{% bird:prop class %}<button class='{{ props.class }}'>{{ slot }}</button>", |
| 355 | + "{% bird button class=dynamic_class %}Click me{% endbird %}", |
| 356 | + {"dynamic_class": "btn-primary"}, |
| 357 | + "<button class='btn-primary'>Click me</button>", |
| 358 | + ), |
| 359 | + ( |
| 360 | + "{% bird:prop class %}<button class='{{ props.class }}'>{{ slot }}</button>", |
| 361 | + "{% bird button class='dynamic_class' %}Click me{% endbird %}", |
| 362 | + {"dynamic_class": "btn-primary"}, |
| 363 | + "<button class='dynamic_class'>Click me</button>", |
| 364 | + ), |
| 365 | + ( |
| 366 | + "{% bird:prop class %}<button class='{{ props.class }}'>{{ slot }}</button>", |
| 367 | + "{% bird button class=btn.class %}Click me{% endbird %}", |
| 368 | + {"btn": {"class": "btn-success"}}, |
| 369 | + "<button class='btn-success'>Click me</button>", |
| 370 | + ), |
| 371 | + ( |
| 372 | + "{% bird:prop class %}<button class='{{ props.class }}'>{{ slot }}</button>", |
| 373 | + "{% bird button class='btn.class' %}Click me{% endbird %}", |
| 374 | + {"btn": {"class": "btn-success"}}, |
| 375 | + "<button class='btn.class'>Click me</button>", |
| 376 | + ), |
| 377 | + ( |
| 378 | + "{% bird:prop class='default' %}<button class='{{ props.class }}'>{{ slot }}</button>", |
| 379 | + "{% bird button class=active_class %}Click me{% endbird %}", |
| 380 | + {"active_class": "active"}, |
| 381 | + "<button class='active'>Click me</button>", |
| 382 | + ), |
308 | 383 | ], |
309 | 384 | ) |
310 | 385 | def test_with_props( |
|
0 commit comments