Skip to content

Commit

Permalink
Merge pull request #9697 from alphagov/content-modelling/719-with-che…
Browse files Browse the repository at this point in the history
…ckbox-confirm-error

show errors if confirm not checked on review page
  • Loading branch information
Harriethw authored Dec 5, 2024
2 parents 470822c + 1252dd2 commit 98a0fa6
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,15 @@ def schedule_or_publish
render "content_block_manager/content_block/editions/workflow/schedule_publishing"
end

REVIEW_ERROR = Data.define(:attribute, :full_message)
def publish
new_edition = ContentBlockManager::PublishEditionService.new.call(@content_block_edition)
redirect_to content_block_manager.content_block_manager_content_block_workflow_path(id: new_edition.id, step: :confirmation)
if params[:step] == NEW_BLOCK_STEPS[:review] && params[:is_confirmed].blank?
@confirm_error_copy = "Confirm details are correct"
@error_summary_errors = [{ text: @confirm_error_copy, href: "#is_confirmed-0" }]
render "content_block_manager/content_block/editions/workflow/review"
else
new_edition = ContentBlockManager::PublishEditionService.new.call(@content_block_edition)
redirect_to content_block_manager.content_block_manager_content_block_workflow_path(id: new_edition.id, step: :confirmation)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
} %>
<% end %>

<% if @error_summary_errors %>
<%= render "govuk_publishing_components/components/error_summary", {
title: "There is a problem",
items: @error_summary_errors,
} %>
<% end %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<%= render(
Expand All @@ -16,9 +23,28 @@
</div>
</div>

<%= form_with(url: content_block_manager.content_block_manager_content_block_workflow_path(@content_block_edition, step: ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:review]), method: :put) do %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<%= render "govuk_publishing_components/components/checkboxes", {
name: "is_confirmed",
id: "is_confirmed",
heading: "Confirm",
visually_hide_heading: true,
no_hint_text: true,
error: @confirm_error_copy,
items: [
{
label: "By creating this content block you are confirming that, to the best of your knowledge, the details you are providing are correct.",
value: true,
},
],
} %>
</div>
</div>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<%= form_with(url: content_block_manager.content_block_manager_content_block_workflow_path(@content_block_edition, step: ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:review]), method: :put) do %>
<div class="govuk-button-group govuk-!-margin-bottom-6">
<div>
<%= render "govuk_publishing_components/components/button", {
Expand Down
15 changes: 15 additions & 0 deletions lib/engines/content_block_manager/features/create_object.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Feature: Create a content object
| title | email_address | department | organisation | instructions_to_publishers |
| my email address | foo@example.com | Somewhere | Ministry of Example | this is important |
Then I am asked to review my answers
And I confirm my answers are correct
When I click confirm
Then the edition should have been created successfully
And I should be taken to the confirmation page for a new block
Expand Down Expand Up @@ -52,6 +53,19 @@ Feature: Create a content object
| my email address | xxxxx | Somewhere | Ministry of Example |
Then I should see a message that the "email_address" field is an invalid "email"

Scenario: GDS editor sees validation errors for unconfirmed answers
When I visit the Content Block Manager home page
And I click to create an object
Then I should see all the schemas listed
When I click on the "email_address" schema
Then I should see a form for the schema
When I complete the form with the following fields:
| title | email_address | department | organisation |
| my email address | foo@example.com | Somewhere | Ministry of Example |
Then I am asked to review my answers
When I click confirm
Then I should see a message that I need to confirm the details are correct

Scenario: GDS editor does not see error when not providing instructions to publishers
When I visit the Content Block Manager home page
And I click to create an object
Expand Down Expand Up @@ -86,6 +100,7 @@ Feature: Create a content object
| title |
| my email address 2 |
Then I am asked to review my answers
And I confirm my answers are correct
When I click confirm
Then the edition should have been created successfully
And I should be taken to the confirmation page for a new block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def has_support_button
end

When("I should be taken to the scheduled confirmation page") do
assert_text "Email address scheduled to publish on #{@future_date.strftime('%e %B %Y%l:%M%P').strip}"
assert_text "Email address scheduled to publish on"
assert_text "You can now view the updated schedule of the content block."

expect(page).to have_link(
Expand Down Expand Up @@ -429,6 +429,10 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
assert_text "#{ContentBlockManager::ContentBlock::Edition.human_attribute_name("details_#{field_name}")} is an invalid #{format.titleize}"
end

Then("I should see a message that I need to confirm the details are correct") do
assert_text "Confirm details are correct", minimum: 2
end

Then("I should see a permissions error") do
assert_text "Permissions error"
end
Expand Down Expand Up @@ -456,6 +460,10 @@ def should_show_edit_form_for_email_address_content_block(document_title, email_
assert_text "Review email address"
end

Then("I confirm my answers are correct") do
check "By creating this content block you are confirming that, to the best of your knowledge, the details you are providing are correct."
end

Then("I accept and publish") do
click_on "Accept and publish"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,23 @@ class ContentBlockManager::ContentBlock::WorkflowTest < ActionDispatch::Integrat
describe "#update" do
it "posts the new edition to the Publishing API and marks edition as published" do
assert_edition_is_published do
put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:)
put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:, is_confirmed: true)
end
end
end
end

describe "when the edition details have not been confirmed" do
let(:step) { ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:review] }

describe "#update" do
it "returns to the review page" do
put content_block_manager.content_block_manager_content_block_workflow_path(id: edition.id, step:)

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

describe "when updating an existing content block" do
Expand Down

0 comments on commit 98a0fa6

Please sign in to comment.