Add test coverage for configuration of autofocus

This commits adds test coverage for ther HTML in several of the forms
which had broken autofocus.

It means that if we make changes to the HTML which triggers autofocus in
the future it should be more obvious that something is depending on the
attributes being added/removed.
This commit is contained in:
Chris Hill-Scott
2021-11-04 11:28:31 +00:00
parent edd2a04c7a
commit e3089af1ef
4 changed files with 125 additions and 1 deletions

View File

@@ -164,6 +164,36 @@ def test_should_200_for_get_tour_step(
)
def test_should_show_empty_text_box(
client_request,
mock_get_service_template_with_multiple_placeholders,
service_one,
fake_uuid,
):
with client_request.session_transaction() as session:
session['placeholders'] = {'phone number': '07700 900762'}
page = client_request.get(
'main.tour_step',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
step_index=1
)
textbox = page.select_one('[data-module=autofocus][data-force-focus=True] .govuk-input')
assert 'value' not in textbox
assert textbox['name'] == 'placeholder_value'
assert textbox['class'] == [
'govuk-input', 'govuk-!-width-full',
]
# data-module=autofocus is set on a containing element so it
# shouldnt also be set on the textbox itself
assert 'data-module' not in textbox
assert normalize_spaces(
page.select_one('label[for=placeholder_value]').text
) == 'one'
def test_should_prefill_answers_for_get_tour_step(
client_request,
mock_get_service_template_with_multiple_placeholders,