mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
context_processors: Use active menu urls to decide what to highlight
- We are using submenu.url to check for specific URLs and then highlight a menu item. This is somewhat incorrect due to string search and not generic enough. We have another mechanism 'active_menu_urls' to perform this. Improve and use this instead. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
3 files changed
+13
-11
No files matched your search
@@ -23,7 +23,7 @@ def test_common(Notification, load_cfg):
|
||||
"""Verify that the common() function returns the correct values."""
|
||||
|
||||
request = HttpRequest()
|
||||
request.path = '/aaa/bbb/ccc/'
|
||||
request.path = '/plinth/aaa/bbb/ccc/'
|
||||
request.user = Mock()
|
||||
request.user.groups.filter().exists = Mock(return_value=True)
|
||||
request.session = MagicMock()
|
||||
@@ -41,7 +41,7 @@ def test_common(Notification, load_cfg):
|
||||
|
||||
urls = response['active_menu_urls']
|
||||
assert urls is not None
|
||||
assert ['/', '/aaa/', '/aaa/bbb/', '/aaa/bbb/ccc/'] == urls
|
||||
assert ['/plinth/aaa/', '/plinth/aaa/bbb/', '/plinth/aaa/bbb/ccc/'] == urls
|
||||
|
||||
assert response['user_is_admin']
|
||||
|
||||
@@ -57,10 +57,10 @@ def test_common_border_conditions(Notification):
|
||||
response = cp.common(request)
|
||||
assert response['active_menu_urls'] == []
|
||||
|
||||
request.path = '/'
|
||||
request.path = '/plinth/'
|
||||
response = cp.common(request)
|
||||
assert response['active_menu_urls'] == ['/']
|
||||
assert response['active_menu_urls'] == []
|
||||
|
||||
request.path = '/aaa/bbb'
|
||||
request.path = '/plinth/aaa/bbb/ccc'
|
||||
response = cp.common(request)
|
||||
assert response['active_menu_urls'] == ['/', '/aaa/']
|
||||
assert response['active_menu_urls'] == ['/plinth/aaa/', '/plinth/aaa/bbb/']
|
||||
Reference in new issue
Block a user