Skip to content

Commit 205839d

Browse files
authored
Merge pull request #643 from alphagov/add_test_sending_a_file_one_off_via_document_download_via_ui
Add test sending a file one off via document download via UI
2 parents 71ca5a8 + 555641e commit 205839d

2 files changed

Lines changed: 164 additions & 1 deletion

File tree

tests/notifications/functional_tests/test_document_download_via_ui.py

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
import uuid
22

3-
from tests.pages import ManageFilesForEmailTemplatePage, ShowTemplatesPage, ViewEmailTemplatePage
3+
import pytest
4+
5+
from config import config
6+
from tests.pages import (
7+
ChangeLinkTextForEmailFilePage,
8+
DocumentDownloadLandingPage,
9+
ManageEmailTemplateFilePage,
10+
ManageFilesForEmailTemplatePage,
11+
SendEmailPreviewPage,
12+
SendOneRecipientPage,
13+
SendSetSenderPage,
14+
SentEmailMessagePage,
15+
ShowTemplatesPage,
16+
ViewEmailTemplatePage,
17+
)
418
from tests.test_utils import (
519
create_an_email_template_and_attach_a_file,
620
delete_file_from_email_template_via_manage_files_page,
@@ -9,6 +23,7 @@
923

1024

1125
@recordtime
26+
@pytest.mark.xdist_group(name="send-files-via-ui-flow")
1227
def test_attaching_files_to_emails_and_also_deleting_them_via_ui(driver, login_seeded_user):
1328
# Test Creating an email template and attach a file to it
1429
template_name = f"Functional Tests - upload/delete file to email template - {uuid.uuid4()}"
@@ -41,3 +56,86 @@ def test_attaching_files_to_emails_and_also_deleting_them_via_ui(driver, login_s
4156
templates_page = ShowTemplatesPage(driver)
4257
assert templates_page.get_h1_text() == "Templates"
4358
assert template_name not in templates_page.get_all_listed_templates()
59+
60+
61+
@recordtime
62+
@pytest.mark.xdist_group(name="send-files-via-ui-flow")
63+
def test_send_one_off_email_with_file_via_ui(driver, login_seeded_user):
64+
# Create an email template
65+
template_name = f"Functional Tests - send one off email with file via ui - {uuid.uuid4()}"
66+
content = "Testing sending a one off email notification. with an email file. Test file below:"
67+
file_name = "attachment.pdf"
68+
create_an_email_template_and_attach_a_file(driver, file_name, template_name, content)
69+
70+
# Confirm file has been attached to template on the Preview email template page
71+
view_email_template_page = ViewEmailTemplatePage(driver)
72+
assert view_email_template_page.get_h1_text() == template_name
73+
assert view_email_template_page.get_file_added_count_text() == "1 file added"
74+
75+
# go to the individual file management page and change the link text
76+
view_email_template_page.click_manage_files_button()
77+
manage_files_page = ManageFilesForEmailTemplatePage(driver)
78+
assert manage_files_page.get_h1_text() == "Manage files"
79+
link_text_label = "Link text"
80+
link_text = "file_download_link"
81+
manage_files_page.click_manage_link(file_name)
82+
manage_file_page = ManageEmailTemplateFilePage(driver)
83+
assert manage_file_page.get_h1_text() == file_name
84+
manage_file_page.click_change_file_setting(link_text_label)
85+
change_link_text_page = ChangeLinkTextForEmailFilePage(driver)
86+
assert change_link_text_page.get_h1_text() == "Add link text"
87+
change_link_text_page.fill_in_link_text(link_text)
88+
change_link_text_page.click_continue_button()
89+
90+
manage_file_page.click_back_link()
91+
assert manage_file_page.get_h1_text() == "Manage files"
92+
manage_file_page.click_back_link()
93+
94+
# send the email
95+
assert view_email_template_page.get_h1_text() == template_name
96+
assert link_text in view_email_template_page.get_email_message_body_content()
97+
view_email_template_page.click_send()
98+
99+
set_sender_page = SendSetSenderPage(driver)
100+
set_sender_page.wait_until_current()
101+
assert set_sender_page.get_h1_text() == "Where should replies come back to?"
102+
set_sender_page.click_continue_button()
103+
104+
send_to_one_recipient_page = SendOneRecipientPage(driver)
105+
assert send_to_one_recipient_page.get_h1_text() == f"Send ‘{template_name}’"
106+
send_to_one_recipient_page.send_to_myself("email")
107+
108+
preview_send_one_recepient_page = SendEmailPreviewPage(driver)
109+
assert preview_send_one_recepient_page.get_h1_text() == f"Preview of ‘{template_name}’"
110+
preview_send_one_recepient_page.click_send_button()
111+
112+
# confirm that the email is being delivered
113+
send_email_confirmation_page = SentEmailMessagePage(driver)
114+
assert send_email_confirmation_page.get_h1_text() == "Email"
115+
assert "Delivering" in send_email_confirmation_page.get_notification_status()
116+
117+
# Confirm that the file download link sent to the recipient works
118+
# There are smoke tests and other tests covering the process of a recipient downloading
119+
# a document, so the whole journey will not be covered here
120+
send_email_confirmation_page.click_file_download_link(link_text)
121+
you_have_a_file_to_download_page = DocumentDownloadLandingPage(driver)
122+
assert you_have_a_file_to_download_page.get_h1_text() == "You have a file to download"
123+
you_have_a_file_to_download_page.go_to_download_page()
124+
125+
# Go to service templates page and select the template
126+
base_url = config["notify_admin_url"]
127+
service_template_page_url = f"{base_url}/services/{config['service']['id']}/templates"
128+
you_have_a_file_to_download_page.get(service_template_page_url)
129+
templates_pages = ShowTemplatesPage(driver)
130+
assert templates_pages.get_h1_text() == "Templates"
131+
templates_pages.click_template_by_link_text(template_name)
132+
133+
# delete the template
134+
assert view_email_template_page.get_h1_text() == template_name
135+
view_email_template_page.click_delete_template_link()
136+
view_email_template_page.click_template_deletion_confirmation_button()
137+
138+
# confirm template has been deleted
139+
templates_page = ShowTemplatesPage(driver)
140+
assert templates_page.get_h1_text() == "Templates"
141+
assert template_name not in templates_page.get_all_listed_templates()

tests/pages/pages.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class BasePage:
133133
sign_out_link = NavigationLocators.SIGN_OUT_LINK
134134
profile_page_link = NavigationLocators.PROFILE_LINK
135135
h1_text = (By.CSS_SELECTOR, "h1")
136+
templates_link = NavigationLocators.TEMPLATES_LINK
136137

137138
def __init__(self, driver):
138139
self.base_url = config["notify_admin_url"]
@@ -881,6 +882,7 @@ class ViewEmailTemplatePage(ViewTemplatePage):
881882
page_banner_text = ViewEmailTemplatePageLocators.PAGE_BANNER_TEXT
882883
delete_template_link = ViewEmailTemplatePageLocators.DELETE_TEMPLATE_LINK
883884
template_deletion_confirmation_button = ViewEmailTemplatePageLocators.TEMPLATE_DELETION_CONFIRMATION_BUTTON
885+
email_message_body_content = (By.XPATH, "//div[contains(@class, 'email-message-body')]")
884886

885887
def click_attach_files_button(self):
886888
element = self.wait_for_element(ViewEmailTemplatePage.attach_files_button)
@@ -906,6 +908,10 @@ def click_template_deletion_confirmation_button(self):
906908
element = self.wait_for_element(ViewEmailTemplatePage.template_deletion_confirmation_button)
907909
element.click()
908910

911+
def get_email_message_body_content(self):
912+
element = self.wait_for_element(ViewEmailTemplatePage.email_message_body_content)
913+
return element.text.strip()
914+
909915

910916
class AddFileToEmailTemplatePage(BasePage):
911917
choose_file_button = AddFileToEmailTemplatePageLocators.CHOOSE_FILE_BUTTON
@@ -930,6 +936,10 @@ class ManageEmailTemplateFilePage(BasePage):
930936
file_link = ManageEmailTemplateFilePageLocators.REMOVE_FILE_LINK
931937
add_to_template = ManageEmailTemplateFilePageLocators.ADD_TO_TEMPLATE_BUTTON
932938
remove_file_dialog_button = ManageEmailTemplateFilePageLocators.REMOVE_FILE_DIALOG_BUTTON
939+
change_link_text_change = (
940+
By.XPATH,
941+
"//div[contains(@class, 'govuk-summary-list__row')][dt[contains(., 'Link text')]]//a[contains(., 'Change')]",
942+
)
933943

934944
def click_remove_file_link(self):
935945
element = self.wait_for_element(ManageEmailTemplateFilePage.file_link)
@@ -943,6 +953,26 @@ def click_remove_file_dialog_button(self):
943953
element = self.wait_for_element(ManageEmailTemplateFilePage.remove_file_dialog_button)
944954
element.click()
945955

956+
def click_change_file_setting(self, label):
957+
xpath = (
958+
f"//div[contains(@class, 'govuk-summary-list__row')][dt[contains(., '{label}')]]//a[contains(., 'Change')]"
959+
)
960+
element = self.wait_for_element((By.XPATH, xpath))
961+
element.click()
962+
963+
964+
class ChangeLinkTextForEmailFilePage(BasePage):
965+
link_text_input = (By.CSS_SELECTOR, "input[name='link_text'][id='link_text']")
966+
continue_button = (By.CSS_SELECTOR, "button[type='submit']")
967+
968+
def click_continue_button(self):
969+
element = self.wait_for_element(ChangeLinkTextForEmailFilePage.continue_button)
970+
element.click()
971+
972+
def fill_in_link_text(self, value):
973+
element = self.wait_for_element(ChangeLinkTextForEmailFilePage.link_text_input)
974+
element.send_keys(value)
975+
946976

947977
class ManageFilesForEmailTemplatePage(BasePage):
948978
def click_manage_link(self, file_name):
@@ -1454,6 +1484,7 @@ class SendSetSenderPage(BasePage):
14541484
By.XPATH,
14551485
"//label[normalize-space(text())='func tests']/preceding-sibling::input[@type='radio']",
14561486
)
1487+
continue_button = (By.CSS_SELECTOR, "button[type='submit']")
14571488

14581489
def wait_until_current(self, time=10):
14591490
return self.wait_until_url_matches(r"/set-sender(\?.*)?$", time=time)
@@ -1469,6 +1500,10 @@ def choose_alternative_sms_sender(self):
14691500
radio = self.wait_for_design_system_checkbox_or_radio(self.alternative_sender_sms_radio)
14701501
radio.click()
14711502

1503+
def click_continue_button(self):
1504+
element = self.wait_for_element(SendSetSenderPage.continue_button)
1505+
element.click()
1506+
14721507

14731508
class SendOneRecipientPage(BasePage):
14741509
def is_placeholder_a_recipient_field(self, message_type):
@@ -1510,6 +1545,36 @@ def click_use_emergency_list(self):
15101545
element.click()
15111546

15121547

1548+
class SendEmailPreviewPage(BasePage):
1549+
"""
1550+
The send file via ui journey slightly differs from the usual one-off email journey
1551+
hence the need for this separate class
1552+
"""
1553+
1554+
send_button = (By.CSS_SELECTOR, "button[type='submit'")
1555+
1556+
def click_send_button(self):
1557+
element = self.wait_for_element(SendEmailPreviewPage.send_button)
1558+
element.click()
1559+
1560+
1561+
class SentEmailMessagePage(BasePage):
1562+
"""
1563+
The send file via ui journey slightly differs from the usual one-off email journey
1564+
hence the need for this separate class
1565+
"""
1566+
1567+
notification_status = (By.XPATH, "//p[contains(@class, 'notification-status')]")
1568+
1569+
def get_notification_status(self):
1570+
element = self.wait_for_element(SentEmailMessagePage.notification_status)
1571+
return element.get_attribute("textContent").strip()
1572+
1573+
def click_file_download_link(self, link_text):
1574+
element = self.wait_for_element((By.XPATH, f"//a[contains(., '{link_text}')]"))
1575+
element.click()
1576+
1577+
15131578
class SendChooseContactListPage(PageWithUploadsList):
15141579
def get_contact_list_info(self, contact_list_id):
15151580
link_element = self.wait_for_element((By.CSS_SELECTOR, f"a[href*='/from-contact-list/{contact_list_id}']"))

0 commit comments

Comments
 (0)