Skip to content

Commit 1ad11f0

Browse files
committed
Add gallery test and update options test
1 parent 83184c0 commit 1ad11f0

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed
67.7 KB
Loading

tests/fixtures/docs/gallery.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
![image-a](img.png){data-gallery="1"}
2+
3+
![image-b](img.png){data-gallery="1"}
4+
5+
![image-c](another-img.png){data-gallery="2"}
6+
7+
![image-d](another-img.png){data-gallery="2"}

tests/fixtures/mkdocs-options.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ plugins:
88
effect: fade
99
slide_effect: fade
1010
width: 80%
11-
height: 80%
11+
height: 60%
1212
zoomable: false
1313
draggable: false
14+
caption_position: right
15+
auto_caption: true

tests/test_builds.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,18 @@ def test_options(tmp_path):
337337
path = "../"
338338
validate_static(contents, path)
339339
validate_script(contents)
340+
# validate slide options
340341
regex_obj = re.search(
341-
rf'<a class="glightbox" .* href="{path}img.png"><img .* src="{path}img.png"\/><\/a>',
342+
rf'<a class="glightbox" (.*) href="{path}img.png"><img .* src="{path}img.png"\/><\/a>',
342343
contents,
343344
)
345+
assert regex_obj
346+
text = regex_obj.group(1)
347+
assert 'data-height="60%"' in text
348+
assert 'data-width="80%"' in text
349+
assert 'data-desc-position="right"' in text
344350

345-
# validate position
351+
# validate GLightbox options
346352
regex_obj = re.search(
347353
r"const lightbox = GLightbox\((.*)\);",
348354
contents,
@@ -362,6 +368,50 @@ def test_options(tmp_path):
362368
assert option in text
363369

364370

371+
def test_gallery(tmp_path):
372+
"""
373+
Validate gallery
374+
"""
375+
mkdocs_file = "mkdocs-material.yml"
376+
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
377+
file = testproject_path / "site/gallery/index.html"
378+
contents = file.read_text(encoding="utf8")
379+
path = "../"
380+
validate_static(contents, path=path)
381+
validate_script(contents)
382+
regex_obj = re.search(
383+
rf'<a class="glightbox" (.*) href="{path}img.png"><img alt="image-a" .* src="{path}img.png"\/><\/a>',
384+
contents,
385+
)
386+
assert regex_obj
387+
text = regex_obj.group(1)
388+
assert 'data-gallery="1"' in text
389+
390+
regex_obj = re.search(
391+
rf'<a class="glightbox" (.*) href="{path}img.png"><img alt="image-b" .* src="{path}img.png"\/><\/a>',
392+
contents,
393+
)
394+
assert regex_obj
395+
text = regex_obj.group(1)
396+
assert 'data-gallery="1"' in text
397+
398+
regex_obj = re.search(
399+
rf'<a class="glightbox" (.*) href="{path}another-img.png"><img alt="image-c" .* src="{path}another-img.png"\/><\/a>',
400+
contents,
401+
)
402+
assert regex_obj
403+
text = regex_obj.group(1)
404+
assert 'data-gallery="2"' in text
405+
406+
regex_obj = re.search(
407+
rf'<a class="glightbox" (.*) href="{path}another-img.png"><img alt="image-d" .* src="{path}another-img.png"\/><\/a>',
408+
contents,
409+
)
410+
assert regex_obj
411+
text = regex_obj.group(1)
412+
assert 'data-gallery="2"' in text
413+
414+
365415
def test_caption(tmp_path):
366416
"""
367417
Validate captions feature
@@ -506,3 +556,4 @@ def test_static(tmp_path):
506556
assert os.path.exists(
507557
os.path.join(testproject_path, "site/assets/javascripts/glightbox.min.js")
508558
)
559+

0 commit comments

Comments
 (0)