From a18ca47355fd8ca9e71f158b13fa7a4188644e01 Mon Sep 17 00:00:00 2001 From: Minno Dang Date: Fri, 13 Dec 2024 13:15:51 +0000 Subject: [PATCH] Add Email Topic subscription list to filtered content Email Alert option --- .../email_alert_fieldset_component.rb | 28 +++++++++++-------- .../email_alert_fieldset_component_spec.rb | 22 +++++++++++++++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/components/email_alert_fieldset_component.rb b/app/components/email_alert_fieldset_component.rb index 58f021a0f..c9ddd7849 100644 --- a/app/components/email_alert_fieldset_component.rb +++ b/app/components/email_alert_fieldset_component.rb @@ -4,19 +4,17 @@ def initialize(email_alert:) end def render_all_content_condition_inputs - hidden_signup_content_id_input = hidden_signup_content_id_input("all_content_signup_id") - - # Do not render the title prefix input if the value is a hash because we don't want to override the existing the existing - # values in such cases. We are going to revisit this later, but for now we only allow users to override this setting - # for finders with a single string value. Trello card for future work: https://trello.com/c/Qe8wOpaw - return hidden_signup_content_id_input if @email_alert.list_title_prefix.is_a?(Hash) - - email_topic_list_title_prefix("all_content_list_title_prefix") + hidden_signup_content_id_input + [ + render_hidden_signup_content_id_input("all_content_signup_id"), + render_email_topic_list_title_prefix("all_content_list_title_prefix"), + ].compact.join.html_safe end # We are handling changes to email facet filters offline at present. def render_filtered_content_condition_inputs - hidden_signup_content_id_input("filtered_content_signup_id") + + [ + render_hidden_signup_content_id_input("filtered_content_signup_id"), + render_email_topic_list_title_prefix("filtered_content_list_title_prefix"), render("govuk_publishing_components/components/checkboxes", { name: "email_filter_by", heading: "Selected filter: #{@email_alert.filter&.humanize}", @@ -26,7 +24,8 @@ def render_filtered_content_condition_inputs value: "CHANGE_REQUESTED", }, ], - }) + }), + ].compact.join.html_safe end def render_external_condition_inputs @@ -42,7 +41,12 @@ def render_external_condition_inputs private - def email_topic_list_title_prefix(input_name) + def render_email_topic_list_title_prefix(input_name) + # Do not render the title prefix input if the value is a hash because we don't want to override the existing the existing + # values in such cases. We are going to revisit this later, but for now we only allow users to override this setting + # for finders with a single string value. Trello card for future work: https://trello.com/c/Qe8wOpaw + return if @email_alert.list_title_prefix.is_a?(Hash) + render("govuk_publishing_components/components/input", { label: { text: "Email subscription topic", @@ -52,7 +56,7 @@ def email_topic_list_title_prefix(input_name) }) end - def hidden_signup_content_id_input(input_name) + def render_hidden_signup_content_id_input(input_name) render("govuk_publishing_components/components/input", { type: "hidden", name: input_name, diff --git a/spec/components/email_alert_fieldset_component_spec.rb b/spec/components/email_alert_fieldset_component_spec.rb index 5d305e407..43391aff8 100644 --- a/spec/components/email_alert_fieldset_component_spec.rb +++ b/spec/components/email_alert_fieldset_component_spec.rb @@ -91,4 +91,26 @@ expect(page).to have_checked_field("email_alert_type", with: "filtered_content") expect(page).to have_field("filtered_content_signup_id", with: "new-id", type: "hidden") end + + it "renders the email subscription topic if the filtered_content value is checked" do + email_alert = EmailAlert.new + email_alert.type = :filtered_content + email_alert.list_title_prefix = "Finder email subscription" + render_inline(described_class.new(email_alert:)) + + expect(page).to have_text("Email subscription topic") + expect(page).to have_field("filtered_content_list_title_prefix", with: email_alert.list_title_prefix) + end + + # We do not render the title prefix input if the value is a hash because we don't want to override the existing the existing + # values in such cases. We are going to revisit this later. Trello card for future work: https://trello.com/c/Qe8wOpaw + it "does not render the email subscription topic if the filtered_content value is checked but the current topic value is a hash" do + email_alert = EmailAlert.new + email_alert.type = :filtered_content + email_alert.list_title_prefix = {} + render_inline(described_class.new(email_alert:)) + + expect(page).not_to have_text("Email subscription topic") + expect(page).not_to have_field("filtered_content_list_title_prefix", with: email_alert.list_title_prefix) + end end