From 54342254b6ffe48526877b84468f8a0b63bcb2ac Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 16 Mar 2023 17:03:37 +0100 Subject: [PATCH] Do not show white label logo is hide_ofn_navigation is not checked They are both strongly linked --- .../enterprises/form/_white_label.html.haml | 2 +- spec/system/admin/enterprises_spec.rb | 73 +++++++++++++++---- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/app/views/admin/enterprises/form/_white_label.html.haml b/app/views/admin/enterprises/form/_white_label.html.haml index bf1ae27aeb..eb15cb1934 100644 --- a/app/views/admin/enterprises/form/_white_label.html.haml +++ b/app/views/admin/enterprises/form/_white_label.html.haml @@ -4,7 +4,7 @@ .three.columns.alpha = f.label :hide_ofn_navigation, t('.hide_ofn_navigation') .three.columns - = f.check_box :hide_ofn_navigation + = f.check_box :hide_ofn_navigation, { "data-controller": "checkbox-display", "data-checkbox-display-target-id-value": "white_label_logo" } .row{id: "white_label_logo"} .three.columns.alpha diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index eaf981c30c..006147db12 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -647,30 +647,73 @@ describe ' end end - context "when white label is active via `hide_ofn_navigation`" do + context "when the feature is enabled" do before do - distributor1.update_attribute(:preferred_hide_ofn_navigation, true) + Flipper.enable(:white_label) + visit edit_admin_enterprise_path(distributor1) + + within(".side_menu") do + click_link "White Label" + end end - it "can updload the white label logo for the current shop" do - attach_file "enterprise_white_label_logo", white_logo_path + 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.white_label_logo_blob.filename).to eq("logo-white.png") - end + expect(distributor1.reload.hide_ofn_navigation).to be true - 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 - it "can remove the white label logo for the current shop" do - click_button "Remove" - within ".reveal-modal" do - click_button "Confirm" + 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 + distributor1.update_attribute(:hide_ofn_navigation, true) + + visit edit_admin_enterprise_path(distributor1) + within(".side_menu") do + click_link "White Label" + end + end + + 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.white_label_logo_blob.filename).to eq("logo-white.png") + 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 - expect(flash_message).to eq("Logo removed") - expect(distributor1.reload.white_label_logo).to be_nil end end end