From 7933dea611604af1a3c8c28e85b423ca6b692972 Mon Sep 17 00:00:00 2001 From: David Cook Date: Fri, 14 Jun 2013 17:38:51 +1000 Subject: [PATCH] WIP: add more tests --- spec/features/consumer/distributors_spec.rb | 95 +++++++++++++++++---- spec/features/consumer/suppliers_spec.rb | 49 +++++++++-- 2 files changed, 124 insertions(+), 20 deletions(-) diff --git a/spec/features/consumer/distributors_spec.rb b/spec/features/consumer/distributors_spec.rb index 4a747e5c0f..8d738120c2 100644 --- a/spec/features/consumer/distributors_spec.rb +++ b/spec/features/consumer/distributors_spec.rb @@ -8,7 +8,7 @@ feature %q{ include AuthenticationWorkflow include WebHelper - scenario "viewing a list of distributors" do + scenario "viewing a list of distributors in the sidebar" do # Given some distributors d1 = create(:distributor_enterprise) d2 = create(:distributor_enterprise) @@ -26,6 +26,85 @@ feature %q{ page.should_not have_selector 'a', :text => d3.name end +scenario "viewing a list of distributors (with active products) in the sidebar when there's 5 or fewer" do + # Given some distributors + d1 = create(:distributor_enterprise) + d2 = create(:distributor_enterprise) + d3 = create(:distributor_enterprise) + d4 = create(:distributor_enterprise) + d5 = create(:distributor_enterprise) + d6 = create(:distributor_enterprise) + + # And some of those distributors have a product + create(:product, :distributors => [d1]) + create(:product, :distributors => [d3], :on_hand => 0) + + # When I go to the home page + visit spree.root_path + + # Then I should see a list containing all the distributors that have active products in stock + page.should have_selector 'a', :text => d1.name + page.should_not have_selector 'a', :text => d2.name #has no products + page.should_not have_selector 'a', :text => d3.name #has no products on hand + + # And I shouldn't see 'xx more' + page.should_not have_selector '#distributor_filter span.filter_more', :text => 'more' + + # And I shouldn't see a browse distributors button + page.should have_selector "#distributor_filter input[value='Browse All Distributors']" + end + + scenario "viewing a list of distributors (with active products) in the sidebar when there's more than 5" do + # Given some distributors + d1 = create(:distributor_enterprise) + d2 = create(:distributor_enterprise) + d3 = create(:distributor_enterprise) + d4 = create(:distributor_enterprise) + d5 = create(:distributor_enterprise) + d6 = create(:distributor_enterprise) + + # And at least 5 of those distributors have a product + create(:product, :distributors => [d1]) + create(:product, :distributors => [d2]) + create(:product, :distributors => [d3]) + create(:product, :distributors => [d4]) + create(:product, :distributors => [d5]) + create(:product, :distributors => [d6]) + + # When I go to the home page + visit spree.root_path + + # Then I should see a list containing 5 distributors that have products in stock + page.should have_selector '#distributor_filter li a', :count => 5 + + # And I should see 'xx more' + page.should have_selector '#distributor_filter span.filter_more', :text => 'more' + + # And I should see a browse distributors button + page.should have_selector "#distributor_filter input[value='Browse All Distributors']" + end + + scenario "viewing a list of all distributors" do + # Given some distributors + d1 = create(:distributor_enterprise) + d2 = create(:distributor_enterprise) + d3 = create(:distributor_enterprise) + + # And some of those distributors have a product + create(:product, :distributors => [d1]) + create(:product, :distributors => [d3]) + + # When I go to the distributors listing page + visit spree.root_path + click_button 'Browse All Distributors' + + # Then I should see a list containing all the distributors + page.should have_selector '#content a', :text => d1.name + page.should have_selector '#content a', :text => d2.name + page.should have_selector '#content a', :text => d3.name + end + + scenario "viewing a distributor" do # Given some distributors with products d1 = create(:distributor_enterprise, :long_description => "

Hello, world!

") @@ -107,20 +186,6 @@ feature %q{ end end - it "allows the user to leave the distributor" do - # Given a distributor with a product - d = create(:distributor_enterprise, :name => 'Melb Uni Co-op') - p1 = create(:product, :distributors => [d]) - - # When I select the distributor and then leave it - visit spree.select_distributor_order_path(d) - visit spree.root_path - click_button 'Browse All Distributors' - - # Then I should have left the distributor - page.should_not have_selector '#current-distributor', :text => 'You are shopping at Melb Uni Co-op' - end - context "viewing a product, it provides a choice of distributor when adding to cart" do it "works when no distributor is chosen" do # Given a distributor and a product under it diff --git a/spec/features/consumer/suppliers_spec.rb b/spec/features/consumer/suppliers_spec.rb index c52e3c6f86..ff7b2caecb 100644 --- a/spec/features/consumer/suppliers_spec.rb +++ b/spec/features/consumer/suppliers_spec.rb @@ -8,23 +8,62 @@ feature %q{ include AuthenticationWorkflow include WebHelper - scenario "viewing a list of suppliers in the sidebar" do + scenario "viewing a list of suppliers (with active products) in the sidebar when there's 5 or fewer" do # Given some suppliers s1 = create(:supplier_enterprise) s2 = create(:supplier_enterprise) s3 = create(:supplier_enterprise) + s4 = create(:supplier_enterprise) + s5 = create(:supplier_enterprise) + s6 = create(:supplier_enterprise) # And some of those suppliers have a product create(:product, :supplier => s1) - create(:product, :supplier => s3) + create(:product, :supplier => s3, :on_hand => 0) # When I go to the home page visit spree.root_path - # Then I should see a list containing all the suppliers that have products in stock + # Then I should see a list containing all the suppliers that have active products in stock page.should have_selector 'a', :text => s1.name - page.should have_selector 'a', :text => s3.name - page.should_not have_selector 'a', :text => s2.name + page.should_not have_selector 'a', :text => s2.name #has no products + page.should_not have_selector 'a', :text => s3.name #has no products on hand + + # And I shouldn't see 'xx more' + page.should_not have_selector '#supplier_filter span.filter_more', :text => 'more' + + # And I shouldn't see a browse suppliers button + page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" + end + + scenario "viewing a list of suppliers (with active products) in the sidebar when there's more than 5" do + # Given some suppliers + s1 = create(:supplier_enterprise) + s2 = create(:supplier_enterprise) + s3 = create(:supplier_enterprise) + s4 = create(:supplier_enterprise) + s5 = create(:supplier_enterprise) + s6 = create(:supplier_enterprise) + + # And at least 5 of those suppliers have a product + create(:product, :supplier => s1) + create(:product, :supplier => s2) + create(:product, :supplier => s3) + create(:product, :supplier => s4) + create(:product, :supplier => s5) + create(:product, :supplier => s6) + + # When I go to the home page + visit spree.root_path + + # Then I should see a list containing 5 suppliers that have products in stock + page.should have_selector '#supplier_filter li a', :count => 5 + + # And I should see 'xx more' + page.should have_selector '#supplier_filter span.filter_more', :text => 'more' + + # And I should see a browse suppliers button + page.should have_selector "#supplier_filter input[value='Browse All Suppliers']" end scenario "viewing a list of all suppliers" do