Skip to content

Commit

Permalink
use dynamic value for the filter sections count
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbowen committed Oct 4, 2024
1 parent 030e35e commit 3fe3971
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions app/views/components/_filter_panel.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
panel_content_id = "filter-panel-#{id_suffix}"
button_id = "filter-button-#{id_suffix}"
result_text ||= ""
section_count ||= ""

show_reset_link ||= false
raise ArgumentError, "reset_link_href is required" if show_reset_link && !local_assigns[:reset_link_href]
Expand All @@ -31,7 +32,7 @@
section: button_text,
text: button_text,
index_section: 0,
index_section_count: 4
index_section_count: section_count
}.to_json
) { button_text } %>
Expand Down Expand Up @@ -61,7 +62,7 @@
section: button_text,
action: "search",
index_section: 0,
index_section_count: 4,
index_section_count: section_count,
}.to_json %>
<% if show_reset_link %>
Expand Down
1 change: 1 addition & 0 deletions app/views/finders/show_all_content_finder.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
open: @search_query.invalid?,
show_reset_link: filters_presenter.any_filters?,
reset_link_href: filters_presenter.reset_url,
section_count: facets.user_visible_count,
} do %>
<% facets.each_with_visible_index_and_count do |facet, index, count| %>
<%=
Expand Down
8 changes: 5 additions & 3 deletions spec/components/filter_panel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,26 @@ def render_component(locals, &block)

it "renders ga4 tracking attributes to open/close button element" do
button_text = "Filter"
section_count = 4

button_event_attributes = {
event_name: "select_content",
type: "finder",
section: button_text,
text: button_text,
index_section: 0,
index_section_count: 4,
index_section_count: section_count,
}

render_component(button_text:)
render_component(button_text:, section_count:)

assert_select ".app-c-filter-panel button[data-ga4-expandable]", true
assert_select ".app-c-filter-panel button[data-ga4-event='#{button_event_attributes.to_json}']", true
end

it "renders ga4 tracking attributes to submit button element" do
button_text = "Apply filters"
section_count = 4

button_event_attributes = {
event_name: "select_content",
Expand All @@ -108,7 +110,7 @@ def render_component(locals, &block)
index_section_count: 4,
}

render_component(button_text:)
render_component(button_text:, section_count:)

assert_select ".app-c-filter-panel__action--submit[data-ga4-event='#{button_event_attributes.to_json}']", true
end
Expand Down

0 comments on commit 3fe3971

Please sign in to comment.