Skip to content

Commit

Permalink
Add FacetsIterator#user_visible_count
Browse files Browse the repository at this point in the history
This returns the total count of facets that are visible to the user,
which we need for GA4 tracking of the overall panel.
  • Loading branch information
csutter committed Oct 4, 2024
1 parent 393f4c1 commit ceef9c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/lib/facets_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ def initialize(facets)
@user_visible_facets = @facets.select(&:user_visible?)
end

def user_visible_count
@user_visible_facets.count
end

def each_with_visible_index_and_count
@facets.each do |facet|
yield facet, @user_visible_facets.index(facet), @user_visible_facets.count
yield facet, @user_visible_facets.index(facet), user_visible_count
end
end
end
6 changes: 6 additions & 0 deletions spec/lib/facets_iterator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

let(:facets) { [visible_facet, hidden_facet, another_visible_facet] }

describe "#user_visible_count" do
it "returns the count of visible facets" do
expect(facets_iterator.user_visible_count).to eq(2)
end
end

describe "#each_with_visible_index_and_count" do
it "yields each facet with its index (if visible) and the total count of visible facets" do
expect { |block| facets_iterator.each_with_visible_index_and_count(&block) }
Expand Down

0 comments on commit ceef9c9

Please sign in to comment.