From d77f775c4cf1158d97daa4d360c4d72abb94559d Mon Sep 17 00:00:00 2001 From: Lynne Davis Date: Mon, 19 Dec 2016 15:06:43 +0000 Subject: [PATCH] Moving commits from 1241 to trigger build on UK staging --- .../filters/filter_products.js.coffee | 2 +- .../darkswarm/services/products.js.coffee | 3 +- .../consumer/shopping/shopping_spec.rb | 34 ++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/darkswarm/filters/filter_products.js.coffee b/app/assets/javascripts/darkswarm/filters/filter_products.js.coffee index 4cc325e483..18402edc02 100644 --- a/app/assets/javascripts/darkswarm/filters/filter_products.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/filter_products.js.coffee @@ -4,5 +4,5 @@ Darkswarm.filter 'products', (Matcher) -> text ?= "" return products if text == "" products.filter (product) => - propertiesToMatch = [product.name, product.supplier.name, product.primary_taxon.name] + propertiesToMatch = [product.name, product.variant_names, product.supplier.name, product.primary_taxon.name] Matcher.match propertiesToMatch, text diff --git a/app/assets/javascripts/darkswarm/services/products.js.coffee b/app/assets/javascripts/darkswarm/services/products.js.coffee index b120cab737..63e015e5ba 100644 --- a/app/assets/javascripts/darkswarm/services/products.js.coffee +++ b/app/assets/javascripts/darkswarm/services/products.js.coffee @@ -25,7 +25,6 @@ Darkswarm.factory 'Products', ($resource, Enterprises, Dereferencer, Taxons, Pro prices = (v.price for v in product.variants) product.price = Math.min.apply(null, prices) product.hasVariants = product.variants?.length > 0 - product.primaryImage = product.images[0]?.small_url if product.images product.primaryImageOrMissing = product.primaryImage || "/assets/noimage/small.png" product.largeImage = product.images[0]?.large_url if product.images @@ -45,5 +44,7 @@ Darkswarm.factory 'Products', ($resource, Enterprises, Dereferencer, Taxons, Pro if product.variants product.variants = for variant in product.variants variant = Variants.register variant + if product.name != variant.name_to_display + product.variant_names += variant.name_to_display variant.product = product variant diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index b449b4d083..e11f929f6a 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -142,7 +142,9 @@ feature "As a consumer I want to shop with a distributor", js: true do describe "after selecting an order cycle with products visible" do let(:variant1) { create(:variant, product: product, price: 20) } - let(:variant2) { create(:variant, product: product, price: 30) } + let(:variant2) { create(:variant, product: product, price: 30, display_name: "Badgers") } + let(:product2) { create(:simple_product, supplier: supplier, name: "Meercats") } + let(:variant3) { create(:variant, product: product2, price: 40, display_name: "Ferrets") } let(:exchange) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) } before do @@ -150,6 +152,7 @@ feature "As a consumer I want to shop with a distributor", js: true do add_variant_to_order_cycle(exchange, variant) add_variant_to_order_cycle(exchange, variant1) add_variant_to_order_cycle(exchange, variant2) + add_variant_to_order_cycle(exchange, variant3) order.order_cycle = oc1 end @@ -171,6 +174,35 @@ feature "As a consumer I want to shop with a distributor", js: true do # Product price should be listed as the lesser of these page.should have_price "$43.00" end + + it "filters search results properly" do + visit shop_path + select "frogs", :from => "order_cycle_id" + + fill_in "search", with: "74576345634XXXXXX" + page.should have_content "Sorry, no results found" + page.should_not have_content product2.name + + fill_in "search", with: "Meer" # For product named "Meercats" + page.should have_content product2.name + page.should_not have_content product.name + end + + it "returns search results for products where the search term matches one of the product's variant names" do + visit shop_path + select "frogs", :from => "order_cycle_id" + + fill_in "search", with: "Badg" # For variant with display_name "Badgers" + + within('div.pad-top') do + page.should have_content product.name + page.should have_content variant2.display_name + page.should_not have_content product2.name + page.should_not have_content variant3.display_name + end + + end + end describe "group buy products" do