Skip to content

Commit

Permalink
show errors if confirm not checked on review page
Browse files Browse the repository at this point in the history
Because this is not an active record error we have
to have some custom behaviour here.
  • Loading branch information
Harriethw committed Dec 4, 2024
1 parent bd116fa commit 0e1fceb
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def edit_draft

def review
@content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id])
@review_errors = [REVIEW_ERROR.new(attribute: "is_confirmed", full_message: "Confirm details are correct")]

render :review
end
Expand Down Expand Up @@ -119,8 +120,17 @@ def schedule_or_publish
render "content_block_manager/content_block/editions/workflow/schedule_publishing"
end

REVIEW_ERROR = Data.define(:attribute, :full_message)
def publish
if params[:step] == NEW_BLOCK_STEPS[:review] && params[:is_confirmed].blank?
raise StandardError
end

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)
rescue StandardError
@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"
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
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,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 @@ -432,6 +436,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 0e1fceb

Please sign in to comment.