Skip to content

Commit

Permalink
adds each to SearchOptions; moves show_optgroups to SearchOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Feb 21, 2025
1 parent 6d5ad90 commit a148efd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 24 deletions.
34 changes: 20 additions & 14 deletions lib/search/presenters/search_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,10 @@ def base_options
end
end

def show_optgroups?
# check if more than one group
options.count > 1
end

def default_option
# get first option
base_options.first
end

# def selected_option
# # select option on load
# end

# def search_only
# # grab only `search` group options (used in advanced search)
# end
end

class SearchOptions
Expand All @@ -95,10 +82,29 @@ def base_search_options
ALL_BASE_SEARCH_OPTIONS.find { |x| x.datastore == @datastore_slug }
end

def options
if search_only?
[base_search_options.options.first]
else
base_search_options.options
end
end

def each(&block)
options.each do |group|
block.call(group)
end
end

def show_optgroups?
# check if more than one group
options.count > 1
end

# select option on load
def selected_option
my_option = base_search_options.default_option
base_options = base_search_options.base_options
my_option = base_options.first

full_option_value_from_query = params["query"]
option_value_from_query = full_option_value_from_query&.split(":(")&.first
Expand Down
43 changes: 33 additions & 10 deletions spec/presenters/search_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,39 @@
expect(subject.search_only?).to eq(true)
end
end
context "options" do
it "returns multiple opt groups when not search only" do
@datastore_slug = "catalog"
expect(subject.options.count).to eq(2)
end
it "returns only one opt group when search only" do
@uri = URI.parse("/catalog/advanced")
@datastore_slug = "catalog"
expect(subject.options.count).to eq(1)
end
end
context "#show_optgroups?" do
it "is true when there is more than one opt group" do
@datastore_slug = "catalog"
expect(subject.show_optgroups?).to eq(true)
end
it "is false when there is only one opt group" do
@uri = URI.parse("/catalog/advanced")
@datastore_slug = "catalog"
expect(subject.show_optgroups?).to eq(false)
end
end

context "#each" do
it "iterates over the options" do
output = nil
subject.each do |group|
output = group.optgroup
end

expect(output).to eq("search")
end
end
end
RSpec.describe Search::Presenters::BaseSearchOptions do
before(:each) do
Expand Down Expand Up @@ -60,16 +93,6 @@
end
end

context "#show_optgroups?" do
it "is true when there is more than one opt group" do
@slug = "catalog"
expect(subject.show_optgroups?).to eq(true)
end
it "is false when there is only one opt group" do
expect(subject.show_optgroups?).to eq(false)
end
end

# context "#datastore_search_options" do
# it "lists search options specific to the datastore" do
# expect(described_class.new.datastore_search_options).to include("...")
Expand Down

0 comments on commit a148efd

Please sign in to comment.