-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add component for HostContentUpdateEvents
- Loading branch information
Showing
7 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
app/assets/stylesheets/admin/views/_host-content-update-event.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/components/admin/editions/host_content_update_event_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
23 changes: 23 additions & 0 deletions
23
app/components/admin/editions/host_content_update_event_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/components/admin/editions/host_content_update_event_component_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |