Merge pull request #11383 from jibees/11274-buu-as-a-single-producer-i-should-not-be-able-to-see-the-producer-dropdown

🚧 Products V3: Do not display "Producers" selector if only one is possible
This commit is contained in:
David Cook
2023-08-22 11:33:12 +10:00
committed by GitHub
2 changed files with 48 additions and 3 deletions

View File

@@ -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"

View File

@@ -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