From 2c14e5b796716ea7781990894fa697b02806c7e2 Mon Sep 17 00:00:00 2001 From: Harriet H-W Date: Wed, 20 Nov 2024 17:26:05 +0000 Subject: [PATCH 1/3] add edit functionality to create flow users should be able to go back and edit their answers from the 'check your answers' page in the new edition journey. --- .../show/confirm_summary_list_component.rb | 15 +++++++++++++++ .../editions/workflow_controller.rb | 13 +++++++++++++ .../content_block/edition_form.rb | 2 +- .../features/create_object.feature | 17 +++++++++++++++++ .../content_block_manager_steps.rb | 17 +++++++++++------ .../show/confirm_summary_list_component_test.rb | 2 ++ 6 files changed, 59 insertions(+), 7 deletions(-) diff --git a/lib/engines/content_block_manager/app/components/content_block_manager/content_block_edition/show/confirm_summary_list_component.rb b/lib/engines/content_block_manager/app/components/content_block_manager/content_block_edition/show/confirm_summary_list_component.rb index b59b3fd2d37..c32b16412e5 100644 --- a/lib/engines/content_block_manager/app/components/content_block_manager/content_block_edition/show/confirm_summary_list_component.rb +++ b/lib/engines/content_block_manager/app/components/content_block_manager/content_block_edition/show/confirm_summary_list_component.rb @@ -9,6 +9,7 @@ def initialize(content_block_edition:) def items [ + edit_item, *details_items, organisation_item, instructions_item, @@ -17,6 +18,13 @@ def items ] end + def edit_item + { + field: "#{content_block_edition.document.block_type.humanize} details", + edit: edit_action, + } + end + def details_items content_block_edition.details.map do |key, value| { @@ -53,4 +61,11 @@ def date_item value: I18n.l(content_block_edition.created_at.to_date, format: :long_ordinal), } end + + def edit_action + { + href: helpers.content_block_manager.content_block_manager_content_block_workflow_path(id: content_block_edition.id, step: ContentBlockManager::ContentBlock::Editions::WorkflowController::NEW_BLOCK_STEPS[:edit_draft]), + link_text: "Edit", + } + end end diff --git a/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions/workflow_controller.rb b/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions/workflow_controller.rb index cd51b4d5d49..0e1aab47697 100644 --- a/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions/workflow_controller.rb +++ b/lib/engines/content_block_manager/app/controllers/content_block_manager/content_block/editions/workflow_controller.rb @@ -1,6 +1,7 @@ class ContentBlockManager::ContentBlock::Editions::WorkflowController < ContentBlockManager::BaseController NEW_BLOCK_STEPS = { review: "review", + edit_draft: "edit_draft", }.freeze UPDATE_BLOCK_STEPS = { @@ -18,6 +19,8 @@ def show @schema = ContentBlockManager::ContentBlock::Schema.find_by_block_type(@content_block_edition.document.block_type) case step + when NEW_BLOCK_STEPS[:edit_draft] + edit_draft when UPDATE_BLOCK_STEPS[:review_links] review_links when UPDATE_BLOCK_STEPS[:schedule_publishing] @@ -46,6 +49,16 @@ def update private + def edit_draft + @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id]) + @form = ContentBlockManager::ContentBlock::EditionForm.for( + content_block_edition: @content_block_edition, + schema: @schema, + ) + + render "content_block_manager/content_block/editions/new" + end + def review @content_block_edition = ContentBlockManager::ContentBlock::Edition.find(params[:id]) diff --git a/lib/engines/content_block_manager/app/forms/content_block_manager/content_block/edition_form.rb b/lib/engines/content_block_manager/app/forms/content_block_manager/content_block/edition_form.rb index 61d74d14ee5..1f6619714f3 100644 --- a/lib/engines/content_block_manager/app/forms/content_block_manager/content_block/edition_form.rb +++ b/lib/engines/content_block_manager/app/forms/content_block_manager/content_block/edition_form.rb @@ -7,7 +7,7 @@ class ContentBlockManager::ContentBlock::EditionForm attr_reader :content_block_edition, :schema def self.for(content_block_edition:, schema:) - content_block_edition.document&.id ? Update.new(content_block_edition:, schema:) : Create.new(content_block_edition:, schema:) + content_block_edition.document&.latest_edition_id ? Update.new(content_block_edition:, schema:) : Create.new(content_block_edition:, schema:) end def initialize(content_block_edition:, schema:) diff --git a/lib/engines/content_block_manager/features/create_object.feature b/lib/engines/content_block_manager/features/create_object.feature index ac690144873..f62f6f7f519 100644 --- a/lib/engines/content_block_manager/features/create_object.feature +++ b/lib/engines/content_block_manager/features/create_object.feature @@ -72,6 +72,23 @@ Feature: Create a content object And no draft Content Block Edition has been created And no draft Content Block Document has been created + Scenario: GDS editor edits answers during creation of an object + When I visit the Content Block Manager home page + And I click to create an object + When I click on the "email_address" 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 check my answers + When I click the first edit link + And I complete the form with the following fields: + | title | + | my email address 2 | + Then I am asked to check my answers + When I accept and publish + Then the edition should have been created successfully + And I should be taken to the confirmation page + Scenario: Draft documents are not listed When I visit the Content Block Manager home page And I click to create an object diff --git a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb index c590097b5d9..29abe05c442 100644 --- a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb @@ -108,11 +108,11 @@ @instructions_to_publishers = fields.delete("instructions_to_publishers") @details = fields - fill_in "Title", with: @title + fill_in "Title", with: @title if @title.present? - select @organisation, from: "content_block/edition_lead_organisation" + select @organisation, from: "content_block/edition_lead_organisation" if @organisation.present? - fill_in "Instructions to publishers", with: @instructions_to_publishers + fill_in "Instructions to publishers", with: @instructions_to_publishers if @instructions_to_publishers.present? fields.keys.each do |k| fill_in "content_block_manager/content_block/edition_details_#{k}", with: @details[k] @@ -138,9 +138,10 @@ assert_not_nil edition assert_not_nil edition.document - assert_equal @title, edition.title - assert_equal @instructions_to_publishers, edition.instructions_to_publishers, - @details.keys.each do |k| + assert_equal @title, edition.title if @title.present? + assert_equal @instructions_to_publishers, edition.instructions_to_publishers if @instructions_to_publishers.present? + + @details.keys.each do |k| assert_equal edition.details[k], @details[k] end end @@ -317,6 +318,10 @@ first_link.click end +When("I click the first edit link") do + click_link "Edit" +end + Then("I should see the edit form") do should_show_edit_form_for_email_address_content_block( @content_block.document.title, diff --git a/lib/engines/content_block_manager/test/components/content_block/edition/show/confirm_summary_list_component_test.rb b/lib/engines/content_block_manager/test/components/content_block/edition/show/confirm_summary_list_component_test.rb index eabe36e12f7..f660e234ebd 100644 --- a/lib/engines/content_block_manager/test/components/content_block/edition/show/confirm_summary_list_component_test.rb +++ b/lib/engines/content_block_manager/test/components/content_block/edition/show/confirm_summary_list_component_test.rb @@ -30,6 +30,8 @@ class ContentBlockManager::ContentBlockEdition::Show::ConfirmSummaryListComponen content_block_edition:, )) + assert_selector ".govuk-summary-list__key", text: "Email address details" + assert_selector ".govuk-summary-list__actions", text: "Edit" assert_selector ".govuk-summary-list__key", text: "New interesting fact" assert_selector ".govuk-summary-list__value", text: "value of fact" assert_selector ".govuk-summary-list__key", text: "Lead organisation" From f68e860368699f9e3aec4c9b6f77adae91e6f059 Mon Sep 17 00:00:00 2001 From: Harriet H-W Date: Wed, 20 Nov 2024 17:28:47 +0000 Subject: [PATCH 2/3] refactor edit button on view of Content Block show just one edit action according to design --- .../document/show/summary_list_component.rb | 14 +++++++++----- .../features/edit_object.feature | 10 +++++----- .../content_block_manager_steps.rb | 8 +------- .../document/show/summary_list_component_test.rb | 12 +++++++----- .../content_block/edition_form_test.rb | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/summary_list_component.rb b/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/summary_list_component.rb index 843e9d6a098..9c55345740c 100644 --- a/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/summary_list_component.rb +++ b/lib/engines/content_block_manager/app/components/content_block_manager/content_block/document/show/summary_list_component.rb @@ -9,6 +9,7 @@ def initialize(content_block_document:) def items [ + edit_item, title_item, *details_items, organisation_item, @@ -20,6 +21,13 @@ def items ].compact end + def edit_item + { + field: "#{content_block_document.block_type.humanize} details", + edit: edit_action, + } + end + def embed_code_item { field: "Embed code", @@ -35,7 +43,6 @@ def title_item { field: "Title", value: content_block_document.title, - edit: edit_action, } end @@ -43,7 +50,6 @@ def organisation_item { field: "Lead organisation", value: content_block_document.latest_edition.lead_organisation, - edit: edit_action, } end @@ -51,7 +57,6 @@ def instructions_item { field: "Instructions to publishers", value: content_block_document.latest_edition.instructions_to_publishers.presence || "None", - edit: edit_action, } end @@ -60,7 +65,6 @@ def details_items { field: key.humanize, value:, - edit: edit_action, } end end @@ -95,7 +99,7 @@ def scheduled_item def edit_action { href: helpers.content_block_manager.new_content_block_manager_content_block_document_edition_path(content_block_document), - link_text: "Change", + link_text: "Edit", } end end diff --git a/lib/engines/content_block_manager/features/edit_object.feature b/lib/engines/content_block_manager/features/edit_object.feature index f53c03e129e..1e1e0e7a051 100644 --- a/lib/engines/content_block_manager/features/edit_object.feature +++ b/lib/engines/content_block_manager/features/edit_object.feature @@ -13,7 +13,7 @@ Feature: Edit a content object Then I should see the details for all documents When I click to view the document Then I should see the details for the email address content block - When I click the first change link + When I click the first edit link Then I should see the edit form And I should see a back link to the document page When I fill out the form @@ -33,7 +33,7 @@ Feature: Edit a content object Scenario: GDS editor cancels the creation of an object when reviewing links When I visit the Content Block Manager home page When I click to view the document - When I click the first change link + When I click the first edit link Then I should see the edit form When I fill out the form Then I am shown where the changes will take place @@ -44,7 +44,7 @@ Feature: Edit a content object Scenario: GDS editor cancels the creation of an object before publishing When I visit the Content Block Manager home page When I click to view the document - When I click the first change link + When I click the first edit link Then I should see the edit form When I fill out the form Then I am shown where the changes will take place @@ -61,7 +61,7 @@ Feature: Edit a content object And an email address content block has been created When I visit the Content Block Manager home page When I click to view the document - When I click the first change link + When I click the first edit link And I set all fields to blank Then I should see errors for the required fields @@ -72,7 +72,7 @@ Feature: Edit a content object And an email address content block has been created When I visit the Content Block Manager home page When I click to view the document - When I click the first change link + When I click the first edit link When I complete the form with the following fields: | title | email_address | organisation | | my email address | xxxxx | Ministry of Example | diff --git a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb index 29abe05c442..e8062f95129 100644 --- a/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb +++ b/lib/engines/content_block_manager/features/step_definitions/content_block_manager_steps.rb @@ -313,11 +313,6 @@ ) end -When("I click the first change link") do - first_link = find("a[href='#{content_block_manager.new_content_block_manager_content_block_document_edition_path(@content_block.document)}']", match: :first) - first_link.click -end - When("I click the first edit link") do click_link "Edit" end @@ -359,7 +354,7 @@ def should_show_summary_card_for_email_address_content_block(document_title, ema def should_show_summary_list_for_email_address_content_block(document_title, email_address, organisation, instructions_to_publishers = nil) expect(page).to have_selector(".govuk-summary-list__key", text: "Title") expect(page).to have_selector(".govuk-summary-list__value", text: document_title) - expect(page).to have_selector(".govuk-summary-list__actions", text: "Change") + expect(page).to have_selector(".govuk-summary-list__actions", text: "Edit") expect(page).to have_selector(".govuk-summary-list__key", text: "Email address") expect(page).to have_selector(".govuk-summary-list__value", text: email_address) expect(page).to have_selector(".govuk-summary-list__key", text: "Lead organisation") @@ -370,7 +365,6 @@ def should_show_summary_list_for_email_address_content_block(document_title, ema end expect(page).to have_selector(".govuk-summary-list__key", text: "Last updated") expect(page).to have_selector(".govuk-summary-list__value", text: @user.name) - expect(page).to have_selector(".govuk-summary-list__actions", text: "Change") end def should_show_edit_form_for_email_address_content_block(document_title, email_address) diff --git a/lib/engines/content_block_manager/test/components/content_block/document/show/summary_list_component_test.rb b/lib/engines/content_block_manager/test/components/content_block/document/show/summary_list_component_test.rb index cbe8177bb14..ff64b6614f7 100644 --- a/lib/engines/content_block_manager/test/components/content_block/document/show/summary_list_component_test.rb +++ b/lib/engines/content_block_manager/test/components/content_block/document/show/summary_list_component_test.rb @@ -21,18 +21,20 @@ class ContentBlockManager::ContentBlock::Document::Show::SummaryListComponentTes it "renders a published content block correctly" do render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryListComponent.new(content_block_document:)) - assert_selector ".govuk-summary-list__row", count: 8 + assert_selector ".govuk-summary-list__row", count: 9 + assert_selector ".govuk-summary-list__actions", count: 1 + + assert_selector ".govuk-summary-list__key", text: "Email address details" + assert_selector ".govuk-summary-list__actions", text: "Edit" + assert_selector ".govuk-summary-list__key", text: "Title" assert_selector ".govuk-summary-list__value", text: content_block_document.title - assert_selector ".govuk-summary-list__actions", text: "Change" assert_selector ".govuk-summary-list__key", text: "Foo" assert_selector ".govuk-summary-list__value", text: "bar" - assert_selector ".govuk-summary-list__actions", text: "Change" assert_selector ".govuk-summary-list__key", text: "Something" assert_selector ".govuk-summary-list__value", text: "else" - assert_selector ".govuk-summary-list__actions", text: "Change" assert_selector ".govuk-summary-list__key", text: "Lead organisation" assert_selector ".govuk-summary-list__value", text: "Department for Example" @@ -57,7 +59,7 @@ class ContentBlockManager::ContentBlock::Document::Show::SummaryListComponentTes render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryListComponent.new(content_block_document:)) - assert_selector ".govuk-summary-list__row", count: 9 + assert_selector ".govuk-summary-list__row", count: 10 assert_selector ".govuk-summary-list__key", text: "Scheduled for publication at" assert_selector ".govuk-summary-list__value", text: I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal) diff --git a/lib/engines/content_block_manager/test/unit/app/forms/content_block_manager/content_block/edition_form_test.rb b/lib/engines/content_block_manager/test/unit/app/forms/content_block_manager/content_block/edition_form_test.rb index 6350203030e..d3766e02242 100644 --- a/lib/engines/content_block_manager/test/unit/app/forms/content_block_manager/content_block/edition_form_test.rb +++ b/lib/engines/content_block_manager/test/unit/app/forms/content_block_manager/content_block/edition_form_test.rb @@ -13,8 +13,8 @@ class ContentBlockManager::ContentBlock::EditionFormTest < ActiveSupport::TestCa ) end - describe "when initialized for an edition with an existing document" do - let(:content_block_document) { build(:content_block_document, id: 123) } + describe "when initialized for an edition with an existing document and live edition" do + let(:content_block_document) { build(:content_block_document, :email_address, id: 123, latest_edition_id: "5b271577-3d3d-475d-986a-246d8c4063a3") } let(:content_block_edition) { build(:content_block_edition, :email_address, document: content_block_document) } let(:result) do From a3403f87fe6533b3f2acf1831672c576bed897f8 Mon Sep 17 00:00:00 2001 From: Harriet H-W Date: Thu, 21 Nov 2024 11:52:37 +0000 Subject: [PATCH 3/3] add Details heading to Content Block view --- .../content_block/documents/show.html.erb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/documents/show.html.erb b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/documents/show.html.erb index a0514c37647..eb3879fadcc 100644 --- a/lib/engines/content_block_manager/app/views/content_block_manager/content_block/documents/show.html.erb +++ b/lib/engines/content_block_manager/app/views/content_block_manager/content_block/documents/show.html.erb @@ -6,11 +6,16 @@ } %> <% end %> -<%= render( - ContentBlockManager::ContentBlock::Document::Show::SummaryListComponent.new( - content_block_document: @content_block_document, - ), - ) %> +
+
+

Details

+ <%= render( + ContentBlockManager::ContentBlock::Document::Show::SummaryListComponent.new( + content_block_document: @content_block_document, + ), + ) %> +
+