diff --git a/spec/system/consumer/shopping/products_spec.rb b/spec/system/consumer/shopping/products_spec.rb index cd8417ab66..c8ecc4983c 100644 --- a/spec/system/consumer/shopping/products_spec.rb +++ b/spec/system/consumer/shopping/products_spec.rb @@ -9,16 +9,27 @@ describe "As a consumer I want to view products", js: true do include UIComponentHelper describe "Viewing a product" do - let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) } + let(:taxon) { create(:taxon, name: "Tricky Taxon") } + let(:property) { create(:property, presentation: "Fresh and Fine") } + let(:taxon2) { create(:taxon, name: "Delicious Dandelion") } + let(:property2) { create(:property, presentation: "Berry Bio") } + let(:user) { create(:user, enterprise_limit: 1) } + let(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true, owner: user, name: "Testing Farm") } let(:supplier) { create(:supplier_enterprise) } let(:oc1) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now) } - let(:product) { create(:simple_product, supplier: supplier) } + let(:product) { + create(:simple_product, supplier: supplier, primary_taxon: taxon, properties: [property], name: "Beans") + } + let(:product2) { + create(:product, supplier: supplier, primary_taxon: taxon2, properties: [property2], name: "Chickpeas") + } let(:variant) { product.variants.first } - let(:order) { create(:order, distributor: distributor) } + let(:variant2) { product2.variants.first } let(:exchange1) { oc1.exchanges.to_enterprises(distributor).outgoing.first } + let(:order) { create(:order, distributor: distributor) } before do set_order order @@ -82,5 +93,47 @@ describe "As a consumer I want to view products", js: true do end end end + + describe "filtering" do + before do + exchange1.update_attribute :pickup_time, "monday" + add_variant_to_order_cycle(exchange1, variant) + add_variant_to_order_cycle(exchange1, variant2) + end + + context "product taxonomies" do + + before do + visit shop_path + end + + it "filters out variants according to the selected taxon" do + + expect(page).to have_content variant.name.to_s + expect(page).to have_content variant2.name.to_s + + within "#shop-tabs .taxon-selectors" do + expect(page).to have_content "Tricky Taxon" + toggle_filter taxon.name + end + + expect(page).to have_content variant.name.to_s + expect(page).not_to have_content variant2.name.to_s + end + + it "filters out variants according to the selected property" do + expect(page).to have_content variant.name.to_s + expect(page).to have_content variant2.name.to_s + + within "#shop-tabs .sticky-shop-filters-container .property-selectors" do + expect(page).to have_content "Fresh and Fine" + toggle_filter property.presentation + end + + expect(page).to have_content variant.name.to_s + expect(page).not_to have_content variant2.name.to_s + end + end + end end end