diff --git a/app/views/admin/products_v3/_filters.html.haml b/app/views/admin/products_v3/_filters.html.haml index b63eb23936..8040365c3e 100644 --- a/app/views/admin/products_v3/_filters.html.haml +++ b/app/views/admin/products_v3/_filters.html.haml @@ -2,9 +2,10 @@ .query .search-input = text_field_tag :search_term, search_term, placeholder: t('.search_products') - .producers - .label= t('.producers.label') - = select_tag :producer_id, options_for_select(producer_options, producer_id), include_blank: t('.all_producers'), "data-controller": "tom-select", "data-tom-select-options-value": '{ "plugins": [] }', class: "fullwidth" + - if producer_options.many? + .producers + .label= t('.producers.label') + = select_tag :producer_id, options_for_select(producer_options, producer_id), include_blank: t('.all_producers'), "data-controller": "tom-select", "data-tom-select-options-value": '{ "plugins": [] }', class: "fullwidth" .categories .label= t('.categories.label') = select_tag :category_id, options_for_select(category_options, category_id), include_blank: t('.all_categories'), "data-controller": "tom-select", "data-tom-select-options-value": '{ "plugins": [] }', class: "fullwidth" diff --git a/spec/views/admin/products_v3/_filters.html.haml_spec.rb b/spec/views/admin/products_v3/_filters.html.haml_spec.rb new file mode 100644 index 0000000000..fa2943502a --- /dev/null +++ b/spec/views/admin/products_v3/_filters.html.haml_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "admin/products_v3/_filters.html.haml" do + subject { render } + + let(:locals) do + { + search_term: "", + producer_options: [], + producer_id: nil, + category_options: [], + category_id: nil, + } + end + + it "shows the producer filter when there are options" do + allow(view).to receive_messages locals.merge( + producer_options: [ + ["Ada's Apples", 1], + ["Ben's Bananas", 2], + ], + ) + + is_expected.to have_content "Producers" + is_expected.to have_select "producer_id", options: [ + "All producers", + "Ada's Apples", + "Ben's Bananas", + ], selected: nil + end + + it "doesn't show the producer filter when there's only one option" do + allow(view).to receive_messages locals.merge( + producer_options: [ + ["Ada's Apples", 1], + ], + ) + + is_expected.to have_no_content "Producers" + is_expected.to have_no_select "producer_id" + end +end