-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from chosak/form-order-blocks
Alphabetically order blocks in search form
- Loading branch information
Showing
2 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
from django.db.models.fields import BLANK_CHOICE_DASH | ||
from django.test import TestCase | ||
|
||
try: | ||
from wagtail.core.models import Page, Site | ||
except ImportError: # pragma: no cover; fallback for Wagtail <2.0 | ||
from wagtail.wagtailcore.models import Page, Site | ||
|
||
from wagtailinventory.forms import PageBlockQueryForm | ||
from wagtailinventory.models import PageBlock | ||
|
||
|
||
class TestPageBlockQueryForm(TestCase): | ||
def test_no_page_blocks_in_database_form_has_blank_choice(self): | ||
form = PageBlockQueryForm() | ||
form_choices = form.fields['block'].choices | ||
|
||
self.assertEqual(len(form_choices), 1) | ||
self.assertEqual(form_choices, BLANK_CHOICE_DASH) | ||
|
||
def test_form_choices_alphabetized(self): | ||
root_page = Site.objects.get(is_default_site=True).root_page | ||
page = Page(title='Title', slug='title') | ||
root_page.add_child(instance=page) | ||
|
||
for block in ( | ||
'blocks.mango', | ||
'blocks.apple', | ||
'blocks.banana', | ||
): | ||
PageBlock.objects.create(page=page, block=block) | ||
|
||
form = PageBlockQueryForm() | ||
form_choices = form.fields['block'].choices | ||
|
||
self.assertEqual(len(form_choices), 4) | ||
self.assertEqual(form_choices[1][0], 'blocks.apple') | ||
self.assertEqual(form_choices[2][0], 'blocks.banana') | ||
self.assertEqual(form_choices[3][0], 'blocks.mango') |