-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9717 from alphagov/content-modelling/use-presente…
…r-for-confirmation-text Use presenter for confirmation text
- Loading branch information
Showing
6 changed files
with
129 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...content_block_manager/app/presenters/content_block_manager/confirmation_copy_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module ContentBlockManager | ||
class ConfirmationCopyPresenter | ||
def initialize(content_block_edition) | ||
@content_block_edition = content_block_edition | ||
end | ||
|
||
def for_panel | ||
I18n.t("content_block_edition.confirmation_page.#{state}.banner", block_type:, date:) | ||
end | ||
|
||
def for_paragraph | ||
I18n.t("content_block_edition.confirmation_page.#{state}.detail") | ||
end | ||
|
||
def state | ||
if content_block_edition.scheduled? | ||
:scheduled | ||
elsif content_block_edition.document.editions.count > 1 | ||
:updated | ||
else | ||
:created | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :content_block_edition | ||
|
||
def date | ||
I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal) if content_block_edition.scheduled_publication | ||
end | ||
|
||
def block_type | ||
content_block_edition.block_type.humanize | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ngines/content_block_manager/test/unit/app/presenters/confirmation_copy_presenter_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::ConfirmationCopyPresenterTest < ActiveSupport::TestCase | ||
extend Minitest::Spec::DSL | ||
|
||
let(:content_block_edition) { build(:content_block_edition, :email_address) } | ||
let(:block_type) { content_block_edition.block_type.humanize } | ||
|
||
let(:presenter) { ContentBlockManager::ConfirmationCopyPresenter.new(content_block_edition) } | ||
|
||
context "when the content block is scheduled" do | ||
let(:content_block_edition) { build(:content_block_edition, :email_address, scheduled_publication: Time.zone.now, state: :scheduled) } | ||
|
||
describe "#for_panel" do | ||
it "should return the scheduled text" do | ||
assert_equal "#{block_type} scheduled to publish on #{I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)}", presenter.for_panel | ||
end | ||
end | ||
|
||
describe "#for_paragraph" do | ||
it "should return the scheduled text" do | ||
assert_equal "You can now view the updated schedule of the content block.", presenter.for_paragraph | ||
end | ||
end | ||
end | ||
|
||
context "when there is more than one edition for the underlying document" do | ||
let(:document) { content_block_edition.document } | ||
|
||
before do | ||
document.expects(:editions).returns( | ||
build_list(:content_block_edition, 3, :email_address), | ||
) | ||
end | ||
|
||
describe "#for_panel" do | ||
it "should return the published text" do | ||
assert_equal "#{block_type} published", presenter.for_panel | ||
end | ||
end | ||
|
||
describe "#for_paragraph" do | ||
it "should return the published text" do | ||
assert_equal "You can now view the updated content block.", presenter.for_paragraph | ||
end | ||
end | ||
end | ||
|
||
context "when there is only one edition for the underlying document" do | ||
describe "#for_panel" do | ||
it "should return the created text" do | ||
assert_equal "#{block_type} created", presenter.for_panel | ||
end | ||
end | ||
|
||
describe "#for_paragraph" do | ||
it "should return the created text" do | ||
assert_equal "You can now view the content block.", presenter.for_paragraph | ||
end | ||
end | ||
end | ||
end |