Skip to content

Commit

Permalink
Merge pull request #9735 from alphagov/content-modelling/748-add-revi…
Browse files Browse the repository at this point in the history
…ew-to-edit

Content modelling/748 add review to edit
  • Loading branch information
Harriethw authored Dec 17, 2024
2 parents e49d424 + 9671e13 commit a416b7c
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def items
*details_items,
organisation_item,
instructions_item,
]
status_item,
].compact
end

def edit_item
Expand Down Expand Up @@ -60,4 +61,22 @@ def edit_action
link_text: "Edit",
}
end

def scheduled_value
I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)
end

def status_item
if content_block_edition.scheduled_publication
{
field: "Scheduled date and time",
value: scheduled_value,
}
elsif content_block_edition.document.editions.count > 1
{
field: "Publish date",
value: I18n.l(Time.zone.today, format: :long_ordinal),
}
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,20 @@ def review_update_url
)
end

def validate_scheduled_edition
@content_block_edition.assign_attributes(scheduled_publication_params)
@content_block_edition.assign_attributes(state: "scheduled")
raise ActiveRecord::RecordInvalid unless @content_block_edition.valid?
end

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

if params[:schedule_publishing].blank?
@content_block_edition.errors.add(:schedule_publishing, "cannot be blank")
raise ActiveRecord::RecordInvalid, @content_block_edition
elsif params[:schedule_publishing] == "schedule"
@content_block_edition.update!(scheduled_publication_params)
@content_block_edition.schedule!
raise ActiveRecord::RecordInvalid, @content_block_edition if @content_block_edition.errors.any?
validate_scheduled_edition
end

@url = review_update_url
Expand Down
14 changes: 13 additions & 1 deletion lib/engines/content_block_manager/features/edit_object.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Feature: Edit a content object
Then I should be taken back to the document page
And no draft Content Block Edition has been created

Scenario: GDS editor cancels the creation of an object before publishing
Scenario: GDS editor cancels the creation of an object before scheduling
When I visit the Content Block Manager home page
When I click to view the document
When I click the first edit link
Expand All @@ -58,6 +58,18 @@ Feature: Edit a content object
Then I should be taken back to the document page
And no draft Content Block Edition has been created

Scenario: GDS editor cancels the creation of an object before confirming answers
When I visit the Content Block Manager home page
When I click to view the document
When I click the first edit link
When I fill out the form
When I save and continue
When I choose to publish the change now
And I save and continue
And I click cancel
Then I am taken back to Content Block Manager home page
And no draft Content Block Edition has been created

Scenario: GDS editor sees validation errors for missing fields
And a schema "email_address" exists with the following fields:
| field | type | format | required |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,11 @@ Feature: Schedule a content object
And I enter a date in the past
And I save and continue
Then I see the errors informing me the date must be in the future

Scenario: GDS Editor cancels after scheduling a block
When I am updating a content block
Then I am asked when I want to publish the change
When I choose to schedule the change
And the block is scheduled and published
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
@@ -1,7 +1,8 @@
require "test_helper"

class ContentBlockManager::ContentBlockEdition::Show::ConfirmSummaryListComponentTest < ViewComponent::TestCase
test "it renders instructions to publishers" do
extend Minitest::Spec::DSL
it "it renders instructions to publishers" do
content_block_edition = create(
:content_block_edition,
:email_address,
Expand All @@ -16,7 +17,7 @@ class ContentBlockManager::ContentBlockEdition::Show::ConfirmSummaryListComponen
assert_selector ".govuk-summary-list__value", text: "some instructions"
end

test "renders a summary list component with the edition details to confirm" do
it "renders a summary list component with the edition details to confirm" do
organisation = create(:organisation, name: "Department for Example")

content_block_document = create(:content_block_document, :email_address, title: "Some title")
Expand Down Expand Up @@ -44,4 +45,60 @@ class ContentBlockManager::ContentBlockEdition::Show::ConfirmSummaryListComponen
assert_selector ".govuk-summary-list__key", text: "Instructions to publishers"
assert_selector ".govuk-summary-list__value", text: "None"
end

describe "when the content block is scheduled" do
it "shows the scheduled date time" do
organisation = create(:organisation, name: "Department for Example")

content_block_document = create(:content_block_document, :email_address, title: "Some title")

content_block_edition = create(
:content_block_edition,
:email_address,
details: { "interesting_fact" => "value of fact" },
organisation:,
document: content_block_document,
scheduled_publication: 2.days.from_now,
)

content_block_edition.schedule!

render_inline(ContentBlockManager::ContentBlockEdition::Show::ConfirmSummaryListComponent.new(
content_block_edition:,
))

assert_selector ".govuk-summary-list__key", text: "Scheduled date and time"
assert_selector ".govuk-summary-list__value", text: I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)
end
end

describe "when the content block is being updated and published immediately" do
it "shows a publish now row" do
organisation = create(:organisation, name: "Department for Example")

content_block_document = create(:content_block_document, :email_address, title: "Some title")

_previous_edition = create(
:content_block_edition,
:email_address,
organisation:,
document: content_block_document,
)

content_block_edition = create(
:content_block_edition,
:email_address,
details: { "interesting_fact" => "value of fact" },
organisation:,
document: content_block_document,
)

render_inline(ContentBlockManager::ContentBlockEdition::Show::ConfirmSummaryListComponent.new(
content_block_edition:,
))

assert_selector ".govuk-summary-list__key", text: "Publish date"
assert_selector ".govuk-summary-list__value", text: I18n.l(Time.zone.today, format: :long_ordinal)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ class ContentBlockManager::WorkflowTest < ActiveSupport::TestCase
assert edition.draft?
end

test "publishing a draft edition transitions it into the published state" do
edition = create(:content_block_edition, document: create(:content_block_document, block_type: "email_address"))
edition.publish!
assert edition.published?
end

test "publishing a scheduled edition transitions it into the published state" do
edition = create(:content_block_edition,
document: create(
Expand Down

0 comments on commit a416b7c

Please sign in to comment.