From 46a199da0522f4eec00b43904a5dc184b71ca497 Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Fri, 7 Jun 2024 17:51:48 +0100 Subject: [PATCH 1/2] Fix components test - needle and haystack were the wrong way around for the assert_no_match, which meant the test always passed - the `not_applicable` part of this test works in Rspec, which this test was originally written in, but is completely ignored in minitest (it's not useful anyway, the govspeak component isn't in this application) --- test/components/all_components_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/components/all_components_test.rb b/test/components/all_components_test.rb index 00b65f81a..237244aad 100644 --- a/test/components/all_components_test.rb +++ b/test/components/all_components_test.rb @@ -47,10 +47,10 @@ class AllComponentsTest < ActionController::TestCase assert File.exist?(css_file) end - should "not use `html_safe`", not_applicable: component_name.in?(%w[govspeak]) do + should "not use `html_safe`" do file = File.read(filename) - assert_no_match file, "html_safe" + assert_no_match "html_safe", file end end end From b6ca36bed9cf5fa7090b85474e1382bb44fb8455 Mon Sep 17 00:00:00 2001 From: Andy Sellick Date: Fri, 7 Jun 2024 17:52:20 +0100 Subject: [PATCH 2/2] Make components pass fixed test - doesn't seem like important_metadata needed the html_safe on it - updated YML example to show links rendered correctly --- .../components/_contents_list_with_body.html.erb | 12 +++++++++--- app/views/components/_important_metadata.html.erb | 2 +- .../components/docs/contents_list_with_body.yml | 8 ++++---- app/views/components/docs/important_metadata.yml | 6 +++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/views/components/_contents_list_with_body.html.erb b/app/views/components/_contents_list_with_body.html.erb index b8659b4db..188ac6ade 100644 --- a/app/views/components/_contents_list_with_body.html.erb +++ b/app/views/components/_contents_list_with_body.html.erb @@ -3,9 +3,15 @@ <% unless block.empty? %> <% contents ||= [] - sticky_attr = ' data-module="sticky-element-container"'.html_safe if contents.any? + sticky_attr = "sticky-element-container" if contents.any? %> -
> + <%= tag.div( + id: "contents", + class: "app-c-contents-list-with-body", + data: { + module: sticky_attr, + }, + ) do %> <% if contents.any? %>
<%= render 'govuk_publishing_components/components/contents_list', contents: contents %> @@ -19,5 +25,5 @@
<% end %> - + <% end %> <% end %> diff --git a/app/views/components/_important_metadata.html.erb b/app/views/components/_important_metadata.html.erb index 2d6ded5c5..1ffdc9f04 100644 --- a/app/views/components/_important_metadata.html.erb +++ b/app/views/components/_important_metadata.html.erb @@ -3,7 +3,7 @@ title = local_assigns[:title] items = local_assigns[:items] || {} items = items.reject { |k,v| v.nil? } - items = items.merge(items) { |k,v| Array(v).join(", ").html_safe } + items = items.merge(items) { |k,v| Array(v).join(", ") } margin_bottom_class = " app-c-important-metadata--bottom-margin" unless local_assigns[:margin_bottom] -%> <% if items.any? %> diff --git a/app/views/components/docs/contents_list_with_body.yml b/app/views/components/docs/contents_list_with_body.yml index 9e1a76c06..9094b27e0 100644 --- a/app/views/components/docs/contents_list_with_body.yml +++ b/app/views/components/docs/contents_list_with_body.yml @@ -79,10 +79,10 @@ examples:

Contact

Please send written representations about any competition issues to:

-
Competition and Markets Authority -
Victoria House -
Southampton Row -
London +
Competition and Markets Authority +
Victoria House +
Southampton Row +
London
WC1B 4AD

diff --git a/app/views/components/docs/important_metadata.yml b/app/views/components/docs/important_metadata.yml index 5b290489a..49f87725d 100644 --- a/app/views/components/docs/important_metadata.yml +++ b/app/views/components/docs/important_metadata.yml @@ -24,9 +24,9 @@ examples: data: items: Many things: - - First thing - - Second thing - - Third thing + - First thing + - Second thing + - Third thing with_title: description: Used on statistics announcements to display release date changed information, [see example](https://gov.uk/government/statistics/announcements/museums-and-galleries-monthly-visits--8) data: