Skip to content

Commit

Permalink
Merge pull request #3492 from alphagov/fac-viscount
Browse files Browse the repository at this point in the history
Add `FacetsIterator#visible_count`
  • Loading branch information
csutter authored Oct 4, 2024
2 parents 393f4c1 + ceef9c9 commit a16abb6
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 a16abb6

Please sign in to comment.