From 9e9a5b5c0e77470dadb435452bfc746224abed1e Mon Sep 17 00:00:00 2001
From: AshGDS <8880610+AshGDS@users.noreply.github.com>
Date: Tue, 14 Jan 2025 15:00:18 +0000
Subject: [PATCH] BREAKING Use component wrapper on attachment link component

---
 CHANGELOG.md                                             | 1 +
 .../components/_attachment_link.html.erb                 | 9 ++++++---
 .../components/docs/attachment_link.yml                  | 5 +++--
 spec/components/attachment_link_spec.rb                  | 2 +-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1c69757b7a..38988e82a8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
 
 * **BREAKING**  Use component wrapper on big number component ([PR #4550](https://github.com/alphagov/govuk_publishing_components/pull/4550))
 * **BREAKING** Use component wrapper on attachment component ([PR #4545](https://github.com/alphagov/govuk_publishing_components/pull/4545))
+* **BREAKING** Use component wrapper on attachment link component ([PR #4549](https://github.com/alphagov/govuk_publishing_components/pull/4549))
 * Add 'draggable' attribute to component wrapper helper ([PR #4544](https://github.com/alphagov/govuk_publishing_components/pull/4544))
 
 ## 48.0.0
diff --git a/app/views/govuk_publishing_components/components/_attachment_link.html.erb b/app/views/govuk_publishing_components/components/_attachment_link.html.erb
index c04c0dda53..78b450458a 100644
--- a/app/views/govuk_publishing_components/components/_attachment_link.html.erb
+++ b/app/views/govuk_publishing_components/components/_attachment_link.html.erb
@@ -3,7 +3,7 @@
 
   attachment = GovukPublishingComponents::Presenters::AttachmentHelper.new(attachment)
   target ||= nil
-  data_attributes ||= {}
+  url_data_attributes ||= {}
   attributes = []
   if attachment.content_type_name
     content = if attachment.content_type_abbr
@@ -30,11 +30,14 @@
       class: "gem-c-attachment-link__attribute",
     )
   end
+
+  component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
+  component_helper.add_class("gem-c-attachment-link")
 %>
-<%= tag.span(class: "gem-c-attachment-link") do %>
+<%= tag.span(**component_helper.all_attributes) do %>
   <%= link_to(attachment.title, attachment.url,
               class: "govuk-link",
               target: target,
-              data: data_attributes) -%>
+              data: url_data_attributes) -%>
   <%= raw("(#{attributes.join(', ')})") if attributes.any? -%>
 <% end %>
diff --git a/app/views/govuk_publishing_components/components/docs/attachment_link.yml b/app/views/govuk_publishing_components/components/docs/attachment_link.yml
index 342a7f2cfe..9e54110327 100644
--- a/app/views/govuk_publishing_components/components/docs/attachment_link.yml
+++ b/app/views/govuk_publishing_components/components/docs/attachment_link.yml
@@ -14,6 +14,7 @@ accessibility_criteria: |
     Attachment links within paragraphs of text do not need to meet the 24 by 24 CSS pixels requirements.    
 shared_accessibility_criteria:
 - link
+uses_component_wrapper_helper: true
 examples:
   default:
     data:
@@ -58,10 +59,10 @@ examples:
         title: "Temporary snow ploughs: guidance note"
         url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/259634/temporary-snow-ploughs.pdf
       target: _blank
-  with_data_attributes:
+  with_data_attributes_on_url:
     data:
       attachment:
         title: "Temporary snow ploughs: guidance note"
         url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/259634/temporary-snow-ploughs.pdf
-      data_attributes:
+      url_data_attributes:
         gtm: "attachment-preview"
diff --git a/spec/components/attachment_link_spec.rb b/spec/components/attachment_link_spec.rb
index 7cb3e2f0e8..fabcab5a33 100644
--- a/spec/components/attachment_link_spec.rb
+++ b/spec/components/attachment_link_spec.rb
@@ -58,7 +58,7 @@ def component_name
         title: "Attachment",
         url: "attachment",
       },
-      data_attributes: { gtm: "attachment-preview" },
+      url_data_attributes: { gtm: "attachment-preview" },
     )
     assert_select "a.govuk-link[data-gtm='attachment-preview']"
   end