-
Notifications
You must be signed in to change notification settings - Fork 193
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
I’ve also added a lightweight Cucumber test to ensure everything fits together as we expect. I had to make a slight change to one of the steps to ensure we’re always visiting the edit page for the latest edition
- Loading branch information
Showing
10 changed files
with
143 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Feature: Showing content block updates in history | ||
|
||
Background: | ||
Given I am an editor | ||
And a published news article "Stubble to be Outlawed" exists | ||
And the document has been updated by a change to the content block "Some email address" | ||
|
||
Scenario: Content block update exists for current edition | ||
When I am on the edit page for news article "Stubble to be Outlawed" | ||
And I click the "History" tab | ||
Then I should see an entry for the content block "Some email address" on the current edition | ||
|
||
Scenario: Content block update exists for a previous edition | ||
When I force publish a new edition of the news article "Stubble to be Outlawed" | ||
And I am on the edit page for news article "Stubble to be Outlawed" | ||
And I click the "History" tab | ||
Then I should see an entry for the content block "Some email address" on the previous edition |
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,13 @@ | ||
And(/^the document has been updated by a change to the content block "([^"]*)"$/) do |content_block_title| | ||
host_content_update_event = build(:host_content_update_event, content_title: content_block_title) | ||
HostContentUpdateEvent.expects(:all_for_date_window).at_least_once.returns([host_content_update_event]) | ||
end | ||
|
||
Then(/^I should see an entry for the content block "([^"]*)" on the (current|previous) edition$/) do |content_block, current_or_previous| | ||
selector = current_or_previous == "current" ? ".app-view-editions__current-edition-entries" : ".app-view-editions__previous-edition-entries" | ||
|
||
within selector do | ||
assert_text "Content Block Update" | ||
assert_text "#{content_block} updated" | ||
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
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 |