Skip to content

Commit

Permalink
Merge pull request #9821 from alphagov/content-modelling/819-cancel-bug
Browse files Browse the repository at this point in the history
content-modelling/819 fix cancel button for reschedule form
  • Loading branch information
Harriethw authored Jan 22, 2025
2 parents 4505971 + 9869a4d commit 409ba6a
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ContentBlockManager::Shared::CancelAndDeleteButtonComponent < ViewComponent::Base
def initialize(url:)
@url = url
end

private

attr_reader :url
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
is_scheduled_param = params["schedule_publishing"]
%>

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

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
Expand All @@ -26,7 +26,7 @@
name: "schedule_publishing",
id: "schedule_publishing",
heading_size: "xl",
error_items: errors_for(@content_block_edition.errors, :schedule_publishing),
error_items: helpers.errors_for(content_block_edition.errors, :schedule_publishing),
items: [
{
value: "now",
Expand All @@ -48,7 +48,7 @@
date_heading: "Date",
date_hint: "For example, 01 08 2025",
time_hint: "For example, 09:30 or 19:30",
error_items: errors_for(@content_block_edition.errors, :scheduled_publication),
error_items: helpers.errors_for(content_block_edition.errors, :scheduled_publication),
year: {
value: year_param.blank? ? nil : year_param.to_i,
id: "scheduled_at_scheduled_publication_1i",
Expand Down Expand Up @@ -96,13 +96,22 @@
<% end %>
</div>
<div>
<%= render partial: "content_block_manager/content_block/shared/cancel_delete_button",
locals: {
url: content_block_manager.content_block_manager_content_block_edition_path(
@content_block_edition,
redirect_path: content_block_manager.content_block_manager_content_block_document_path(@content_block_edition.document),
),
} %>
<% if is_rescheduling %>
<%= render "govuk_publishing_components/components/button", {
text: "Cancel",
name: "Cancel",
value: "Cancel",
href: back_link,
secondary_solid: true,
} %>
<% else %>
<%= render ContentBlockManager::Shared::CancelAndDeleteButtonComponent.new(url: helpers.content_block_manager.
content_block_manager_content_block_edition_path(
content_block_edition, redirect_path:
helpers.content_block_manager.content_block_manager_content_block_document_path(content_block_edition.document)
),
) %>
<% end %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class ContentBlockManager::Shared::SchedulePublishingComponent < ViewComponent::Base
def initialize(content_block_edition:, params:, context:, back_link:, form_url:, is_rescheduling:)
@content_block_edition = content_block_edition
@params = params
@context = context
@back_link = back_link
@form_url = form_url
@is_rescheduling = is_rescheduling
end

private

attr_reader :is_rescheduling, :content_block_edition, :params, :context, :back_link, :form_url
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<%= render "content_block_manager/content_block/shared/schedule_publishing", {
context: "Edit a content block",
back_link: content_block_manager.content_block_manager_content_block_document_path(id: @content_block_edition.document.id),
form_url: content_block_manager.content_block_manager_content_block_document_update_schedule_path(document_id: @content_block_edition.document.id),
} %>
<%=
render ContentBlockManager::Shared::SchedulePublishingComponent.new(
context: "Edit a content block",
content_block_edition: @content_block_edition,
params:,
back_link: content_block_manager.content_block_manager_content_block_document_path(id: @content_block_edition.document.id),
form_url: content_block_manager.content_block_manager_content_block_document_update_schedule_path(document_id: @content_block_edition.document.id),
is_rescheduling: true,
)
%>
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@
<% end %>
</div>
<div>
<%= render partial: "content_block_manager/content_block/shared/cancel_delete_button",
locals: {
url: content_block_manager.content_block_manager_content_block_edition_path(@content_block_edition),
} %>
<%= render ContentBlockManager::Shared::CancelAndDeleteButtonComponent.new(url: content_block_manager.
content_block_manager_content_block_edition_path(@content_block_edition),
) %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@
type: "submit",
} %>
<% end %>
<%= render partial: "content_block_manager/content_block/shared/cancel_delete_button",
locals: {
url: content_block_manager.content_block_manager_content_block_edition_path(
@content_block_edition,
redirect_path: content_block_manager.content_block_manager_content_block_document_path(@content_block_edition.document),
),
} %>
<%= render ContentBlockManager::Shared::CancelAndDeleteButtonComponent.new(url: content_block_manager.
content_block_manager_content_block_edition_path(
@content_block_edition, redirect_path:
content_block_manager.content_block_manager_content_block_document_path(@content_block_edition.document)
),
) %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<%= render "content_block_manager/content_block/shared/schedule_publishing", {
context:,
back_link: content_block_manager.content_block_manager_content_block_workflow_path(
edition_id: @content_block_edition.id,
step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_links],
),
form_url: content_block_manager.content_block_manager_content_block_workflow_path(
edition_id: @content_block_edition.id,
step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:schedule_publishing],
),
} %>
<%=
render ContentBlockManager::Shared::SchedulePublishingComponent.new(
content_block_edition: @content_block_edition,
params:,
context:,
back_link: content_block_manager.content_block_manager_content_block_workflow_path(
edition_id: @content_block_edition.id,
step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:review_links],
),
form_url: content_block_manager.content_block_manager_content_block_workflow_path(
edition_id: @content_block_edition.id,
step: ContentBlockManager::ContentBlock::Editions::WorkflowController::UPDATE_BLOCK_STEPS[:schedule_publishing],
),
is_rescheduling: false,
)
%>
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ Feature: Schedule a content object
And I click to edit the schedule
And I save and continue
Then I should see an error message telling me that schedule publishing cannot be blank

@disable-sidekiq-test-mode
Scenario: GDS editor cancels the rescheduling of an object
When I am updating a content block
Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
When I review and confirm my answers are correct
When I click to view the content block
And I click to edit the schedule
And I click the cancel link
Then I should be taken back to the document page
And no draft Content Block Edition has been created
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
click_button "Cancel"
end

Then(/^I click on page ([^"]*)$/) do |page_number|
click_link page_number
When("I click the cancel link") do
click_link "Cancel"
end

When("I click on page ") do
click_button "Cancel"
Then(/^I click on page ([^"]*)$/) do |page_number|
click_link page_number
end

When("I click to view results") do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "test_helper"

class ContentBlockManager::Shared::CancelAndDeleteButtonComponentTest < ViewComponent::TestCase
extend Minitest::Spec::DSL

let(:url) { "/url" }

let(:cancel_and_delete_component) do
ContentBlockManager::Shared::CancelAndDeleteButtonComponent.new(url:)
end

it "renders the delete form with given url" do
render_inline(cancel_and_delete_component)

assert_selector "form[action='#{url}']" do
assert_selector "button[value='delete']", text: "Cancel"
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
require "test_helper"

class ContentBlockManager::Shared::SchedulePublishingComponentTest < ViewComponent::TestCase
extend Minitest::Spec::DSL
include ContentBlockManager::Engine.routes.url_helpers

let(:content_block_document) { create(:content_block_document, :email_address) }
let(:content_block_edition) { create(:content_block_edition, :email_address, document: content_block_document) }
let(:params) { {} }
let(:context) { "Some context" }
let(:back_link) { "/back-link" }
let(:form_url) { "/form-url" }

let(:rescheduling_component) do
ContentBlockManager::Shared::SchedulePublishingComponent.new(
content_block_edition:,
params:,
context:,
back_link:,
form_url:,
is_rescheduling: true,
)
end

let(:component) do
ContentBlockManager::Shared::SchedulePublishingComponent.new(
content_block_edition:,
params:,
context:,
back_link:,
form_url:,
is_rescheduling: false,
)
end

describe "when edition is being rescheduled" do
it "renders the cancel button with back link" do
render_inline(rescheduling_component)

assert_selector "a[href='#{back_link}']", text: "Cancel"
end
end

describe "when edition is not being rescheduled" do
it "renders the cancel button with delete form" do
render_inline(component)

assert_selector ".govuk-button", text: "Cancel"
assert_selector "form[action='#{content_block_manager_content_block_edition_path(
content_block_edition,
redirect_path: content_block_manager_content_block_document_path(content_block_edition.document),
)}']"
end
end
end

0 comments on commit 409ba6a

Please sign in to comment.