From 7a780d115ed28b57c2c213da3d3aed4ebd21f09b Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 3 Mar 2020 10:50:07 +0000 Subject: [PATCH] Test that addresses display on uploads page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We didn’t have a test that checked for the first two lines of the address being displayed when rendering one-off letters on the uploads page. I double checked in the database and we store addresses in the `to` field with newlines, not commas. --- app/templates/views/dashboard/_jobs.html | 2 +- tests/app/main/views/test_uploads.py | 31 +++++++++++++++++++----- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/templates/views/dashboard/_jobs.html b/app/templates/views/dashboard/_jobs.html index dfbaedb54..cc9f84ac6 100644 --- a/app/templates/views/dashboard/_jobs.html +++ b/app/templates/views/dashboard/_jobs.html @@ -62,7 +62,7 @@ ) }} {% elif item.pdf_letter %}

- {% for line in item.recipient.split(',') %} + {% for line in item.recipient.splitlines() %} {% if loop.index < 3 %} {{ line }}
{% endif %} diff --git a/tests/app/main/views/test_uploads.py b/tests/app/main/views/test_uploads.py index c9cf333ed..943e5b205 100644 --- a/tests/app/main/views/test_uploads.py +++ b/tests/app/main/views/test_uploads.py @@ -79,13 +79,32 @@ def test_get_upload_hub_page( 'main.upload_letter', service_id=SERVICE_ONE_ID ) - assert page.find_all( - 'a', {'class': 'file-list-filename-large'} - )[0].attrs['href'] == '/services/{}/jobs/job_id_1'.format(SERVICE_ONE_ID) + uploads = page.select('tbody tr') - assert page.find_all( - 'a', {'class': 'file-list-filename-large'} - )[1].attrs['href'] == '/services/{}/notification/letter_id_1'.format(SERVICE_ONE_ID) + assert normalize_spaces(uploads[0].text.strip()) == ( + 'some.csv ' + 'Sent 1 January 2016 at 11:09am ' + '0 sending 8 delivered 2 failed' + ) + assert uploads[0].select_one('a.file-list-filename-large')['href'] == ( + '/services/{}/jobs/job_id_1'.format(SERVICE_ONE_ID) + ) + + assert normalize_spaces(uploads[1].text.strip()) == ( + 'some.pdf ' + 'Sent 1 January 2016 at 11:09am ' + 'Firstname Lastname ' + '123 Example Street' + ) + assert normalize_spaces(str(uploads[1].select_one('.govuk-body'))) == ( + '

' + 'Firstname Lastname
' + '123 Example Street
' + '

' + ) + assert uploads[1].select_one('a.file-list-filename-large')['href'] == ( + '/services/{}/notification/letter_id_1'.format(SERVICE_ONE_ID) + ) def test_get_upload_letter(client_request):