0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Basic tests for admin search hook

This commit is contained in:
Ben Kerle 2015-11-05 17:28:46 +10:00 committed by Matt Westcott
parent d478f96ef6
commit 973c290e77
2 changed files with 39 additions and 0 deletions

View File

@ -3,6 +3,7 @@ from django.http import HttpResponse
from wagtail.wagtailcore import hooks
from wagtail.wagtailcore.whitelist import attribute_rule, check_url, allow_without_attributes
from wagtail.wagtailadmin.menu import MenuItem
from wagtail.wagtailadmin.search import SearchArea
# Register one hook using decorators...
@ -45,3 +46,22 @@ def register_kittens_menu_item():
attrs={'data-fluffy': 'yes'},
order=10000
)
# Admin Other Searches hook
class MyCustomSearchArea(SearchArea):
def is_shown(self, request):
return not request.GET.get('hide-option', False)
def is_active(self, request, current=None):
return request.GET.get('active-option', False)
@hooks.register('register_admin_search_area')
def register_custom_search_area():
return MyCustomSearchArea(
'My Search',
'/customsearch/',
classnames='icon icon-custom',
attrs={'is-custom': 'true'},
order=10000)

View File

@ -1419,6 +1419,25 @@ class TestPageSearch(TestCase, WagtailTestUtils):
results = response.context['pages']
self.assertTrue(any([r.slug == 'root' for r in results]))
def test_other_searches(self):
query = "Hello"
base_css = "icon icon-custom"
test_string = '<a href="/customsearch/?q=%s" class="%s" is-custom="true">My Search</a>'
# Testing the option link exists
response = self.get({'q': query})
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/pages/search.html')
self.assertTemplateUsed(response, 'wagtailadmin/shared/search_area.html')
self.assertContains(response, test_string % (query, base_css), html=True)
# Testing is_shown
response = self.get({'q': query, 'hide-option': "true"})
self.assertNotContains(response, test_string % (query, base_css), status_code=200, html=True)
# Testing is_active
response = self.get({'q': query, 'active-option': "true"})
self.assertContains(response, test_string % (query, base_css + " nolink"), status_code=200, html=True)
class TestPageMove(TestCase, WagtailTestUtils):
def setUp(self):