Skip to content

Commit

Permalink
Add untitests for full_menu
Browse files Browse the repository at this point in the history
  • Loading branch information
153957 committed Feb 4, 2024
1 parent 2a3e2c2 commit 5daa383
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
79 changes: 79 additions & 0 deletions tests/test_full_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from pathlib import Path
from unittest import TestCase, mock

from sigal.gallery import Gallery
from sigal.settings import read_settings

from theme_153957 import full_menu


class TestFullMenu(TestCase):
def get_demo_gallery(self) -> Gallery:
demo_settings = str(Path(__file__).parent.parent / 'demo/sigal.conf.py')
settings = read_settings(demo_settings)
return Gallery(settings, ncpu=1)

def test_full_tree(self) -> None:
gallery = self.get_demo_gallery()

full_menu.full_tree(gallery)

with self.subTest('Top level albums'):
self.assertEqual(
['Long menu', 'Nine levels deep', 'Poles', 'Sequences', 'Time-Lapse'],
list(gallery.full_tree.keys()),
)

with self.subTest('Subalbums'):
self.assertEqual(
['Candle', 'Tree'],
list(gallery.full_tree['Sequences']['subalbums'].keys()),
)

with self.subTest('References to Album objects'):
self.assertEqual(gallery.albums['Poles'], gallery.full_tree['Poles']['self'])

def test_path_to_root(self) -> None:
gallery = self.get_demo_gallery()

with self.subTest('Top level', album='.'):
album = gallery.albums['.']
full_menu.path_to_root(album)
self.assertEqual('', album.path_to_root)

with self.subTest('First level subalbum', album='Poles'):
album = gallery.albums['Poles']
full_menu.path_to_root(album)
self.assertEqual('../', album.path_to_root)

with self.subTest('Over nine levels deep'):
album = gallery.albums['Nine levels deep/Limbo/Lust/Gluttony/Greed/Wrath/Heresy/Violence/Fraud/Treachery']
full_menu.path_to_root(album)
self.assertEqual('../' * 10, album.path_to_root)

def test_path_from_root(self) -> None:
gallery = self.get_demo_gallery()

with self.subTest('Top level', album='.'):
album = gallery.albums['.']
full_menu.path_from_root(album)
self.assertEqual(album.path, album.path_from_root)

with self.subTest('First level subalbum', album='Poles'):
album = gallery.albums['Poles']
full_menu.path_from_root(album)
self.assertEqual(album.path, album.path_from_root)

with self.subTest('Over nine levels deep'):
album = gallery.albums['Nine levels deep/Limbo/Lust/Gluttony/Greed/Wrath/Heresy/Violence/Fraud/Treachery']
full_menu.path_from_root(album)
self.assertEqual(album.path, album.path_from_root)


@mock.patch('theme_153957.full_menu.signals')
def test_register(self, mock_signals: mock.MagicMock) -> None:
full_menu.register({})

mock_signals.gallery_initialized.connect.assert_called_once_with(full_menu.full_tree)
mock_signals.album_initialized.connect.assert_any_call(full_menu.path_to_root)
mock_signals.album_initialized.connect.assert_any_call(full_menu.path_from_root)
4 changes: 2 additions & 2 deletions theme_153957/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
{% if album.breadcrumb|length == 0 %}
class="current_siblings"
{% else %}
{% for name, album_dict in albums.items() %}
{% for album_dict in albums.values() %}
{% if album_dict.self == album %}
class="current_siblings"
{% endif %}
{% endfor %}
{% endif %}
>
{% for name, album_dict in albums.items() %}
{% for album_dict in albums.values() %}
{% with current_ancestor=(album.breadcrumb|length and depth < album.breadcrumb|length and album_dict.self.title == album.breadcrumb[depth][1]) %}
<li class="album_title{% if album_dict.self == album %} current{% endif %}{% if current_ancestor %} current_ancestor{% endif %}">
<a href="{{ album.path_to_root|urlencode }}{{ album_dict.self.path_from_root|urlencode }}">{{ album_dict.self.title }}</a>
Expand Down

0 comments on commit 5daa383

Please sign in to comment.