diff --git a/app/controllers/concerns/white_label.rb b/app/controllers/concerns/white_label.rb index 19c54741f8..5b9d23b96b 100644 --- a/app/controllers/concerns/white_label.rb +++ b/app/controllers/concerns/white_label.rb @@ -5,6 +5,8 @@ module WhiteLabel include EnterprisesHelper def hide_ofn_navigation + 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.preferred_hide_ofn_navigation diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index 8e273a810f..f36661544a 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -50,8 +50,13 @@ 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 }, - { name: 'white_label', icon_class: "icon-leaf", 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 } end # rubocop:enable Metrics/MethodLength end diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb index ebebffb1de..b6a3048209 100644 --- a/lib/open_food_network/feature_toggle.rb +++ b/lib/open_food_network/feature_toggle.rb @@ -40,6 +40,9 @@ 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 # Move your feature entry from CURRENT_FEATURES to RETIRED_FEATURES when diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 0265a1f32d..1ba51c6a65 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -586,29 +586,43 @@ describe ' end context "white label settings" do - before do - visit edit_admin_enterprise_path(distributor1) + context "when the feature is enabled" do + before do + Flipper.enable(:white_label) + visit edit_admin_enterprise_path(distributor1) - within(".side_menu") do - click_link "White Label" + 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' + expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') + expect(distributor1.reload.preferred_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('Enterprise "First Distributor" has been successfully updated!') + expect(distributor1.reload.preferred_hide_ofn_navigation).to be false end end - it "set the hide_ofn_navigation preference for the current shop" do - check "Hide OFN navigation" - click_button 'Update' - expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.preferred_hide_ofn_navigation).to be true - - visit edit_admin_enterprise_path(distributor1) - within(".side_menu") do - click_link "White Label" + context "when the feature is disabled" do + before do + Flipper.disable(:white_label) + visit edit_admin_enterprise_path(distributor1) end - uncheck "Hide OFN navigation" - click_button 'Update' - expect(flash_message).to eq('Enterprise "First Distributor" has been successfully updated!') - expect(distributor1.reload.preferred_hide_ofn_navigation).to be false + it "does not show the white label settings" do + expect(page).not_to have_link "White Label" + end end end end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index ce1d52ab13..58aa0ff5af 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -21,136 +21,154 @@ describe 'White label setting' do let(:ofn_navigation) { 'ul.nav-main-menu' } - context "manage the hide_ofn_navigation preference" do - context "when the preference is set to true" do - before do - distributor.update_attribute(:preferred_hide_ofn_navigation, true) - end + shared_examples "does not hide the OFN navigation" do + it "does not hide the OFN navigation when visiting the shop" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_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) - 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 + 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 - end - end + it "does not hide the OFN navigation when visiting cart path" do + visit main_app.cart_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 white label feature is activated" do + before do + Flipper.enable(:white_label) + end - context "when the user has an order ready to checkout" do + context "manage the hide_ofn_navigation preference" do + context "when the preference is set to true" do before do - order.update_attribute(:state, 'cart') - order.line_items << create(:line_item, variant: product.variants.first) - set_order(order) + distributor.update_attribute(:preferred_hide_ofn_navigation, true) end - shared_examples "hides the OFN navigation when needed only for the checkout" do + 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 + + 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" - - 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 "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 + context "when the user has an order ready to checkout" do before do - Flipper.enable(:split_checkout) + order.update_attribute(:state, 'cart') + order.line_items << create(:line_item, variant: product.variants.first) + set_order(order) end - it_behaves_like "hides the OFN navigation when needed only for the checkout" - end - end + shared_examples "hides the OFN navigation when needed only for the checkout" do + it_behaves_like "hides the OFN navigation when needed only" - context "when the user has a complete order" do - let(:complete_order) { - create(:order_with_credit_payment, - user: nil, - email: "guest@user.com", - distributor: distributor, - order_cycle: order_cycle) - } - before do - set_order(complete_order) - 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 - 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 + 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" end end - context "when the current distributor is the distributor of the order" do + context "when the user has a complete order" do + let(:complete_order) { + create(:order_with_credit_payment, + user: nil, + email: "guest@user.com", + distributor: distributor, + order_cycle: order_cycle) + } + 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(:preferred_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 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(:preferred_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" + it_behaves_like "hides the OFN navigation when needed only" end end - context "when the user has a current distributor" do + context "when the preference is set to false" do before do + distributor.update_attribute(:preferred_hide_ofn_navigation, false) + set_order(order) allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). and_return(distributor) end - it_behaves_like "hides the OFN navigation when needed only" - end - end - - context "when the preference is set to false" do - before do - distributor.update_attribute(:preferred_hide_ofn_navigation, false) - set_order(order) - allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor). - and_return(distributor) - end - - it "does not hide the OFN navigation when visiting the shop" do - visit main_app.enterprise_shop_path(distributor) - expect(page).to have_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 - end - - it "does not hide the OFN navigation when visiting cart path" do - visit main_app.cart_path - expect(page).to have_selector ofn_navigation + it_behaves_like "does not hide the OFN navigation" end end end + + context "when the white label feature is deactivated" do + before do + Flipper.disable(:white_label) + end + + it_behaves_like "does not hide the OFN navigation" + end end