Skip to content

Commit

Permalink
Add component for HostContentUpdateEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
pezholio committed Dec 19, 2024
1 parent 090f1d6 commit e79be6f
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/assets/stylesheets/admin/views/_host-content-update-event.scss
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="app-view-editions-host-content-update-event-entry__list-item">
<h4 class="govuk-heading-s app-view-editions-host-content-update-event-entry__heading">Content Block Update</h4>

<p class="govuk-body app-view-editions-host-content-update-event-entry__detail">
<%= activity %>
</p>

<p class="govuk-body-s app-view-editions-host-content-update-event-entry__datetime">
<%= time %> by <%= actor %>
</p>
</div>
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e79be6f

Please sign in to comment.