From 2ded09a8b98515baddd145a228e198511ee4146d Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Tue, 22 Oct 2019 20:01:30 +0100 Subject: [PATCH] Fix tests broken by GOV.UK Frontend template Fix test broken by removal of GOV.UK logo image - tests/app/main/views/test_notifications.py Fix tests that ref GOV.UK template CSS files - tests/app/main/views/test_index.py Fix test broken by govuk-visually-hidden - tests/app/main/views/test_send.py Fix tests broken by header menu link -> button - tests/app/main/views/test_service_settings.py - tests/app/main/views/test_template_folders.py Fix tests broken by removing div#content - tests/app/main/views/accounts/test_choose_accounts.py - tests/app/test_navigation.py Remove references to GOV.UK CSS - tests/app/main/views/test_index.py Fix tests querying the header navigation - tests/app/test_navigation.py --- tests/app/main/views/accounts/test_choose_accounts.py | 10 +++++----- tests/app/main/views/test_index.py | 4 +--- tests/app/main/views/test_notifications.py | 5 ++--- tests/app/main/views/test_send.py | 2 +- tests/app/main/views/test_service_settings.py | 4 ++-- tests/app/main/views/test_template_folders.py | 2 +- tests/app/test_navigation.py | 6 +++--- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/tests/app/main/views/accounts/test_choose_accounts.py b/tests/app/main/views/accounts/test_choose_accounts.py index 7024ff34c..b799b063d 100644 --- a/tests/app/main/views/accounts/test_choose_accounts.py +++ b/tests/app/main/views/accounts/test_choose_accounts.py @@ -88,7 +88,7 @@ def test_choose_account_should_show_choose_accounts_page( mock_get_organisation, ): resp = client_request.get('main.choose_account') - page = resp.find('div', {'id': 'content'}).main + page = resp.find('main', {'id': 'main-content'}) assert normalize_spaces(page.h1.text) == 'Choose service' outer_list_items = page.select('nav ul')[0].select('li') @@ -144,7 +144,7 @@ def test_choose_account_should_show_choose_accounts_page_if_no_services( 'services': [] } resp = client_request.get('main.choose_account') - page = resp.find('div', {'id': 'content'}).main + page = resp.find('main', {'id': 'main-content'}) links = page.findAll('a') assert len(links) == 1 @@ -182,8 +182,8 @@ def test_choose_account_should_show_back_to_service_link( ): resp = client_request.get('main.choose_account') - page = resp.find('div', {'id': 'content'}) - back_to_service_link = page.find('div', {'class': 'navigation-service'}).a + service_navigation = resp.find('div', {'class': 'navigation-service'}) + back_to_service_link = service_navigation.a assert back_to_service_link['href'] == url_for('main.show_accounts_or_dashboard') assert back_to_service_link.text == 'Back to service one' @@ -273,7 +273,7 @@ def test_should_not_show_back_to_service_if_user_doesnt_belong_to_service( ) assert normalize_spaces( - page.select_one('#content').text + page.select_one('header + .govuk-width-container').text ).startswith( normalize_spaces(page_text) ) diff --git a/tests/app/main/views/test_index.py b/tests/app/main/views/test_index.py index 1a9e4ccf4..fb6c49956 100644 --- a/tests/app/main/views/test_index.py +++ b/tests/app/main/views/test_index.py @@ -172,10 +172,8 @@ def test_css_is_served_from_correct_path(client_request): page.select('link[rel=stylesheet]') ): assert link['href'].startswith([ - 'https://static.example.com/stylesheets/govuk-template.css?', - 'https://static.example.com/stylesheets/govuk-template-print.css?', - 'https://static.example.com/stylesheets/fonts.css?', 'https://static.example.com/stylesheets/main.css?', + 'https://static.example.com/stylesheets/print.css?', ][index]) diff --git a/tests/app/main/views/test_notifications.py b/tests/app/main/views/test_notifications.py index 3aba1d535..20be1b0f0 100644 --- a/tests/app/main/views/test_notifications.py +++ b/tests/app/main/views/test_notifications.py @@ -227,10 +227,9 @@ def test_notification_page_shows_page_for_letter_notification( letter_images = page.select('main img') assert len(letter_images) == count_of_pages - - for index in range(1, count_of_pages + 1): + for index in range(count_of_pages): assert page.select('img')[index]['src'].endswith( - '.png?page={}'.format(index) + '.png?page={}'.format(index + 1) ) assert len(mock_page_count.call_args_list) == 1 diff --git a/tests/app/main/views/test_send.py b/tests/app/main/views/test_send.py index 8846ebdca..83e8d1f14 100644 --- a/tests/app/main/views/test_send.py +++ b/tests/app/main/views/test_send.py @@ -94,7 +94,7 @@ def test_show_correct_title_and_description_for_sender_type( assert page.select_one('h1').text == expected_title - for element in ('legend', 'legend .visually-hidden'): + for element in ('legend', 'legend .govuk-visually-hidden'): assert normalize_spaces(page.select_one(element).text) == expected_description diff --git a/tests/app/main/views/test_service_settings.py b/tests/app/main/views/test_service_settings.py index ed060e80e..fd8497e5b 100644 --- a/tests/app/main/views/test_service_settings.py +++ b/tests/app/main/views/test_service_settings.py @@ -1187,8 +1187,8 @@ def test_non_gov_user_is_told_they_cant_go_live( assert normalize_spaces(page.select_one('main p').text) == ( 'Only team members with a government email address can request to go live.' ) - assert page.select('form') == [] - assert page.select('button') == [] + assert len(page.select('form')) == 0 + assert len(page.select('button')) == 1 @pytest.mark.parametrize('consent_to_research, displayed_consent', ( diff --git a/tests/app/main/views/test_template_folders.py b/tests/app/main/views/test_template_folders.py index 391292ae5..392f8e7dd 100644 --- a/tests/app/main/views/test_template_folders.py +++ b/tests/app/main/views/test_template_folders.py @@ -835,7 +835,7 @@ def test_delete_template_folder_should_request_confirmation( assert page.select_one('input[name=name]')['value'] == 'sacrifice' assert len(page.select('form')) == 2 - assert len(page.select('button')) == 2 + assert len(page.select('button')) == 3 assert 'action' not in page.select('form')[0] assert page.select('form button')[0].text == 'Yes, delete' diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index 96b1cb8ce..3f2bec8be 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -124,7 +124,7 @@ def test_a_page_should_nave_selected_header_navigation_item( selected_nav_item, ): page = client_request.get(endpoint, service_id=SERVICE_ONE_ID) - selected_nav_items = page.select('#proposition-links a.active') + selected_nav_items = page.select('.govuk-header__navigation-item--active') assert len(selected_nav_items) == 1 assert selected_nav_items[0].text.strip() == selected_nav_item @@ -179,7 +179,7 @@ def test_caseworkers_get_caseworking_navigation( return_value=active_caseworking_user(fake_uuid) ) page = client_request.get('main.choose_template', service_id=SERVICE_ONE_ID) - assert normalize_spaces(page.select_one('#content nav').text) == ( + assert normalize_spaces(page.select_one('header + .govuk-width-container nav').text) == ( 'Templates Sent messages Team members' ) @@ -197,6 +197,6 @@ def test_caseworkers_see_jobs_nav_if_jobs_exist( return_value=active_caseworking_user(fake_uuid) ) page = client_request.get('main.choose_template', service_id=SERVICE_ONE_ID) - assert normalize_spaces(page.select_one('#content nav').text) == ( + assert normalize_spaces(page.select_one('header + .govuk-width-container nav').text) == ( 'Templates Sent messages Uploads Team members' )