From e79be6f29f717faa3e0a4991e630ab799eb0d936 Mon Sep 17 00:00:00 2001 From: pezholio Date: Thu, 19 Dec 2024 09:18:51 +0000 Subject: [PATCH] Add component for HostContentUpdateEvents --- .../views/_host-content-update-event.scss | 20 ++++++++++++ app/assets/stylesheets/application.scss | 1 + .../document_history_tab_component.rb | 2 ++ ...st_content_update_event_component.html.erb | 11 +++++++ .../host_content_update_event_component.rb | 23 +++++++++++++ .../document_history_tab_component_test.rb | 13 ++++++++ ...ost_content_update_event_component_test.rb | 32 +++++++++++++++++++ 7 files changed, 102 insertions(+) create mode 100644 app/assets/stylesheets/admin/views/_host-content-update-event.scss create mode 100644 app/components/admin/editions/host_content_update_event_component.html.erb create mode 100644 app/components/admin/editions/host_content_update_event_component.rb create mode 100644 test/components/admin/editions/host_content_update_event_component_test.rb diff --git a/app/assets/stylesheets/admin/views/_host-content-update-event.scss b/app/assets/stylesheets/admin/views/_host-content-update-event.scss new file mode 100644 index 00000000000..15e8e392043 --- /dev/null +++ b/app/assets/stylesheets/admin/views/_host-content-update-event.scss @@ -0,0 +1,20 @@ +.app-view-editions-host-content-update-event-entry { + &__list-item { + margin-bottom: govuk-spacing(4); + } + + &__detail { + margin-top: govuk-spacing(0); + margin-bottom: govuk-spacing(0); + } + + &__heading { + margin-bottom: govuk-spacing(1); + } + + &__datetime { + margin-top: govuk-spacing(0); + margin-bottom: govuk-spacing(0); + color: $govuk-secondary-text-colour; + } +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 15a3d953592..f69dcfc37b6 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -34,6 +34,7 @@ $govuk-page-width: 1140px; @import "./admin/views/filter"; @import "./admin/views/govspeak-help"; @import "./admin/views/groups-index"; +@import "./admin/views/host-content-update-event"; @import "./admin/views/historical-accounts-index"; @import "./admin/views/organisations-index"; @import "./admin/views/organisations-edit"; diff --git a/app/components/admin/editions/document_history_tab_component.rb b/app/components/admin/editions/document_history_tab_component.rb index 033887c495c..283715292ed 100644 --- a/app/components/admin/editions/document_history_tab_component.rb +++ b/app/components/admin/editions/document_history_tab_component.rb @@ -26,6 +26,8 @@ def entries_on_previous_editions def render_entry(entry) if entry.is_a?(EditorialRemark) render(Admin::Editions::EditorialRemarkComponent.new(editorial_remark: entry)) + elsif entry.is_a?(HostContentUpdateEvent) + render(Admin::Editions::HostContentUpdateEventComponent.new(entry)) else render(Admin::Editions::AuditTrailEntryComponent.new(entry:, edition:)) end diff --git a/app/components/admin/editions/host_content_update_event_component.html.erb b/app/components/admin/editions/host_content_update_event_component.html.erb new file mode 100644 index 00000000000..3f85397a9ac --- /dev/null +++ b/app/components/admin/editions/host_content_update_event_component.html.erb @@ -0,0 +1,11 @@ +
+

Content Block Update

+ +

+ <%= activity %> +

+ + +
diff --git a/app/components/admin/editions/host_content_update_event_component.rb b/app/components/admin/editions/host_content_update_event_component.rb new file mode 100644 index 00000000000..f224b858300 --- /dev/null +++ b/app/components/admin/editions/host_content_update_event_component.rb @@ -0,0 +1,23 @@ +class Admin::Editions::HostContentUpdateEventComponent < ViewComponent::Base + include ApplicationHelper + + def initialize(event) + @event = event + end + +private + + attr_reader :event + + def activity + "#{event.content_title.strip} updated" + end + + def time + absolute_time(event.created_at) + end + + def actor + event.author ? linked_author(event.author, class: "govuk-link") : "User (removed)" + end +end diff --git a/test/components/admin/editions/document_history_tab_component_test.rb b/test/components/admin/editions/document_history_tab_component_test.rb index 7cb766cc04d..7aa70aec28a 100644 --- a/test/components/admin/editions/document_history_tab_component_test.rb +++ b/test/components/admin/editions/document_history_tab_component_test.rb @@ -54,17 +54,22 @@ class Admin::Editions::DocumentHistoryTabComponentTest < ViewComponent::TestCase assert_selector ".app-view-editions__newer-edition-entries h3", text: "On newer editions" assert_selector ".app-view-editions__newer-edition-entries div.app-view-editions-audit-trail-entry__list-item", count: 2 assert_selector ".app-view-editions__newer-edition-entries div.app-view-editions-editorial-remark__list-item", count: 1 + assert_selector ".app-view-editions__newer-edition-entries div.app-view-editions-host-content-update-event-entry__list-item", count: 0 assert_selector ".app-view-editions__current-edition-entries h3", text: "On this edition" assert_selector ".app-view-editions__current-edition-entries div.app-view-editions-audit-trail-entry__list-item", count: 4 assert_selector ".app-view-editions__current-edition-entries div.app-view-editions-editorial-remark__list-item", count: 1 + assert_selector ".app-view-editions__current-edition-entries div.app-view-editions-host-content-update-event-entry__list-item", count: 1 assert_selector ".app-view-editions__previous-edition-entries h3", text: "On previous editions" assert_selector ".app-view-editions__previous-edition-entries div.app-view-editions-audit-trail-entry__list-item", count: 2 assert_selector ".app-view-editions__previous-edition-entries div.app-view-editions-editorial-remark__list-item", count: 0 + assert_selector ".app-view-editions__previous-edition-entries div.app-view-editions-host-content-update-event-entry__list-item", count: 2 end def seed_document_event_history + @events = [] + acting_as(@user) do @document = create(:document) @first_edition = create(:draft_edition, document: @document, major_change_published_at: Time.zone.now) @@ -96,6 +101,10 @@ def seed_document_event_history @first_edition.publish! end + some_time_passes + @events << build(:host_content_update_event, created_at: Time.zone.now) + some_time_passes + @events << build(:host_content_update_event, created_at: Time.zone.now) some_time_passes acting_as(@user) do @@ -108,6 +117,8 @@ def seed_document_event_history @second_edition.publish! end + some_time_passes + @events << build(:host_content_update_event, created_at: Time.zone.now) some_time_passes acting_as(@user2) do @@ -117,6 +128,8 @@ def seed_document_event_history some_time_passes create(:editorial_remark, edition: @third_edition, author: @user, body: "Drafted to include newer changes.") end + + HostContentUpdateEvent.stubs(:all_for_date_window).returns(@events) end def some_time_passes diff --git a/test/components/admin/editions/host_content_update_event_component_test.rb b/test/components/admin/editions/host_content_update_event_component_test.rb new file mode 100644 index 00000000000..7379fd9684d --- /dev/null +++ b/test/components/admin/editions/host_content_update_event_component_test.rb @@ -0,0 +1,32 @@ +require "test_helper" + +class Admin::Editions::HostContentUpdateEventComponentTest < ViewComponent::TestCase + extend Minitest::Spec::DSL + include Rails.application.routes.url_helpers + + let(:created_at) { Time.zone.local(2020, 1, 1, 11, 11) } + let(:content_title) { "Some content" } + let(:user) { build_stubbed(:user) } + + let(:host_content_update_event) do + build(:host_content_update_event, content_title:, created_at:, author: user) + end + + it "constructs output based on the entry when an actor is present" do + render_inline(Admin::Editions::HostContentUpdateEventComponent.new(host_content_update_event)) + + assert_equal page.find("h4").text, "Content Block Update" + assert_equal page.all("p")[0].text.strip, "#{content_title} updated" + assert_equal page.all("p")[1].text.strip, "1 January 2020 11:11am by #{user.name}" + end + + describe "when an actor is not present" do + let(:user) { nil } + + it "shows removed user when an actor is not present" do + render_inline(Admin::Editions::HostContentUpdateEventComponent.new(host_content_update_event)) + + assert_equal page.all("p")[1].text.strip, "1 January 2020 11:11am by User (removed)" + end + end +end