From aaa9bac4ddc2c4b18a5ae19ddf505db22bc397a3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 9 May 2023 15:05:37 +0200 Subject: [PATCH] Remove white_label feature toggle White label is now activated for everyone. + add mock for `spec/controllers/spree/orders_controller_spec.rb` --- app/controllers/concerns/white_label.rb | 2 - app/helpers/admin/enterprises_helper.rb | 9 +- lib/open_food_network/feature_toggle.rb | 3 - .../spree/orders_controller_spec.rb | 3 +- spec/system/admin/enterprises_spec.rb | 157 +++--- spec/system/consumer/white_label_spec.rb | 480 +++++++++--------- 6 files changed, 303 insertions(+), 351 deletions(-) diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb index 63fff5a525..f42fd782c3 100644 --- a/app/controllers/concerns/white_label.rb +++ b/app/controllers/concerns/white_label.rb @@ -5,8 +5,6 @@ module WhiteLabel include EnterprisesHelper def hide_ofn_navigation(distributor = current_distributor) - return false unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label) - # if the distributor has the hide_ofn_navigation preference set to true # then we should hide the OFN navigation @hide_ofn_navigation = distributor.hide_ofn_navigation diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index a07db116da..a81cc66e93 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -49,13 +49,8 @@ module Admin { name: 'tag_rules', icon_class: "icon-random", show: is_shop }, { name: 'shop_preferences', icon_class: "icon-shopping-cart", show: is_shop }, { name: 'users', icon_class: "icon-user", show: true }, - ] + [add_white_label_if_feature_activated].compact - end - - def add_white_label_if_feature_activated - return nil unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label) - - { name: 'white_label', icon_class: "icon-leaf", show: true } + { name: 'white_label', icon_class: "icon-leaf", show: true }, + ] end end end diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb index 305511a0a5..a316ebc43f 100644 --- a/lib/open_food_network/feature_toggle.rb +++ b/lib/open_food_network/feature_toggle.rb @@ -41,9 +41,6 @@ module OpenFoodNetwork "vouchers" => <<~DESC, Add voucher functionality. Voucher can be managed via Enterprise settings. DESC - "white_label" => <<~DESC, - Customize shopfront (shop, cart, checkout) and emails without OFN branding. - DESC }.freeze def self.setup! diff --git a/spec/controllers/spree/orders_controller_spec.rb b/spec/controllers/spree/orders_controller_spec.rb index 60d27d13f5..ace06eccee 100644 --- a/spec/controllers/spree/orders_controller_spec.rb +++ b/spec/controllers/spree/orders_controller_spec.rb @@ -90,12 +90,13 @@ describe Spree::OrdersController, type: :controller do it "redirects to shop when order is empty" do allow(controller).to receive(:current_distributor).and_return(distributor) - allow(distributor).to receive(:hide_ofn_navigation).and_return false allow(controller).to receive(:current_order_cycle).and_return(order_cycle) allow(controller).to receive(:current_order).and_return order allow(order).to receive_message_chain(:line_items, :empty?).and_return true allow(order).to receive(:insufficient_stock_lines).and_return [] allow(order).to receive(:line_item_variants).and_return [] + allow(order).to receive(:distributor).and_return distributor + allow(distributor).to receive(:hide_ofn_navigation).and_return false allow(order_cycle).to receive(:variants_distributed_by).and_return [] session[:access_token] = order.token diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 8fd7a1f9d0..3c75145ced 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -607,80 +607,78 @@ describe ' end context "white label settings" do - context "when the feature is enabled" do - before do - Flipper.enable(:white_label) - visit edit_admin_enterprise_path(distributor1) + before do + visit edit_admin_enterprise_path(distributor1) - within(".side_menu") do - click_link "White Label" - end - end - - it "set the hide_ofn_navigation preference for the current shop" do - check "Hide OFN navigation" - click_button 'Update' - success_message = 'Enterprise "First Distributor" has been successfully updated!' - expect(flash_message).to eq success_message - expect(distributor1.reload.hide_ofn_navigation).to be true - - visit edit_admin_enterprise_path(distributor1) - within(".side_menu") do - click_link "White Label" - end - - uncheck "Hide OFN navigation" - click_button 'Update' - expect(flash_message).to eq success_message - expect(distributor1.reload.hide_ofn_navigation).to be false + within(".side_menu") do + click_link "White Label" end end - context "when the feature is disabled" do - before do - Flipper.disable(:white_label) - visit edit_admin_enterprise_path(distributor1) + it "set the hide_ofn_navigation preference for the current shop" do + check "Hide OFN navigation" + click_button 'Update' + success_message = 'Enterprise "First Distributor" has been successfully updated!' + expect(flash_message).to eq success_message + expect(distributor1.reload.hide_ofn_navigation).to be true + + visit edit_admin_enterprise_path(distributor1) + within(".side_menu") do + click_link "White Label" end - it "does not show the white label settings" do - expect(page).not_to have_link "White Label" - end + uncheck "Hide OFN navigation" + click_button 'Update' + expect(flash_message).to eq success_message + expect(distributor1.reload.hide_ofn_navigation).to be false end - context "when the feature is enabled" do + it "set the hide_ofn_navigation preference for the current shop" do + expect(page).not_to have_content "LOGO USED IN SHOPFRONT" + check "Hide OFN navigation" + click_button 'Update' + expect(flash_message) + .to eq('Enterprise "First Distributor" has been successfully updated!') + expect(distributor1.reload.hide_ofn_navigation).to be true + + visit edit_admin_enterprise_path(distributor1) + within(".side_menu") do + click_link "White Label" + end + + expect(page).to have_content "LOGO USED IN SHOPFRONT" + uncheck "Hide OFN navigation" + click_button 'Update' + expect(flash_message) + .to eq('Enterprise "First Distributor" has been successfully updated!') + expect(distributor1.reload.hide_ofn_navigation).to be false + end + + context "when white label is active via `hide_ofn_navigation`" do before do - Flipper.enable(:white_label) - visit edit_admin_enterprise_path(distributor1) - - within(".side_menu") do - click_link "White Label" - end - end - - it "set the hide_ofn_navigation preference for the current shop" do - expect(page).not_to have_content "LOGO USED IN SHOPFRONT" - check "Hide OFN navigation" - click_button 'Update' - expect(flash_message) - .to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.hide_ofn_navigation).to be true + distributor1.update_attribute(:hide_ofn_navigation, true) visit edit_admin_enterprise_path(distributor1) within(".side_menu") do click_link "White Label" end + end - expect(page).to have_content "LOGO USED IN SHOPFRONT" - uncheck "Hide OFN navigation" + it "can updload the white label logo for the current shop" do + attach_file "enterprise_white_label_logo", white_logo_path click_button 'Update' expect(flash_message) .to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.hide_ofn_navigation).to be false + expect(distributor1.reload.white_label_logo_blob.filename).to eq("logo-white.png") end - context "when white label is active via `hide_ofn_navigation`" do + it "does not show the white label logo link field" do + expect(page).not_to have_field "white_label_logo_link" + end + + context "when enterprise has a white label logo" do before do - distributor1.update_attribute(:hide_ofn_navigation, true) + distributor1.update white_label_logo: white_logo_file visit edit_admin_enterprise_path(distributor1) within(".side_menu") do @@ -688,47 +686,24 @@ describe ' end end - it "can updload the white label logo for the current shop" do - attach_file "enterprise_white_label_logo", white_logo_path + it "can remove the white label logo for the current shop" do + expect(page).to have_selector("img[src*='logo-white.png']") + expect(distributor1.white_label_logo).to be_attached + click_button "Remove" + within ".reveal-modal" do + click_button "Confirm" + end + expect(flash_message).to match(/Logo removed/) + distributor1.reload + expect(distributor1.white_label_logo).to_not be_attached + end + + it "can edit the text field white_label_logo_link" do + fill_in "enterprise_white_label_logo_link", with: "https://www.openfoodnetwork.org" click_button 'Update' expect(flash_message) .to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.white_label_logo_blob.filename).to eq("logo-white.png") - end - - it "does not show the white label logo link field" do - expect(page).not_to have_field "white_label_logo_link" - end - - context "when enterprise has a white label logo" do - before do - distributor1.update white_label_logo: white_logo_file - - visit edit_admin_enterprise_path(distributor1) - within(".side_menu") do - click_link "White Label" - end - end - - it "can remove the white label logo for the current shop" do - expect(page).to have_selector("img[src*='logo-white.png']") - expect(distributor1.white_label_logo).to be_attached - click_button "Remove" - within ".reveal-modal" do - click_button "Confirm" - end - expect(flash_message).to match(/Logo removed/) - distributor1.reload - expect(distributor1.white_label_logo).to_not be_attached - end - - it "can edit the text field white_label_logo_link" do - fill_in "enterprise_white_label_logo_link", with: "https://www.openfoodnetwork.org" - click_button 'Update' - expect(flash_message) - .to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.white_label_logo_link).to eq("https://www.openfoodnetwork.org") - end + expect(distributor1.reload.white_label_logo_link).to eq("https://www.openfoodnetwork.org") end end end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index a7ddcc283f..317a196d96 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -46,294 +46,280 @@ describe 'White label setting' do end end - context "when the white label feature is activated" do - before do - Flipper.enable(:white_label) - end + context "manage the hide_ofn_navigation preference" do + context "when the preference is set to true" do + before do + distributor.update_attribute(:hide_ofn_navigation, true) + end - context "manage the hide_ofn_navigation preference" do - context "when the preference is set to true" do - before do - distributor.update_attribute(:hide_ofn_navigation, true) + shared_examples "hides the OFN navigation when needed only" do + it "hides the OFN navigation when visiting the shop" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_no_selector ofn_navigation end - shared_examples "hides the OFN navigation when needed only" do - it "hides the OFN navigation when visiting the shop" do - visit main_app.enterprise_shop_path(distributor) + it "does not hide the OFN navigation when visiting root path" do + visit main_app.root_path + expect(page).to have_selector ofn_navigation + end + end + + context "without order or current distributor" do + it_behaves_like "hides the OFN navigation when needed only" + end + + context "when the user has an order ready to checkout" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + end + + shared_examples "hides the OFN navigation when needed only for the checkout" do + it_behaves_like "hides the OFN navigation when needed only" + + it "hides the OFN navigation when visiting cart path" do + visit main_app.cart_path expect(page).to have_no_selector ofn_navigation end - it "does not hide the OFN navigation when visiting root path" do - visit main_app.root_path - expect(page).to have_selector ofn_navigation + it "hides the OFN navigation when visiting checkout path" do + visit checkout_path + expect(page).to have_content "Checkout now" + expect(page).to have_content "Order ready for " + expect(page).to have_no_selector ofn_navigation end end - context "without order or current distributor" do - it_behaves_like "hides the OFN navigation when needed only" + context "when the split checkout is disabled" do + it_behaves_like "hides the OFN navigation when needed only for the checkout" end - context "when the user has an order ready to checkout" do + context "when the split checkout is enabled" do before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) + Flipper.enable(:split_checkout) end - shared_examples "hides the OFN navigation when needed only for the checkout" do - it_behaves_like "hides the OFN navigation when needed only" + it_behaves_like "hides the OFN navigation when needed only for the checkout" + end + end - it "hides the OFN navigation when visiting cart path" do - visit main_app.cart_path - expect(page).to have_no_selector ofn_navigation - end + context "when the user has a complete order" do + before do + set_order(complete_order) + end - it "hides the OFN navigation when visiting checkout path" do - visit checkout_path - expect(page).to have_content "Checkout now" - expect(page).to have_content "Order ready for " - expect(page).to have_no_selector ofn_navigation - end - end - - context "when the split checkout is disabled" do - it_behaves_like "hides the OFN navigation when needed only for the checkout" - end - - context "when the split checkout is enabled" do - before do - Flipper.enable(:split_checkout) - end - - it_behaves_like "hides the OFN navigation when needed only for the checkout" + shared_examples "hides the OFN navigation when needed only for the order confirmation" do + it "hides" do + visit order_path(complete_order, order_token: complete_order.token) + expect(page).to have_no_selector ofn_navigation end end - context "when the user has a complete order" do - before do - set_order(complete_order) - end - - shared_examples "hides the OFN navigation when needed only for the order confirmation" do - it "hides" do - visit order_path(complete_order, order_token: complete_order.token) - expect(page).to have_no_selector ofn_navigation - end - end - - context "when the current distributor is the distributor of the order" do - before do - allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). - and_return(distributor) - end - - it_behaves_like "hides the OFN navigation when needed only for the order confirmation" - end - - context "when the user has a current distributor that is not the distributor's order" do - let!(:another_distributor) { create(:distributor_enterprise) } - before do - another_distributor.update_attribute(:hide_ofn_navigation, false) - allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). - and_return(another_distributor) - end - - it_behaves_like "hides the OFN navigation when needed only for the order confirmation" - end - end - - context "when the user has a current distributor" do + context "when the current distributor is the distributor of the order" do before do allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(distributor) end - it_behaves_like "hides the OFN navigation when needed only" + it_behaves_like "hides the OFN navigation when needed only for the order confirmation" + end + + context "when the user has a current distributor that is not the distributor's order" do + let!(:another_distributor) { create(:distributor_enterprise) } + before do + another_distributor.update_attribute(:hide_ofn_navigation, false) + allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). + and_return(another_distributor) + end + + it_behaves_like "hides the OFN navigation when needed only for the order confirmation" end end - context "when the preference is set to false" do + context "when the user has a current distributor" do before do - distributor.update_attribute(:hide_ofn_navigation, false) - set_order(order) allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(distributor) end - it_behaves_like "does not hide the OFN navigation" + it_behaves_like "hides the OFN navigation when needed only" end end - context "manage the white_label_logo preference" do - context "when the distributor has no logo" do - before do - distributor.update_attribute(:hide_ofn_navigation, true) - end - - shared_examples "shows/hide the right logos" do - it "shows the OFN logo on shop page" do - expect(page).to have_selector "img[src*='/default_images/ofn-logo.png']" - end - end - - context "on shop page" do - before do - visit main_app.enterprise_shop_path(distributor) - end - - it_behaves_like "shows/hide the right logos" - end - - context "on cart page" do - before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) - visit main_app.cart_path - end - - it_behaves_like "shows/hide the right logos" - end - - context "on checkout page" do - before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) - visit checkout_path - end - - it_behaves_like "shows/hide the right logos" - end - - context "on order confirmation page" do - before do - visit order_path(complete_order, order_token: complete_order.token) - end - - it_behaves_like "shows/hide the right logos" - end + context "when the preference is set to false" do + before do + distributor.update_attribute(:hide_ofn_navigation, false) + set_order(order) + allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). + and_return(distributor) end - context "when the distributor has a logo" do - before do - distributor.update_attribute(:hide_ofn_navigation, true) - distributor.update white_label_logo: white_logo_file - end - - shared_examples "shows/hide the right logos" do - it "shows the white label logo on shop page" do - expect(page).to have_selector "img[src*='/logo-white.png']" - end - it "does not show the OFN logo on shop page" do - expect(page).not_to have_selector "img[src*='/default_images/ofn-logo.png']" - end - it "links the logo to the default URL" do - within ".nav-logo .ofn-logo" do - expect(page).to have_selector "a[href='/']" - end - end - end - - context "on shop page" do - before do - visit main_app.enterprise_shop_path(distributor) - end - - it_behaves_like "shows/hide the right logos" - end - - context "on cart page" do - before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) - visit main_app.cart_path - end - - it_behaves_like "shows/hide the right logos" - end - - context "on checkout page" do - before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) - visit checkout_path - end - - it_behaves_like "shows/hide the right logos" - end - - context "on order confirmation page" do - before do - visit order_path(complete_order, order_token: complete_order.token) - end - - it_behaves_like "shows/hide the right logos" - end - - context "and a link on this logo" do - before do - distributor.update_attribute(:white_label_logo_link, "https://www.example.com") - end - - shared_examples "shows the right link on the logo" do - it "shows the white label logo link" do - within ".nav-logo .ofn-logo" do - expect(page).to_not have_selector "a[href='/']" - expect(page).to have_selector "a[href*='https://www.example.com']" - end - end - end - - context "on shop page" do - before do - visit main_app.enterprise_shop_path(distributor) - end - - it_behaves_like "shows the right link on the logo" - end - - context "on cart page" do - before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) - visit main_app.cart_path - end - - it_behaves_like "shows the right link on the logo" - end - - context "on checkout page" do - before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) - visit checkout_path - end - - it_behaves_like "shows the right link on the logo" - end - - context "on order confirmation page" do - before do - visit order_path(complete_order, order_token: complete_order.token) - end - - it_behaves_like "shows the right link on the logo" - end - end - end + it_behaves_like "does not hide the OFN navigation" end end - context "when the white label feature is deactivated" do - before do - Flipper.disable(:white_label) + context "manage the white_label_logo preference" do + context "when the distributor has no logo" do + before do + distributor.update_attribute(:hide_ofn_navigation, true) + end + + shared_examples "shows/hide the right logos" do + it "shows the OFN logo on shop page" do + expect(page).to have_selector "img[src*='/default_images/ofn-logo.png']" + end + end + + context "on shop page" do + before do + visit main_app.enterprise_shop_path(distributor) + end + + it_behaves_like "shows/hide the right logos" + end + + context "on cart page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit main_app.cart_path + end + + it_behaves_like "shows/hide the right logos" + end + + context "on checkout page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit checkout_path + end + + it_behaves_like "shows/hide the right logos" + end + + context "on order confirmation page" do + before do + visit order_path(complete_order, order_token: complete_order.token) + end + + it_behaves_like "shows/hide the right logos" + end end - it_behaves_like "does not hide the OFN navigation" + context "when the distributor has a logo" do + before do + distributor.update_attribute(:hide_ofn_navigation, true) + distributor.update white_label_logo: white_logo_file + end + + shared_examples "shows/hide the right logos" do + it "shows the white label logo on shop page" do + expect(page).to have_selector "img[src*='/logo-white.png']" + end + it "does not show the OFN logo on shop page" do + expect(page).not_to have_selector "img[src*='/default_images/ofn-logo.png']" + end + it "links the logo to the default URL" do + within ".nav-logo .ofn-logo" do + expect(page).to have_selector "a[href='/']" + end + end + end + + context "on shop page" do + before do + visit main_app.enterprise_shop_path(distributor) + end + + it_behaves_like "shows/hide the right logos" + end + + context "on cart page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit main_app.cart_path + end + + it_behaves_like "shows/hide the right logos" + end + + context "on checkout page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit checkout_path + end + + it_behaves_like "shows/hide the right logos" + end + + context "on order confirmation page" do + before do + visit order_path(complete_order, order_token: complete_order.token) + end + + it_behaves_like "shows/hide the right logos" + end + + context "and a link on this logo" do + before do + distributor.update_attribute(:white_label_logo_link, "https://www.example.com") + end + + shared_examples "shows the right link on the logo" do + it "shows the white label logo link" do + within ".nav-logo .ofn-logo" do + expect(page).to_not have_selector "a[href='/']" + expect(page).to have_selector "a[href*='https://www.example.com']" + end + end + end + + context "on shop page" do + before do + visit main_app.enterprise_shop_path(distributor) + end + + it_behaves_like "shows the right link on the logo" + end + + context "on cart page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit main_app.cart_path + end + + it_behaves_like "shows the right link on the logo" + end + + context "on checkout page" do + before do + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) + visit checkout_path + end + + it_behaves_like "shows the right link on the logo" + end + + context "on order confirmation page" do + before do + visit order_path(complete_order, order_token: complete_order.token) + end + + it_behaves_like "shows the right link on the logo" + end + end + end end end