Add scripts component in order to enable/disable vendor scripts

This commit is contained in:
taitus
2024-12-09 16:34:27 +01:00
parent 7407c386a6
commit 5ffaf7a80e
6 changed files with 87 additions and 1 deletions

View File

@@ -0,0 +1,32 @@
require "rails_helper"
describe Layout::CookiesConsent::Vendors::ScriptsComponent do
before do
Setting["feature.cookies_consent"] = true
end
it "is not rendered when there are no vendors" do
render_inline Layout::CookiesConsent::Vendors::ScriptsComponent.new
expect(page).not_to be_rendered
end
it "is not rendered when cookies consent feature is not enabled" do
Setting["feature.cookies_consent"] = false
create(:cookies_vendor, name: "Third party", cookie: "third_party", script: "alert('Welcome!')")
render_inline Layout::CookiesConsent::Vendors::ScriptsComponent.new
expect(page).not_to be_rendered
end
it "renders script for vendor" do
create(:cookies_vendor, name: "Third party", cookie: "third_party", script: "alert('Welcome!')")
render_inline Layout::CookiesConsent::Vendors::ScriptsComponent.new
expect(page).to have_content "function third_party_script()"
expect(page).to have_content "alert('Welcome!')"
expect(page).to have_css "script", visible: :none
end
end