Skip to content

Commit

Permalink
Add Email Topic subscription list to filtered content Email Alert option
Browse files Browse the repository at this point in the history
  • Loading branch information
minhngocd committed Dec 16, 2024
1 parent d9db079 commit a18ca47
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
28 changes: 16 additions & 12 deletions app/components/email_alert_fieldset_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand All @@ -26,7 +24,8 @@ def render_filtered_content_condition_inputs
value: "CHANGE_REQUESTED",
},
],
})
}),
].compact.join.html_safe
end

def render_external_condition_inputs
Expand All @@ -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",
Expand All @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions spec/components/email_alert_fieldset_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a18ca47

Please sign in to comment.