Sort selected item to the top

When you land on the page it’s good to be able to quickly see what the
currently-set value is, before you change it.

This is unnecessarily hard if the selected item is buried half way down
the page. This commit moves it to the top.
This commit is contained in:
Chris Hill-Scott
2018-11-05 13:47:31 +00:00
parent c960fef8f8
commit 43988661d6
2 changed files with 23 additions and 13 deletions

View File

@@ -788,6 +788,7 @@ class LetterBranding(StripWhitespaceForm):
self.dvla_org_id.choices = list(sorted(
choices,
key=lambda choice: (
choice[0] != kwargs.get('dvla_org_id'),
choice[0] != '001',
choice[1],
),

View File

@@ -2085,10 +2085,22 @@ def test_set_letter_branding_platform_admin_only(
assert response.status_code == 403
@pytest.mark.parametrize('current_dvla_org_id, expected_selected', [
(None, '001'),
('500', '500'),
('999', '999'),
@pytest.mark.parametrize('current_dvla_org_id, expected_selected, expected_items', [
(None, '001', (
('001', 'HM Government'),
('999', 'Animal and Plant Health Agency'),
('500', 'Land Registry'),
)),
('500', '500', (
('500', 'Land Registry'),
('001', 'HM Government'),
('999', 'Animal and Plant Health Agency'),
)),
('999', '999', (
('999', 'Animal and Plant Health Agency'),
('001', 'HM Government'),
('500', 'Land Registry'),
)),
])
def test_set_letter_branding_prepopulates(
logged_in_platform_admin_client,
@@ -2096,6 +2108,7 @@ def test_set_letter_branding_prepopulates(
mock_get_letter_email_branding,
current_dvla_org_id,
expected_selected,
expected_items,
):
if current_dvla_org_id:
service_one['dvla_organisation'] = current_dvla_org_id
@@ -2104,16 +2117,12 @@ def test_set_letter_branding_prepopulates(
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
for element in {'label', 'input[type=radio]'}:
assert len(page.select(element)) == 3
assert len(page.select(element)) == len(expected_items)
assert normalize_spaces(page.select('label')[0].text) == 'HM Government'
assert page.select('input')[0]['value'] == '001'
assert normalize_spaces(page.select('label')[1].text) == 'Animal and Plant Health Agency'
assert page.select('input')[1]['value'] == '999'
assert normalize_spaces(page.select('label')[2].text) == 'Land Registry'
assert page.select('input')[2]['value'] == '500'
for index, expected_item in enumerate(expected_items):
expected_value, expected_label = expected_item
assert normalize_spaces(page.select('label')[index].text) == expected_label
assert page.select('input')[index]['value'] == expected_value
assert len(page.select('input[checked]')) == 1
assert page.select('input[checked]')[0]['value'] == expected_selected