Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content modelling/832 notes on timeline #9852

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@

.timeline__date {
@include govuk-font($size: 16);
margin-top: govuk-spacing(1);
margin-bottom: 0;
}

.timeline__description {
Expand Down Expand Up @@ -80,3 +78,9 @@
padding-left: 0;
}
}

.timeline__note {
.govuk-body {
margin-bottom: govuk-spacing(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@
<% end %>
</div>
<% end %>

<div>
<% if item[:internal_change_note].present? %>
<div class="timeline__note">
<h2 class="timeline__title">Internal note</h2>
<p class="govuk-body"><%= item[:internal_change_note] %></p>
</div>
<% end %>

<% if item[:change_note].present? %>
<div class="timeline__note">
<h2 class="timeline__title">Public note</h2>
<p class="govuk-body"><%= item[:change_note] %></p>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def items
byline: User.find_by_id(version.whodunnit)&.then { |user| helpers.linked_author(user, { class: "govuk-link" }) } || "unknown user",
date: time_html(version.created_at),
table_rows: table_rows(version),
internal_change_note: internal_change_note(version),
change_note: change_note(version),
}
end
end
Expand Down Expand Up @@ -47,4 +49,12 @@ def table_rows(version)
end
end
end

def internal_change_note(version)
version.item.internal_change_note
end

def change_note(version)
version.item.change_note
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Feature: Edit a content object
Then the edition should have been updated successfully
And I should be taken back to the document page
And I should see 2 publish events on the timeline
And I should see the notes on the timeline
And I should see the edition diff in a table

Scenario: GDS editor cancels the creation of an object when reviewing links
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
expect(page).to have_selector(".timeline__title", text: "Email address published", count:)
end

Then("I should see the notes on the timeline") do
expect(page).to have_selector("p", text: @internal_note)
expect(page).to have_selector("p", text: @change_note)
end

Then("I should see the publish event on the timeline") do
expect(page).to have_selector(".timeline__title", text: "Email address published")
expect(page).to have_selector(".timeline__byline", text: "by Scheduled Publishing Robot")
Expand Down
6 changes: 4 additions & 2 deletions lib/engines/content_block_manager/features/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ def update_content_block
end

def add_internal_note
fill_in "Describe the change for internal users", with: "Some internal note goes here"
@internal_note = "Some internal note goes here"
fill_in "Describe the change for internal users", with: @internal_note
click_save_and_continue
end

def add_change_note
@change_note = "Some text"
choose "Yes - information has been added, updated or removed"
fill_in "Describe the edit for users", with: "Some text"
fill_in "Describe the edit for users", with: @change_note
click_save_and_continue
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,52 @@ class ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineCompone
include Rails.application.routes.url_helpers
include ActionView::Helpers::UrlHelper
include ApplicationHelper
extend Minitest::Spec::DSL

let(:user) { create(:user) }

test "renders a timeline component with events in correct order" do
@user = create(:user)
@version_1 = create(
item = build(:content_block_edition, :email_address, change_note: nil, internal_change_note: nil)
version_1 = create(
:content_block_version,
event: "created",
whodunnit: @user.id,
whodunnit: user.id,
item:,
)
@version_2 = create(
version_2 = create(
:content_block_version,
event: "updated",
whodunnit: @user.id,
whodunnit: user.id,
state: "published",
item:,
)
@version_3 = create(
version_3 = create(
:content_block_version,
event: "updated",
whodunnit: @user.id,
whodunnit: user.id,
state: "scheduled",
item:,
)

render_inline(ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineComponent.new(
content_block_versions: [@version_3, @version_2, @version_1],
content_block_versions: [version_3, version_2, version_1],
))

assert_selector ".timeline__item", count: 2

assert_equal "Email address scheduled", page.all(".timeline__title")[0].text
assert_equal "by #{linked_author(@user, { class: 'govuk-link' })}", page.all(".timeline__byline")[0].native.inner_html
assert_equal I18n.l(@version_3.created_at, format: :long_ordinal),
page.all("time[datetime='#{@version_3.created_at.iso8601}']")[1].text
assert_equal "by #{linked_author(user, { class: 'govuk-link' })}", page.all(".timeline__byline")[0].native.inner_html
assert_equal I18n.l(version_3.created_at, format: :long_ordinal),
page.all("time[datetime='#{version_3.created_at.iso8601}']")[1].text

assert_equal "Email address published", page.all(".timeline__title")[1].text
assert_equal "by #{linked_author(@user, { class: 'govuk-link' })}", page.all(".timeline__byline")[1].native.inner_html
assert_equal I18n.l(@version_2.created_at, format: :long_ordinal),
page.all("time[datetime='#{@version_2.created_at.iso8601}']")[1].text
assert_equal "by #{linked_author(user, { class: 'govuk-link' })}", page.all(".timeline__byline")[1].native.inner_html
assert_equal I18n.l(version_2.created_at, format: :long_ordinal),
page.all("time[datetime='#{version_2.created_at.iso8601}']")[1].text

assert_no_selector ".govuk-table"
assert_no_selector "h2", text: "Internal note"
assert_no_selector "h2", text: "Public note"
end

test "renders the edition diff table in correct order" do
Expand All @@ -62,17 +70,16 @@ class ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineCompone
"previous_value": "old instructions",
},
]
@user = create(:user)
@version = create(
version = create(
:content_block_version,
event: "updated",
whodunnit: @user.id,
whodunnit: user.id,
state: "scheduled",
field_diffs: field_diffs,
)

render_inline(ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineComponent.new(
content_block_versions: [@version],
content_block_versions: [version],
))

assert_equal "old title", page.all("td")[0].text
Expand All @@ -82,4 +89,36 @@ class ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineCompone
assert_equal "old instructions", page.all("td")[4].text
assert_equal "new instructions", page.all("td")[5].text
end

test "renders an internal change note" do
edition = create(:content_block_edition, :email_address, internal_change_note: "changed x to y")
version = create(
:content_block_version,
item: edition,
event: "updated",
state: "published",
)

render_inline(ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineComponent.new(
content_block_versions: [version],
))

assert_selector "p", text: "changed x to y"
end

test "renders a public change note" do
edition = create(:content_block_edition, :email_address, change_note: "changed a to b")
version = create(
:content_block_version,
item: edition,
event: "updated",
state: "published",
)

render_inline(ContentBlockManager::ContentBlock::Document::Show::DocumentTimelineComponent.new(
content_block_versions: [version],
))

assert_selector "p", text: "changed a to b"
end
end