Render more info link in management component

This commit is contained in:
taitus
2024-11-29 15:56:20 +01:00
parent d35455624f
commit 0121e57fd0
4 changed files with 20 additions and 5 deletions

View File

@@ -5,10 +5,6 @@ class Layout::CookiesConsent::BannerComponent < Layout::CookiesConsent::BaseComp
super && cookies_consent_unset? super && cookies_consent_unset?
end end
def more_info_link
Setting["cookies_consent.more_info_link"]
end
private private
def cookies_consent_unset? def cookies_consent_unset?

View File

@@ -2,4 +2,8 @@ class Layout::CookiesConsent::BaseComponent < ApplicationComponent
def render? def render?
feature?(:cookies_consent) feature?(:cookies_consent)
end end
def more_info_link
Setting["cookies_consent.more_info_link"]
end
end end

View File

@@ -6,6 +6,9 @@
</button> </button>
</header> </header>
<p><%= t("cookies_management.description") %><p> <p><%= t("cookies_management.description") %><p>
<% if more_info_link.present? %>
<p><%= link_to t("cookies_consent.more_info_link"), more_info_link, target: "_blank" %></p>
<% end %>
<h3><%= t("cookies_management.essentials.title") %></h3> <h3><%= t("cookies_management.essentials.title") %></h3>
<p><%= t("cookies_management.essentials.description") %></p> <p><%= t("cookies_management.essentials.description") %></p>

View File

@@ -11,12 +11,24 @@ describe Layout::CookiesConsent::ManagementComponent do
expect(page).not_to be_rendered expect(page).not_to be_rendered
end end
it "is rendered with essential cookies content when the cookies consent is enabled" do it "is rendered when the cookies consent is enabled" do
Setting["cookies_consent.more_info_link"] = "/cookies_policy"
render_inline Layout::CookiesConsent::ManagementComponent.new render_inline Layout::CookiesConsent::ManagementComponent.new
expect(page).to be_rendered expect(page).to be_rendered
expect(page).to have_css "h2", text: "Cookies management" expect(page).to have_css "h2", text: "Cookies management"
expect(page).to have_link "More information about cookies", href: "/cookies_policy"
expect(page).to have_css "h3", text: "Essential cookies" expect(page).to have_css "h3", text: "Essential cookies"
expect(page).to have_button "Accept essential cookies" expect(page).to have_button "Accept essential cookies"
end end
it "does not render a link when the setting `cookies_consent.more_info_link` is not defined" do
Setting["cookies_consent.more_info_link"] = ""
render_inline Layout::CookiesConsent::ManagementComponent.new
expect(page).not_to have_link "More information about cookies"
expect(page).to be_rendered
end
end end