Repository navigation
Expand file tree
/
Copy pathtest_codegen.py
More file actions
1969 lines (1684 loc) · 68.7 KB
/
Copy pathtest_codegen.py
File metadata and controls
1969 lines (1684 loc) · 68.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Tests for HTML code generation."""
from __future__ import annotations
import calendar
from compiler.types import jalali_to_gregorian
from tests.helpers import compile_ok
LINK = 'Link { title: "GitHub", url: "https://github.com" }'
def _html(source: str = LINK) -> str:
result = compile_ok(source)
assert result.html is not None
return result.html
class TestPageShell:
def test_doctype_and_lang(self):
html = _html()
assert html.startswith("<!DOCTYPE html>")
assert '<html lang="fa" dir="rtl">' in html
def test_default_title(self):
html = _html()
assert "<title>Linkora</title>" in html
def test_no_metadata_when_absent(self):
html = _html()
assert 'name="description"' not in html
assert 'rel="icon"' not in html
def test_page_container(self):
html = _html()
assert '<main class="lk-page">' in html
assert "</main>" in html
def test_brand_footer_fa(self):
html = _html()
assert 'class="lk-brand"' in html
assert 'href="https://github.com/Fargolnz/Linkora"' in html
assert "ساخته شده با لینکورا" in html
assert "Built With Linkora" not in html
assert "mix-blend-mode: difference" in html
assert 'viewBox="0 0 128.2367 62.1405"' in html
assert "<g fill=\"#fff\">" in html
assert "font-family: \"Vazirmatn\"" in html
assert '<span class="lk-brand-divider" aria-hidden="true"></span>' in html
assert "linear-gradient(to right, transparent, #fff, transparent)" in html
divider_pos = html.index("lk-brand-divider")
logo_pos = html.index('viewBox="0 0 128.2367 62.1405"')
assert divider_pos < logo_pos
def test_brand_footer_en(self):
html = _html('Page { language: en }\nLink { title: "GitHub", url: "https://github.com" }')
assert 'class="lk-brand"' in html
assert "Built With Linkora" in html
assert "ساخته شده با لینکورا" not in html
assert "font-family: \"Inter\"" in html
def test_brand_font_preloaded_with_theme_font(self):
html = _html(
"Theme {\n"
' PageTheme { fontFamily: inter }\n'
"}\n"
'Link { title: "GitHub", url: "https://github.com" }'
)
assert html.count('rel="stylesheet"') == 2
assert "family=Inter" in html
assert "family=Vazirmatn" in html
def test_custom_font_family_url_and_stack(self):
html = _html(
"Theme {\n"
' PageTheme { fontFamily: "Caveat" }\n'
"}\n"
'Link { title: "GitHub", url: "https://github.com" }'
)
assert "family=Caveat" in html
assert '"Caveat", -apple-system' in html
def test_styles_embedded(self):
html = _html()
assert "<style>" in html
assert ".lk-link" in html
assert ".lk-shape-rounded" in html
assert ".lk-align-center" in html
def test_unused_block_css_is_tree_shaken(self):
html = _html()
for unused in (
".lk-profile {",
".lk-connect {",
".lk-image {",
".lk-banner {",
".lk-video {",
".lk-faq {",
".lk-superlink {",
".lk-countdown {",
".lk-divider {",
):
assert unused not in html
assert ".lk-link {" in html
assert ".lk-page {" in html
def test_used_block_css_is_kept(self):
html = _html(
"Countdown { date: \"2026/12/31\", time: \"23:59\", calendar: gregorian }\n"
"Divider { style: orb }\n"
"FAQ { FAQItem { question: \"Q\", answer: \"A\" } }\n"
)
assert ".lk-countdown {" in html
assert ".lk-divider {" in html
assert ".lk-faq {" in html
assert ".lk-connect {" not in html
assert ".lk-image {" not in html
class TestPageBlock:
def test_language_en_sets_lang_and_dir(self):
html = _html('Page { language: en }\n')
assert '<html lang="en" dir="ltr">' in html
def test_title_rendered_and_escaped(self):
html = _html('Page { title: "My <Page>" }\n')
assert "<title>My <Page></title>" in html
def test_description_meta_rendered_and_escaped(self):
html = _html('Page { description: "A <b>page</b>" }\n')
assert '<meta name="description" content="A <b>page</b>">' in html
def test_favicon_link_rendered(self):
html = _html('Page { favicon: "./assets/icon.png" }\n')
assert '<link rel="icon" href="./assets/icon.png">' in html
def test_page_not_rendered_in_body(self):
html = _html('Page { title: "Secret" }\n' + LINK)
assert "<title>Secret</title>" in html
body = html.split("<body>", 1)[1]
assert "Secret" not in body
def test_language_en_flips_grid_directions(self):
html = _html(
"Page { language: en }\n"
"SocialMedia {\n"
' SocialMediaItem { service: instagram, url: "https://ig/x" }\n'
"}\n"
"Image {\n"
" ImageItem { image: \"./a.jpg\" }\n"
"}\n"
"Banner {\n"
' BannerItem { image: "./a.jpg", url: "https://example.com" }\n'
"}\n"
)
assert 'data-columns="1" data-direction="ltr"' in html
assert '<section class="lk-image lk-image-grid" data-direction="ltr">' in html
assert '<section class="lk-banner" data-direction="ltr">' in html
assert 'data-direction="rtl"' not in html
def test_language_en_sets_countdown_to_english(self):
html = _html(
"Page { language: en }\n"
'Countdown { date: "2026/12/31", time: "23:59", calendar: gregorian }\n'
)
assert ">Days</span>" in html
assert ">روز</span>" not in html
assert "data-digits=\"fa\"" not in html
def test_explicit_block_beats_page_default(self):
html = _html(
"Page { language: en }\n"
"SocialMedia {\n"
" direction: rtl\n"
' SocialMediaItem { service: instagram, url: "https://ig/x" }\n'
"}\n"
"Countdown {\n"
" language: fa\n"
' date: "2026/12/31", time: "23:59", calendar: gregorian }\n'
)
assert 'data-columns="1" data-direction="rtl"' in html
assert "data-digits=\"fa\"" in html
class TestResponsiveDesign:
def test_theme_background_variable(self):
html = _html()
assert "--lk-background: #ffffff" in html
assert "--lk-backdrop: #e0f4f4" in html
assert "background-color: var(--lk-background);" in html
assert "background-color: var(--lk-backdrop);" in html
def test_mobile_first_page(self):
html = _html()
assert "min-height: 100dvh" in html
assert "min-height: 100vh" in html
def test_desktop_media_query(self):
html = _html()
assert "@media (min-width: 600px)" in html
assert "max-width: 560px" in html
def test_floating_card_styles(self):
html = _html()
assert "border-radius: 20px" in html
assert "box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08)" in html
def test_link_touch_target(self):
html = _html()
assert "min-height: 52px" in html
def test_vazirmatn_font_loaded(self):
html = _html()
assert "https://fonts.googleapis.com/css2?family=Vazirmatn" in html
assert '"Vazirmatn"' in html
class TestLinkRendering:
def test_renders_anchor(self):
html = _html()
assert (
'<a class="lk-link lk-shape-rounded lk-align-center" '
'style="color: #FFFFFF; background-color: #00B4B0; '
'border-color: transparent;" href="https://github.com">GitHub</a>'
) in html
def test_custom_visual_properties(self):
html = _html(
'Link { title: "Portfolio", url: "https://example.com", '
'align: left, shape: pill, backgroundColor: "#3B82F6", '
'titleColor: "#000000", borderColor: "#2563EB" }'
)
assert 'class="lk-link lk-shape-pill lk-align-left"' in html
assert (
'style="color: #000000; background-color: #3B82F6; '
'border-color: #2563EB;"'
) in html
def test_multiple_links_rendered_in_order(self):
html = _html(
'Link { title: "First", url: "https://a.com" }\n'
'Link { title: "Second", url: "https://b.com" }\n'
)
first = html.index(">First</a>")
second = html.index(">Second</a>")
assert first < second
def test_html_escaping(self):
html = _html(
'Link { title: "He said \\"Hi & Bye\\"", '
'url: "https://x.com/?a=1&b=2" }'
)
assert "He said "Hi & Bye"" in html
assert 'href="https://x.com/?a=1&b=2"' in html
def test_newline_escape_rendered_as_newline(self):
html = _html(
'Link { title: "Line1\\nLine2", url: "https://x.com" }'
)
assert "Line1\nLine2" in html
class TestTitleRendering:
def test_renders_heading(self):
html = _html('Title { title: "My Links" }')
assert (
'<h2 class="lk-title" style="color: #000000; '
'text-align: center;">My Links</h2>'
) in html
def test_custom_visual_properties(self):
html = _html(
'Title { title: "Customized", align: left, titleColor: "#c7006e" }'
)
assert (
'<h2 class="lk-title" style="color: #c7006e; '
'text-align: left;">Customized</h2>'
) in html
def test_html_escaping(self):
html = _html('Title { title: "He said \\"Hi & Bye\\"" }')
assert "He said "Hi & Bye"" in html
def test_multiple_titles_rendered_in_order(self):
html = _html(
'Title { title: "First" }\n'
'Title { title: "Second" }\n'
)
first = html.index(">First</h2>")
second = html.index(">Second</h2>")
assert first < second
def test_title_css_present(self):
html = _html('Title { title: "My Links" }')
assert ".lk-title" in html
assert "font-size: 28px" in html
class TestTextRendering:
def test_renders_paragraph(self):
html = _html('Text { text: "Hello" }')
assert (
'<p class="lk-text lk-shape-rounded" '
'style="color: #000000; background-color: transparent; '
'border-color: transparent; text-align: center;">Hello</p>'
) in html
def test_custom_visual_properties(self):
html = _html(
'Text { text: "Custom", align: left, textColor: "#333333", '
'backgroundColor: "#F3F4F6", borderColor: "#2563EB", shape: pill }'
)
assert 'class="lk-text lk-shape-pill lk-text--boxed"' in html
assert (
'style="color: #333333; background-color: #F3F4F6; '
'border-color: #2563EB; text-align: left;"'
) in html
def test_html_escaping(self):
html = _html('Text { text: "He said \\"Hi & Bye\\"" }')
assert "He said "Hi & Bye"" in html
def test_multiple_texts_rendered_in_order(self):
html = _html('Text { text: "First" }\nText { text: "Second" }\n')
first = html.index(">First</p>")
second = html.index(">Second</p>")
assert first < second
def test_text_css_present(self):
html = _html('Text { text: "Hello" }')
assert ".lk-text" in html
assert "font-size: 14px" in html
def test_no_boxed_class_by_default(self):
html = _html('Text { text: "Hello", align: left }')
assert "lk-text--boxed\"" not in html
assert 'class="lk-text lk-shape-rounded"' in html
def test_boxed_class_with_background(self):
html = _html('Text { text: "Hi", backgroundColor: "#F3F4F6" }')
assert 'class="lk-text lk-shape-rounded lk-text--boxed"' in html
def test_boxed_class_with_border_only(self):
html = _html('Text { text: "Hi", borderColor: "#2563EB" }')
assert "lk-text--boxed" in html
def test_boxed_css_rule(self):
html = _html('Text { text: "Hello" }')
assert ".lk-text--boxed" in html
assert "padding: 12px 20px" in html
assert "padding: 12px 0" in html
PROFILE = (
'Profile {\n'
' Cover { image: "https://x.com/cover.jpg" }\n'
' Logo { image: "https://x.com/photo.jpg" }\n'
' Name { title: "Fargol", subtitle: "Dev" }\n'
' Bio { text: "Building things" }\n'
'}\n'
)
class TestProfileRendering:
def test_profile_section(self):
html = _html(PROFILE)
assert '<section class="lk-profile">' in html
assert "</section>" in html
def test_cover_renders_first(self):
html = _html(PROFILE)
cover_pos = html.index('<div class="lk-cover')
logo_pos = html.index('<img class="lk-logo')
assert cover_pos < logo_pos
def test_name_renders_after_logo(self):
html = _html(PROFILE)
logo_pos = html.index('<img class="lk-logo')
name_pos = html.index('<div class="lk-name')
assert logo_pos < name_pos
def test_bio_renders_last(self):
html = _html(PROFILE)
name_pos = html.index("lk-name")
bio_pos = html.index("lk-bio")
assert name_pos < bio_pos
def test_name_title_and_subtitle(self):
html = _html(PROFILE)
assert "Fargol" in html
assert "Dev" in html
assert "lk-name-title" in html
assert "lk-name-subtitle" in html
def test_logo_shape(self):
html = _html(PROFILE)
assert "lk-shape-pill" in html
def test_cover_shape(self):
html = _html(PROFILE)
assert "lk-shape-rounded" in html
def test_bio_text(self):
html = _html(PROFILE)
assert "Building things" in html
def test_bio_no_boxed_class_by_default(self):
html = _html(PROFILE)
assert "lk-bio--boxed\"" not in html
assert 'class="lk-bio lk-shape-rounded"' in html
def test_bio_boxed_class_with_background(self):
html = _html(
'Profile {\n'
' Bio { text: "Hi", backgroundColor: "#F3F4F6" }\n'
"}\n"
)
assert 'class="lk-bio lk-shape-rounded lk-bio--boxed"' in html
def test_empty_profile(self):
html = _html("Profile {}")
assert '<section class="lk-profile">' in html
SOCIAL = (
"SocialMedia {\n"
" SocialMediaItem { service: instagram, url: \"https://ig/insta\" }\n"
" SocialMediaItem { service: github, url: \"https://gh/me\" }\n"
"}\n"
)
class TestSocialMediaRendering:
def test_grid_section(self):
html = _html(SOCIAL)
assert '<section class="lk-connect"' in html
assert 'data-columns="1"' in html
def test_item_anchor(self):
html = _html(SOCIAL)
assert 'class="lk-connectitem lk-shape-rounded"' in html
assert 'href="https://ig/insta"' in html
def test_service_title_defaults_to_name(self):
html = _html(SOCIAL)
assert ">Instagram</span>" in html
assert ">GitHub</span>" in html
def test_brand_icon_present(self):
html = _html(SOCIAL)
assert 'class="lk-connectitem-icon"' in html
def test_columns_attribute(self):
html = _html(
"SocialMedia {\n"
" columns: 2\n"
" SocialMediaItem { service: x, url: \"https://x.com\" }\n"
" SocialMediaItem { service: x, url: \"https://x.com\" }\n"
"}\n"
)
assert 'data-columns="2"' in html
def test_direction_default_is_rtl(self):
html = _html(
"SocialMedia {\n"
" SocialMediaItem { service: instagram, url: \"https://ig/x\" }\n"
"}\n"
)
assert 'data-direction="rtl"' in html
def test_direction_ltr_override(self):
html = _html(
"SocialMedia {\n"
" direction: ltr\n"
" SocialMediaItem { service: instagram, url: \"https://ig/x\" }\n"
"}\n"
)
assert 'data-direction="ltr"' in html
assert 'data-direction="rtl"' not in html
def test_icon_precedes_title_in_dom(self):
html = _html(
"SocialMedia {\n"
" SocialMediaItem { service: instagram, url: \"https://ig/x\" }\n"
"}\n"
)
assert html.index('class="lk-connectitem-icon"') < html.index(">Instagram</span>")
def test_no_icon_position_class_emitted(self):
html = _html(
"SocialMedia {\n"
" direction: ltr\n"
" SocialMediaItem { service: instagram, url: \"https://ig/x\" }\n"
"}\n"
)
assert "lk-icon-" not in html
def test_items_flex_row_default(self):
html = _html(SOCIAL)
assert "flex-direction: row-reverse" not in html
assert ".lk-connectitem {" in html
def test_css_styles_present(self):
html = _html(SOCIAL)
assert ".lk-connectitem" in html
assert "flex-basis: calc((100% - 24px) / 3)" in html
def test_partial_last_row_is_centered(self):
html = _html(SOCIAL)
assert "display: flex;" in html
assert "flex-wrap: wrap;" in html
assert "justify-content: center;" in html
assert "display: grid;" not in html
assert "grid-template-columns" not in html
for columns, basis in (
(1, "100%"),
(2, "calc((100% - 12px) / 2)"),
(3, "calc((100% - 24px) / 3)"),
(4, "calc((100% - 36px) / 4)"),
):
assert f"flex-basis: {basis}" in html
def test_item_shrinks_in_narrow_grid(self):
html = _html(SOCIAL)
assert "min-width: 0" in html
assert "text-overflow: ellipsis" in html
assert "white-space: nowrap" in html
def test_instagram_icon_uses_gradient_fill(self):
html = _html(SOCIAL)
assert "linearGradient" in html
assert 'fill="url(#ig)"' in html
def test_brand_icons_use_exact_brand_hex(self):
html = _html(
"SocialMedia {\n"
" SocialMediaItem { service: github, url: \"https://gh/me\" }\n"
" SocialMediaItem { service: pinterest, url: \"https://pin/x\" }\n"
" SocialMediaItem { service: telegram, url: \"https://t/x\" }\n"
"}\n"
)
assert 'fill="#181717"' in html # GitHub
assert 'fill="#BD081C"' in html # Pinterest
assert 'fill="#26A5E4"' in html # Telegram
def test_icon_color_recolors_gradient_and_flat_fills(self):
html = _html(
"SocialMedia {\n"
" iconColor: \"#123456\"\n"
" SocialMediaItem { service: instagram, url: \"https://ig/x\" }\n"
" SocialMediaItem { service: github, url: \"https://gh/me\" }\n"
"}\n"
)
assert 'stop-color="#123456"' in html # Instagram gradient stops
assert 'fill="url(#ig)"' in html # gradient fill reference preserved
assert 'fill="#123456"' in html # GitHub flat fill recolored
SOCIAL_NETWORK = (
"SocialNetwork {\n"
" SocialNetworkItem { service: whatsapp, url: \"https://wa.me/1\" }\n"
" SocialNetworkItem { service: discord, url: \"https://discord.gg/x\" }\n"
"}\n"
)
class TestSocialNetworkRendering:
def test_grid_section(self):
html = _html(SOCIAL_NETWORK)
assert '<section class="lk-connect"' in html
assert 'data-columns="1"' in html
def test_item_anchor(self):
html = _html(SOCIAL_NETWORK)
assert 'class="lk-connectitem lk-shape-rounded"' in html
assert 'href="https://wa.me/1"' in html
def test_service_title_defaults_to_name(self):
html = _html(SOCIAL_NETWORK)
assert ">WhatsApp</span>" in html
assert ">Discord</span>" in html
def test_brand_icon_present(self):
html = _html(SOCIAL_NETWORK)
assert 'class="lk-connectitem-icon"' in html
def test_icon_precedes_title_and_no_icon_class(self):
html = _html(SOCIAL_NETWORK)
assert html.index('class="lk-connectitem-icon"') < html.index(">WhatsApp</span>")
assert "lk-icon-" not in html
def test_columns_attribute(self):
html = _html(
"SocialNetwork {\n"
" columns: 2\n"
" SocialNetworkItem { service: telegram, url: \"https://t.me/x\" }\n"
" SocialNetworkItem { service: telegram, url: \"https://t.me/y\" }\n"
"}\n"
)
assert 'data-columns="2"' in html
def test_direction_default_is_rtl(self):
html = _html(
"SocialNetwork {\n"
" SocialNetworkItem { service: whatsapp, url: \"https://wa.me/1\" }\n"
"}\n"
)
assert 'data-direction="rtl"' in html
def test_direction_ltr_override(self):
html = _html(
"SocialNetwork {\n"
" direction: ltr\n"
" SocialNetworkItem { service: whatsapp, url: \"https://wa.me/1\" }\n"
"}\n"
)
assert 'data-direction="ltr"' in html
assert 'data-direction="rtl"' not in html
def test_css_styles_present(self):
html = _html(SOCIAL_NETWORK)
assert ".lk-connectitem" in html
assert "flex-basis: calc((100% - 24px) / 3)" in html
def test_item_shrinks_in_narrow_grid(self):
html = _html(SOCIAL_NETWORK)
assert "min-width: 0" in html
assert "text-overflow: ellipsis" in html
def test_brand_icons_use_exact_brand_hex(self):
html = _html(
"SocialNetwork {\n"
" SocialNetworkItem { service: telegram, url: \"https://t.me/x\" }\n"
" SocialNetworkItem { service: whatsapp, url: \"https://wa.me/1\" }\n"
" SocialNetworkItem { service: discord, url: \"https://d.gg/x\" }\n"
"}\n"
)
assert 'fill="#0088CC"' in html # Telegram
assert 'fill="#25D366"' in html # WhatsApp
assert 'fill="#5865F2"' in html # Discord
def test_new_network_service_brand_hexes(self):
html = _html(
"SocialNetwork {\n"
" SocialNetworkItem { service: bale, url: \"https://ble.ir/x\" }\n"
" SocialNetworkItem { service: eitaa, url: \"https://eitaa.com/x\" }\n"
" SocialNetworkItem { service: rubika, url: \"https://rubika.ir/x\" }\n"
" SocialNetworkItem { service: soroushPlus, url: \"https://splus.ir/x\" }\n"
"}\n"
)
assert 'fill="#0ACA9B"' in html # Bale
assert 'fill="#ee7f22"' in html # Eitaa
assert 'fill="#49BDCA"' in html # Rubika
assert 'fill="#0F68A0"' in html # Rubika
assert 'fill="#196FF0"' in html # Soroush Plus
def test_default_title_color_is_3b3b3b(self):
html = _html(SOCIAL_NETWORK)
assert "color: #3B3B3B" in html
CONTACT = (
"Contact {\n"
" ContactItem { service: email, value: \"hi@example.com\" }\n"
" ContactItem { service: mobile, value: \"+1 234 567 8901\" }\n"
"}\n"
)
class TestContactRendering:
def test_grid_section(self):
html = _html(CONTACT)
assert '<section class="lk-connect"' in html
assert 'data-columns="1"' in html
def test_item_anchor(self):
html = _html(CONTACT)
assert 'class="lk-connectitem lk-shape-rounded"' in html
def test_title_defaults_to_service_name(self):
html = _html(CONTACT)
assert ">Email</span>" in html
assert ">Mobile</span>" in html
def test_icon_present(self):
html = _html(CONTACT)
assert 'class="lk-connectitem-icon"' in html
def test_icon_precedes_title_and_no_icon_class(self):
html = _html(CONTACT)
assert html.index('class="lk-connectitem-icon"') < html.index(">Email</span>")
assert "lk-icon-" not in html
def test_columns_attribute(self):
html = _html(
"Contact {\n"
" columns: 2\n"
" ContactItem { service: email, value: \"hi@example.com\" }\n"
" ContactItem { service: mobile, value: \"+1 234 567 8901\" }\n"
"}\n"
)
assert 'data-columns="2"' in html
def test_direction_default_is_rtl(self):
html = _html(
"Contact {\n"
" ContactItem { service: email, value: \"hi@example.com\" }\n"
"}\n"
)
assert 'data-direction="rtl"' in html
def test_direction_ltr_override(self):
html = _html(
"Contact {\n"
" direction: ltr\n"
" ContactItem { service: email, value: \"hi@example.com\" }\n"
"}\n"
)
assert 'data-direction="ltr"' in html
assert 'data-direction="rtl"' not in html
def test_css_styles_present(self):
html = _html(CONTACT)
assert ".lk-connectitem" in html
def test_href_mailto(self):
html = _html(
"Contact {\n"
" ContactItem { service: email, value: \"hi@example.com\" }\n"
"}\n"
)
assert 'href="mailto:hi@example.com"' in html
def test_href_tel(self):
html = _html(
"Contact {\n"
" ContactItem { service: mobile, value: \"+1 234 567 8901\" }\n"
"}\n"
)
assert 'href="tel:+1 234 567 8901"' in html
def test_href_sms(self):
html = _html(
"Contact {\n"
" ContactItem { service: sms, value: \"+1 234 567 8901\" }\n"
"}\n"
)
assert 'href="sms:+1 234 567 8901"' in html
def test_href_website_with_scheme(self):
html = _html(
"Contact {\n"
" ContactItem { service: website, value: \"https://example.com\" }\n"
"}\n"
)
assert 'href="https://example.com"' in html
def test_href_website_without_scheme(self):
html = _html(
"Contact {\n"
" ContactItem { service: website, value: \"example.org\" }\n"
"}\n"
)
assert 'href="https://example.org"' in html
def test_default_title_color_is_00b4b0(self):
html = _html(CONTACT)
assert "color: #00B4B0" in html
def test_icon_color_recolors_contact_icons(self):
html = _html(
"Contact {\n"
" iconColor: \"#123456\"\n"
" ContactItem { service: email, value: \"hi@example.com\" }\n"
" ContactItem { service: mobile, value: \"+1 234 567 8901\" }\n"
"}\n"
)
assert 'fill="#123456"' in html
assert 'fill="#00B4B0"' not in html
ADDRESS = (
"Address {\n"
" AddressItem { service: googleMap, url: \"https://maps.google.com/?q=T\" }\n"
" AddressItem { service: waze, url: \"https://waze.com/ul?q=T\" }\n"
"}\n"
)
class TestAddressRendering:
def test_grid_section(self):
html = _html(ADDRESS)
assert '<section class="lk-connect"' in html
assert 'data-columns="1"' in html
def test_direction_default_is_rtl(self):
html = _html(
"Address {\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
"}\n"
)
assert 'data-direction="rtl"' in html
def test_direction_ltr_override(self):
html = _html(
"Address {\n"
" direction: ltr\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
"}\n"
)
assert 'data-direction="ltr"' in html
assert 'data-direction="rtl"' not in html
def test_item_anchor_with_url_href(self):
html = _html(ADDRESS)
assert 'href="https://maps.google.com/?q=T"' in html
assert 'href="https://waze.com/ul?q=T"' in html
def test_title_defaults_to_service_name(self):
html = _html(ADDRESS)
assert ">Google Maps</span>" in html
assert ">Waze</span>" in html
def test_icon_present_with_brand_hexes(self):
html = _html(ADDRESS)
assert 'class="lk-connectitem-icon"' in html
assert 'fill="#ea4335"' in html
assert 'fill="#33CCFF"' in html
def test_icon_precedes_title_and_no_icon_class(self):
html = _html(ADDRESS)
assert html.index('class="lk-connectitem-icon"') < html.index(">Google Maps</span>")
assert "lk-icon-" not in html
def test_all_service_brand_hexes(self):
html = _html(
"Address {\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
" AddressItem { service: waze, url: \"https://w/x\" }\n"
" AddressItem { service: neshan, url: \"https://n/x\" }\n"
" AddressItem { service: balad, url: \"https://b/x\" }\n"
"}\n"
)
assert 'fill="#ea4335"' in html
assert 'fill="#33CCFF"' in html
assert 'fill="#10b990"' in html
assert 'fill="#7868f6"' in html
def test_default_background_is_per_service_shade(self):
html = _html(ADDRESS)
assert "background-color: #E8F0FE" in html
assert "background-color: #E5F6FC" in html
def test_default_border_is_transparent(self):
html = _html(ADDRESS)
assert "border-color: transparent" in html
def test_default_title_color_is_3b3b3b(self):
html = _html(ADDRESS)
assert "color: #3B3B3B" in html
def test_address_caption_rendered(self):
html = _html(
"Address {\n"
" address: \"Tehran, Iran\"\n"
" addressColor: \"#111111\"\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
"}\n"
)
assert "Tehran, Iran" in html
assert "color: #111111" in html
def test_no_caption_when_address_empty(self):
html = _html(ADDRESS)
assert "Tehran, Iran" not in html
def test_caption_align_defaults_to_center(self):
html = _html(
"Address {\n"
" address: \"Tehran, Iran\"\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
"}\n"
)
assert "text-align: center" in html
def test_caption_align_left(self):
html = _html(
"Address {\n"
" address: \"Tehran, Iran\"\n"
" align: left\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
"}\n"
)
assert "text-align: left" in html
def test_caption_align_right(self):
html = _html(
"Address {\n"
" address: \"Tehran, Iran\"\n"
" align: right\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
"}\n"
)
assert "text-align: right" in html
def test_icon_color_recolors_address_icons(self):
html = _html(
"Address {\n"
" iconColor: \"#123456\"\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
"}\n"
)
assert 'fill="#123456"' in html
assert 'fill="#ea4335"' not in html
def test_tinted_soroush_clears_light_fills(self):
html = _html(
"SocialNetwork {\n"
" iconColor: \"#111111\"\n"
" SocialNetworkItem { service: soroushPlus, url: \"https://splus.ir/x\" }\n"
"}\n"
)
assert 'fill="#111111"' in html
assert 'fill="#FEFEFE"' not in html
assert html.count('fill="none"') == 2
def test_tinted_balad_uses_simplified_mark(self):
html = _html(
"Address {\n"
" iconColor: \"#111111\"\n"
" AddressItem { service: balad, url: \"https://b/x\" }\n"
"}\n"
)
assert 'fill="#111111"' in html
assert 'fill="#241957"' not in html
assert 'fill="#7868f6"' not in html
assert 'fill="#f8d748"' not in html
assert 'fill="#ef8b32"' not in html
assert '<path fill="#fff"' not in html
assert 'fill="none"' not in html
def test_tinted_rubika_clears_light_fills(self):
html = _html(
"SocialNetwork {\n"
" iconColor: \"#111111\"\n"
" SocialNetworkItem { service: rubika, url: \"https://rubika.ir/x\" }\n"
"}\n"
)
assert 'fill="#111111"' in html
assert 'fill="#E4E4E4"' not in html
assert 'fill="#F1F1F1"' not in html
assert 'fill="none"' in html
def test_item_color_inheritance(self):
html = _html(
"Address {\n"
" titleColor: \"#FF0000\"\n"
" backgroundColor: \"#EEEEEE\"\n"
" AddressItem { service: googleMap, url: \"https://g/x\" }\n"
"}\n"
)
assert "color: #FF0000" in html
assert "background-color: #EEEEEE" in html
class TestImageRendering:
SRC = (
"Image {\n"
" ImageItem { image: \"./assets/one.jpg\" }\n"
" ImageItem { image: \"./assets/two.jpg\", title: \"Two\" }\n"
"}\n"
)
def test_grid_section_and_rows(self):
html = _html(self.SRC)
assert '<section class="lk-image lk-image-grid" data-direction="rtl">' in html
assert 'class="lk-image-row"' in html
def test_direction_default_is_rtl(self):
html = _html(self.SRC)
assert '<section class="lk-image lk-image-grid" data-direction="rtl">' in html
assert 'data-direction="ltr"' not in html
def test_direction_ltr_override(self):
html = _html(
"Image {\n"
" direction: ltr\n"
" ImageItem { image: \"./a.jpg\" }\n"
"}\n"
)
assert '<section class="lk-image lk-image-grid" data-direction="ltr">' in html
assert 'data-direction="rtl"' not in html
def test_direction_ignored_in_slider_mode(self):
html = _html(
"Image {\n"
" displayMode: slider\n"
" direction: ltr\n"
" ImageItem { image: \"./a.jpg\" }\n"
"}\n"