Skip to content

Commit

Permalink
Add a change note step
Browse files Browse the repository at this point in the history
This allows the user to select if the change was major and add a change
note if it was.
  • Loading branch information
pezholio committed Jan 23, 2025
1 parent 28f0bd3 commit 31fdc56
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Workflow::ShowMethods
review_links: :review_links,
schedule_publishing: :schedule_publishing,
internal_note: :internal_note,
change_note: :change_note,
review: :review,
review_update: :review_update,
confirmation: :confirmation,
Expand Down Expand Up @@ -51,13 +52,23 @@ def internal_note
render :internal_note
end

def change_note
@content_block_document = @content_block_edition.document
@back_path = content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step: :internal_note,
)

render :change_note
end

def review_update
@content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])

@url = review_update_url
@back_path = content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step: :internal_note,
step: :change_note,
)

render :review
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Workflow::UpdateMethods
review_links: :redirect_to_schedule,
schedule_publishing: :validate_schedule,
internal_note: :update_internal_note,
change_note: :update_change_note,
review_update: :validate_review_page,
review: :validate_review_page,
}.freeze
Expand Down Expand Up @@ -34,10 +35,22 @@ def validate_schedule
def update_internal_note
@content_block_edition.update!(internal_change_note: edition_params[:internal_change_note])

redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
id: @content_block_edition.id,
step: :change_note,
)
end

def update_change_note
@content_block_edition.assign_attributes(change_note: edition_params[:change_note], major_change: edition_params[:major_change])
@content_block_edition.save!(context: :change_note)

redirect_to content_block_manager.content_block_manager_content_block_workflow_path(
id: @content_block_edition.id,
step: :review_update,
)
rescue ActiveRecord::RecordInvalid
render :change_note
end

def validate_review_page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def edition_params
"scheduled_publication(5i)",
:title,
:internal_change_note,
:change_note,
:major_change,
document_attributes: %w[block_type],
details: @schema.permitted_params,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<% content_for :context, context %>
<% content_for :title, "Do users have to know the content has changed?" %>
<% content_for :title_margin_bottom, 4 %>
<% content_for :back_link do %>
<%= render "govuk_publishing_components/components/back_link", {
href: @back_path,
} %>
<% end %>

<% content_for :error_summary, render(Admin::ErrorSummaryComponent.new(object: @content_block_edition)) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with url: content_block_manager.content_block_manager_content_block_workflow_path(
@content_block_edition,
step: :change_note,
), method: :put do %>

<%= render "govuk_publishing_components/components/radio", {
name: "content_block/edition[major_change]",
id: "content_block_manager_content_block_edition_major_change",
error_items: errors_for(@content_block_edition.errors, :major_change),
items: [
{
value: "1",
checked: @content_block_edition.major_change === true,
text: "Yes - information has been added, updated or removed",
hint_text: "A change note will be published on the page and emailed to users subscribed to email alerts. The 'last updated' date will change.",
bold: true,
conditional: render("govuk_publishing_components/components/textarea", {
label: {
text: "Describe the edit for users",
},
name: "content_block/edition[change_note]",
id: "content_block_manager_content_block_edition_change_note",
error_items: errors_for(@content_block_edition.errors, :change_note),
value: @content_block_edition.change_note,
hint: (tag.p('Tell users what has changed, where and why. Write in full sentences, leading with the most important words. For example, "College A has been removed from the registered sponsors list because its licence has been suspended."', class: "govuk-!-margin-bottom-0 govuk-!-margin-top-0") +
link_to("Guidance about change notes (opens in a new tab)", "https://www.gov.uk/guidance/content-design/writing-for-gov-uk#change-notes", target: "_blank", class: "govuk-link", rel: "noopener")).html_safe,
}),
},
{
value: "0",
checked: @content_block_edition.major_change === false,
text: "No - it's a minor edit that does not change the meaning",
hint_text: "This includes fixing a typo or broken link, a style change or similar. Users signed up to email alerts will not get notified and the 'last updated' date will not change.",
bold: true,
},
],
} %>

<div class="govuk-button-group govuk-!-margin-bottom-6">
<%= render "govuk_publishing_components/components/button", {
text: "Save and continue",
name: "save_and_continue",
value: "Save and continue",
type: "submit",
} %>
<%= render "govuk_publishing_components/components/button", {
text: "Cancel",
href: @back_path,
secondary_solid: true,
} %>
</div>
<% end %>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ Feature: Edit a content object
Then I should be on the "internal_note" step
And I should see a back link to the "schedule_publishing" step
When I add an internal note
Then I should be on the "review" step
Then I should be on the "change_note" step
And I should see a back link to the "internal_note" step
When I add a change note
Then I should be on the "review" step
And I should see a back link to the "change_note" step
When I review and confirm my answers are correct
Then I should be taken to the confirmation page for a published block
When I click to view the content block
Expand Down Expand Up @@ -60,6 +63,7 @@ Feature: Edit a content object
And I continue after reviewing the links
When I choose to publish the change now
And I add an internal note
And I add a change note
When I click cancel
Then I am taken back to Content Block Manager home page
And no draft Content Block Edition has been created
Expand Down Expand Up @@ -96,6 +100,7 @@ Feature: Edit a content object
And I continue after reviewing the links
And I choose to publish the change now
And I add an internal note
And I add a change note
Then I am asked to review my answers
When I click publish without confirming my details
Then I should see a message that I need to confirm the details are correct
Expand All @@ -105,12 +110,14 @@ Feature: Edit a content object
When I am updating a content block
And I schedule the change for 7 days in the future
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
When I revisit the edit page
Then I should see a warning telling me there is a scheduled change
When I make the changes
And I choose to publish the change now
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
Then I should be taken to the confirmation page for a published block
When I click to view the content block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Schedule a content object
When I am updating a content block
And I schedule the change for 7 days in the future
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
Expand All @@ -26,6 +27,7 @@ Feature: Schedule a content object
When I am updating a content block
And I schedule the change for 7 days in the future
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
Expand All @@ -40,6 +42,7 @@ Feature: Schedule a content object
When I am updating a content block
And I schedule the change for 7 days in the future
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
Expand All @@ -51,6 +54,7 @@ Feature: Schedule a content object
When I am updating a content block
And I schedule the change for 7 days in the future
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
Expand All @@ -63,6 +67,7 @@ Feature: Schedule a content object
When I am updating a content block
And I schedule the change for 7 days in the future
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Feature: Schedule a content object
When I am updating a content block
And I schedule the change for 7 days in the future
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
And I should be taken to the scheduled confirmation page
When I click to view the content block
Expand All @@ -23,10 +24,12 @@ Feature: Schedule a content object
When I am updating a content block
And I schedule the change for 7 days in the future
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
When I am updating a content block
And I choose to publish the change now
And I save and continue
And I add a change note
When I review and confirm my answers are correct
Then there should be no jobs scheduled

Expand All @@ -35,6 +38,7 @@ Feature: Schedule a content object
When I choose to schedule the change
And the block is scheduled and published
And I add an internal note
And I add a change note
When I review and confirm my answers are correct
Then the published state of the object should be shown
And I should see the publish event on the timeline
Expand Down Expand Up @@ -64,5 +68,6 @@ Feature: Schedule a content object
When I choose to schedule the change
And the block is scheduled and published
And I add an internal note
And I add a change note
And I click cancel
Then I am taken back to Content Block Manager home page
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,12 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
click_save_and_continue
end

When(/^I add a change note$/) do
choose "Yes - information has been added, updated or removed"
fill_in "Describe the edit for users", with: "Some text"
click_save_and_continue
end

def visit_edit_page
visit content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document)
end
Expand Down Expand Up @@ -867,6 +873,8 @@ def click_save_and_continue
should_show_publish_form
when "review"
should_be_on_review_step
when "change_note"
should_be_on_change_note_step
end
end

Expand Down Expand Up @@ -921,3 +929,7 @@ def should_show_publish_form
def should_be_on_review_step
assert_text "Review email address"
end

def should_be_on_change_note_step
assert_text "Do users have to know the content has changed?"
end
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,62 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat

assert_equal edition.reload.internal_change_note, change_note

assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :change_note)
end
end
end

describe "when updating the change note" do
let(:step) { :change_note }

describe "#show" do
it "shows the form" do
get content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:)

assert_template "content_block_manager/content_block/editions/workflow/change_note"
end
end

describe "#update" do
it "adds the note and redirects" do
change_note = "This is my note"
put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:),
params: {
"content_block/edition" => {
"major_change" => "1",
"change_note" => change_note,
},
}

assert_equal edition.reload.change_note, change_note
assert_equal edition.reload.major_change, true

assert_redirected_to content_block_manager_content_block_workflow_path(id: edition.id, step: :review_update)
end

it "shows an error if the change is major and the change note is blank" do
put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:),
params: {
"content_block/edition" => {
"major_change" => "1",
"change_note" => "",
},
}

assert_match(/#{I18n.t('activerecord.errors.models.content_block_manager/content_block/edition.blank', attribute: 'Change note')}/, response.body)
end

it "shows an error if major_change is blank" do
put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:),
params: {
"content_block/edition" => {
"major_change" => "",
"change_note" => "",
},
}

assert_match(/#{I18n.t('activerecord.errors.models.content_block_manager/content_block/edition.attributes.major_change.inclusion')}/, response.body)
end
end
end
end
Expand Down

0 comments on commit 31fdc56

Please sign in to comment.