Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix component wrapper rel option #4552

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ def check_rel_is_valid(rel_attribute)
return if rel_attribute.blank?

options = %w[alternate author bookmark canonical dns-prefetch external expect help icon license manifest me modulepreload next nofollow noopener noreferrer opener pingback preconnect prefetch preload prerender prev privacy-policy search stylesheet tag terms-of-service]
unless options.include? rel_attribute
rel_array = rel_attribute.split(" ")
unless rel_array.all? { |r| options.include? r }
raise(ArgumentError, "rel attribute (#{rel_attribute}) is not recognised")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,23 @@
}.to raise_error(ArgumentError, error)
end

it "accepts valid rel value" do
it "accepts a valid rel value" do
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(rel: "nofollow")
expect(component_helper.all_attributes[:rel]).to eql("nofollow")
end

it "accepts multiple valid rel values" do
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(rel: "nofollow noreferrer")
expect(component_helper.all_attributes[:rel]).to eql("nofollow noreferrer")
end

it "does not accept multiple rel values if one of them is invalid" do
error = "rel attribute (nofollow noreferrer potato) is not recognised"
expect {
GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(rel: "nofollow noreferrer potato")
}.to raise_error(ArgumentError, error)
end

it "can set a rel, overriding a passed value" do
helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(rel: "nofollow")
helper.set_rel("noreferrer")
Expand All @@ -412,6 +424,12 @@
helper.add_rel("noreferrer")
expect(helper.all_attributes[:rel]).to eql("nofollow noreferrer")
end

it "can add multiple rels to an existing rel" do
helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(rel: "nofollow")
helper.add_rel("noreferrer external")
expect(helper.all_attributes[:rel]).to eql("nofollow noreferrer external")
end
end

describe "margins" do
Expand Down
Loading