From aed757e349986e1bede4b5e3bc363a9a619f7b93 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 13 Apr 2022 23:35:20 +0100 Subject: [PATCH] Adds tests on shopfront ordering preference setting --- spec/system/admin/enterprises_spec.rb | 75 +++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 7a5c6df235..ba0d3e31d4 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -8,6 +8,8 @@ describe ' ' do include WebHelper include AuthenticationHelper + include ShopWorkflow + include UIComponentHelper it "viewing an enterprise" do e = create(:enterprise) @@ -110,17 +112,19 @@ describe ' accept_alert do click_link "Primary Details" end - uncheck 'enterprise_is_primary_producer' # unchecking... + # Unchecking hides the Properties tab + uncheck 'enterprise_is_primary_producer' choose 'None' expect(page).not_to have_selector "#enterprise_fees" expect(page).not_to have_selector "#payment_methods" expect(page).not_to have_selector "#shipping_methods" - expect(page).not_to have_selector "#properties" # ...hides the Properties tab - check 'enterprise_is_primary_producer' # checking... + expect(page).not_to have_selector "#properties" + # Checking displays the Properties tab + check 'enterprise_is_primary_producer' expect(page).to have_selector "#enterprise_fees" expect(page).not_to have_selector "#payment_methods" expect(page).not_to have_selector "#shipping_methods" - expect(page).to have_selector "#properties" # ...displays the Properties tab + expect(page).to have_selector "#properties" uncheck 'enterprise_is_primary_producer' choose 'Own' expect(page).to have_selector "#enterprise_fees" @@ -451,5 +455,68 @@ describe ' expect(page).to have_content 'Enterprise "First Supplier" has been successfully updated!' expect(supplier1.producer_properties.reload).to be_empty end + + describe "setting ordering preferences" do + let(:taxon) { create(:taxon, name: "Tricky Taxon") } + let(:property) { create(:property, presentation: "Fresh and Fine") } + let(:user) { create(:user, enterprise_limit: 1) } + let(:oc1) { + create(:simple_order_cycle, distributors: [distributor1], + coordinator: create(:distributor_enterprise), orders_close_at: 2.days.from_now) + } + let(:product) { + create(:simple_product, supplier: supplier1, primary_taxon: taxon, properties: [property], name: "Beans") + } + let(:variant) { product.variants.first } + let(:exchange1) { oc1.exchanges.to_enterprises(distributor1).outgoing.first } + let(:order) { create(:order, distributor: distributor1) } + + before do + exchange1.update_attribute :pickup_time, "monday" + add_variant_to_order_cycle(exchange1, variant) + end + + context "sorting by category" do + before do + visit edit_admin_enterprise_path(distributor1) + + within(".side_menu") do + click_link "Shop Preferences" + end + + choose "enterprise_preferred_shopfront_product_sorting_method_by_category" + find("#s2id_autogen7").click + find(".select2-result-label", text: "Tricky Taxon").click + click_button 'Update' + expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') + end + + it "sets the preference correctly" do + expect(distributor1.preferred_shopfront_product_sorting_method).to eql("by_category") + expect(distributor1.preferred_shopfront_taxon_order).to eql(taxon.id.to_s) + end + end + + context "sorting by producer" do + before do + visit edit_admin_enterprise_path(distributor1) + + within(".side_menu") do + click_link "Shop Preferences" + end + + choose "enterprise_preferred_shopfront_product_sorting_method_by_producer" + find("#s2id_autogen8").click + find(".select2-result-label", text: "First Supplier").click + click_button 'Update' + expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') + end + + it "sets the preference correctly" do + expect(distributor1.preferred_shopfront_product_sorting_method).to eql("by_producer") + expect(distributor1.preferred_shopfront_producer_order).to eql(supplier1.id.to_s) + end + end + end end end