From d6f21b24dac649b52082cb2ab6b52a6ea710803e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 6 Jul 2016 11:04:36 +1000 Subject: [PATCH] Add specs for producers and shops search by URL --- spec/features/consumer/producers_spec.rb | 69 ++++++++++-------- spec/features/consumer/shops_spec.rb | 90 ++++++++++++++---------- 2 files changed, 91 insertions(+), 68 deletions(-) diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb index 634350af18..5c89a23529 100644 --- a/spec/features/consumer/producers_spec.rb +++ b/spec/features/consumer/producers_spec.rb @@ -27,45 +27,54 @@ feature %q{ producer1.set_producer_property 'Local', 'Victoria' producer2.set_producer_property 'Fair Trade', 'FT123' - - visit producers_path end - it "filters by taxon" do - toggle_filters - - toggle_filter 'Vegetables' - - page.should_not have_content producer1.name - page.should have_content producer2.name - - toggle_filter 'Vegetables' - toggle_filter 'Fruit' - - page.should have_content producer1.name - page.should_not have_content producer2.name + it "searches by URL" do + visit producers_path(anchor: "/?query=xyzzy") + expect(page).to have_content "Sorry, no results found for xyzzy" end - it "shows all producers with expandable details" do - page.should have_content producer1.name - expand_active_table_node producer1.name + context "on the producers page" do + before do + visit producers_path + end - # -- Taxons - page.should have_content 'Fruit' + it "filters by taxon" do + toggle_filters - # -- Properties - page.should have_content 'Organic' # Product property - page.should have_content 'Local' # Producer property - end + toggle_filter 'Vegetables' - it "doesn't show invisible producers" do - page.should_not have_content invisible_producer.name - end + page.should_not have_content producer1.name + page.should have_content producer2.name - it "links to places to buy produce" do - expand_active_table_node producer1.name - page.should have_link shop.name + toggle_filter 'Vegetables' + toggle_filter 'Fruit' + + page.should have_content producer1.name + page.should_not have_content producer2.name + end + + it "shows all producers with expandable details" do + page.should have_content producer1.name + expand_active_table_node producer1.name + + # -- Taxons + page.should have_content 'Fruit' + + # -- Properties + page.should have_content 'Organic' # Product property + page.should have_content 'Local' # Producer property + end + + it "doesn't show invisible producers" do + page.should_not have_content invisible_producer.name + end + + it "links to places to buy produce" do + expand_active_table_node producer1.name + page.should have_link shop.name + end end diff --git a/spec/features/consumer/shops_spec.rb b/spec/features/consumer/shops_spec.rb index 8b1a709462..0c5d3d7e09 100644 --- a/spec/features/consumer/shops_spec.rb +++ b/spec/features/consumer/shops_spec.rb @@ -14,56 +14,70 @@ feature 'Shops', js: true do before do producer.set_producer_property 'Organic', 'NASAA 12345' - visit shops_path end - it "shows hubs" do - page.should have_content distributor.name - expand_active_table_node distributor.name - page.should have_content "OUR PRODUCERS" + it "searches by URL" do + visit shops_path(anchor: "/?query=xyzzy") + expect(page).to have_content "Sorry, no results found for xyzzy" end - it "does not show invisible hubs" do - page.should_not have_content invisible_distributor.name - end - it "should not show hubs that are not in an order cycle" do - create(:simple_product, distributors: [d1, d2]) - visit shops_path - page.should have_no_selector 'hub.inactive' - page.should have_no_selector 'hub', text: d2.name - end + context "on the shops path" do + before do + visit shops_path + end - it "should show closed shops after clicking the button" do - create(:simple_product, distributors: [d1, d2]) - visit shops_path - click_link_and_ensure("Show closed shops", -> { page.has_selector? 'hub.inactive' }) - page.should have_selector 'hub.inactive', text: d2.name - end - - it "should link to the hub page" do - follow_active_table_node distributor.name - expect(page).to have_current_path enterprise_shop_path(distributor) - end - - describe "hub producer modal" do - let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) } - let!(:taxon) { create(:taxon, name: 'Fruit') } - let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) } - - it "should show hub producer modals" do + it "shows hubs" do + page.should have_content distributor.name expand_active_table_node distributor.name - expect(page).to have_content producer.name - open_enterprise_modal producer - modal_should_be_open_for producer + page.should have_content "OUR PRODUCERS" + end - within ".reveal-modal" do - expect(page).to have_content 'Fruit' # Taxon - expect(page).to have_content 'Organic' # Producer property + it "does not show invisible hubs" do + page.should_not have_content invisible_distributor.name + end + + it "should not show hubs that are not in an order cycle" do + create(:simple_product, distributors: [d1, d2]) + visit shops_path + page.should have_no_selector 'hub.inactive' + page.should have_no_selector 'hub', text: d2.name + end + + it "should show closed shops after clicking the button" do + create(:simple_product, distributors: [d1, d2]) + visit shops_path + click_link_and_ensure("Show closed shops", -> { page.has_selector? 'hub.inactive' }) + page.should have_selector 'hub.inactive', text: d2.name + end + + it "should link to the hub page" do + follow_active_table_node distributor.name + expect(page).to have_current_path enterprise_shop_path(distributor) + end + + describe "hub producer modal" do + let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) } + let!(:taxon) { create(:taxon, name: 'Fruit') } + let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) } + + it "should show hub producer modals" do + expand_active_table_node distributor.name + expect(page).to have_content producer.name + open_enterprise_modal producer + modal_should_be_open_for producer + + within ".reveal-modal" do + expect(page).to have_content 'Fruit' # Taxon + expect(page).to have_content 'Organic' # Producer property + end end end end + + private + def click_link_and_ensure(link_text, check) # Buttons appear to be unresponsive for a while, so keep clicking them until content appears using_wait_time 0.5 do