-
Notifications
You must be signed in to change notification settings - Fork 193
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 #9902 from alphagov/content-modelling/876-style-pe…
…nsion-view content modelling/876 style pension view
- Loading branch information
Showing
9 changed files
with
221 additions
and
33 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
.../assets/stylesheets/content_block_manager/components/_host-editions-rollup-component.scss
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
2 changes: 1 addition & 1 deletion
2
...content_block_manager/content_block/document/show/host_editions_rollup_component.html.erb
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
4 changes: 4 additions & 0 deletions
4
...ponents/content_block_manager/content_block/document/show/summary_card_component.html.erb
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,4 @@ | ||
<%= render "govuk_publishing_components/components/summary_card", { | ||
title:, | ||
rows:, | ||
} %> |
97 changes: 97 additions & 0 deletions
97
...pp/components/content_block_manager/content_block/document/show/summary_card_component.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,97 @@ | ||
class ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponent < ViewComponent::Base | ||
def initialize(content_block_document:) | ||
@content_block_document = content_block_document | ||
end | ||
|
||
private | ||
|
||
attr_reader :content_block_document | ||
|
||
def rows | ||
[ | ||
title_item, | ||
*details_items, | ||
organisation_item, | ||
instructions_item, | ||
status_item, | ||
embed_code_item, | ||
].compact | ||
end | ||
|
||
def title | ||
"#{content_block_document.block_type.humanize} details" | ||
end | ||
|
||
def embed_code_item | ||
{ | ||
key: "Embed code", | ||
value: content_block_document.embed_code, | ||
data: { | ||
module: "copy-embed-code", | ||
"embed-code": content_block_document.embed_code, | ||
}, | ||
} | ||
end | ||
|
||
def title_item | ||
{ | ||
key: "Title", | ||
value: content_block_document.title, | ||
} | ||
end | ||
|
||
def organisation_item | ||
{ | ||
key: "Lead organisation", | ||
value: content_block_edition.lead_organisation, | ||
} | ||
end | ||
|
||
def instructions_item | ||
{ | ||
key: "Instructions to publishers", | ||
value: content_block_edition.instructions_to_publishers.presence || "None", | ||
} | ||
end | ||
|
||
def details_items | ||
content_block_edition.details.map do |key, value| | ||
{ | ||
key: key.humanize, | ||
value:, | ||
} | ||
end | ||
end | ||
|
||
def status_item | ||
if content_block_edition.state == "scheduled" | ||
{ | ||
key: "Status", | ||
value: scheduled_value, | ||
actions: [ | ||
{ | ||
label: sanitize("Edit <span class='govuk-visually-hidden'>schedule</span>"), | ||
href: helpers.content_block_manager.content_block_manager_content_block_document_schedule_edit_path(content_block_document), | ||
}, | ||
], | ||
} | ||
else | ||
{ | ||
key: "Status", | ||
value: last_updated_value, | ||
} | ||
end | ||
end | ||
|
||
def last_updated_value | ||
"Published #{time_ago_in_words(content_block_edition.updated_at)} ago by #{content_block_edition.creator.name}" | ||
end | ||
|
||
def scheduled_value | ||
"Scheduled for publication at #{I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)}" | ||
end | ||
|
||
def content_block_edition | ||
@content_block_edition = content_block_document.latest_edition | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,7 +254,7 @@ | |
assert_text "Content Block Manager" | ||
|
||
ContentBlockManager::ContentBlock::Document.find_each do |document| | ||
should_show_summary_card_for_email_address_content_block( | ||
should_show_summary_title_for_email_address_content_block( | ||
document.title, | ||
document.latest_edition.details[:email_address], | ||
) | ||
|
@@ -263,7 +263,7 @@ | |
|
||
Then("I should see the details for all documents from my organisation") do | ||
ContentBlockManager::ContentBlock::Document.with_lead_organisation(@user.organisation.id).each do |document| | ||
should_show_summary_card_for_email_address_content_block( | ||
should_show_summary_title_for_email_address_content_block( | ||
document.title, | ||
document.latest_edition.details[:email_address], | ||
) | ||
|
@@ -289,9 +289,9 @@ | |
end | ||
|
||
Then("I should see the details for the email address content block") do | ||
assert_text "View email address" | ||
expect(page).to have_selector("h1", text: @content_block.document.title) | ||
|
||
should_show_summary_list_for_email_address_content_block( | ||
should_show_summary_card_for_email_address_content_block( | ||
@content_block.document.title, | ||
@email_address, | ||
@organisation, | ||
|
@@ -302,6 +302,10 @@ | |
click_link "Edit", match: :first | ||
end | ||
|
||
When("I click to edit the {string}") do |block_type| | ||
click_link "Edit #{block_type}", match: :first | ||
end | ||
|
||
When("I fill out the form") do | ||
change_details | ||
end | ||
|
@@ -314,7 +318,7 @@ | |
end | ||
|
||
Then("the edition should have been updated successfully") do | ||
should_show_summary_list_for_email_address_content_block( | ||
should_show_summary_card_for_email_address_content_block( | ||
"Changed title", | ||
"[email protected]", | ||
"Ministry of Example", | ||
|
6 changes: 3 additions & 3 deletions
6
lib/engines/content_block_manager/features/support/helpers.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
76 changes: 76 additions & 0 deletions
76
..._block_manager/test/components/content_block/document/show/summary_card_component_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,76 @@ | ||
require "test_helper" | ||
|
||
class ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponentTest < ViewComponent::TestCase | ||
extend Minitest::Spec::DSL | ||
include ContentBlockManager::Engine.routes.url_helpers | ||
|
||
let(:organisation) { create(:organisation, name: "Department for Example") } | ||
let!(:content_block_edition) do | ||
create( | ||
:content_block_edition, | ||
:email_address, | ||
details: { foo: "bar", something: "else" }, | ||
creator: build(:user), | ||
organisation:, | ||
scheduled_publication: Time.zone.now, | ||
state: "published", | ||
updated_at: 1.day.ago, | ||
) | ||
end | ||
let(:content_block_document) { content_block_edition.document } | ||
|
||
it "renders a published content block correctly" do | ||
render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponent.new(content_block_document:)) | ||
|
||
assert_selector ".govuk-summary-list__row", count: 7 | ||
|
||
assert_selector ".govuk-summary-card__title", text: "Email address details" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Title" | ||
assert_selector ".govuk-summary-list__value", text: content_block_document.title | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Foo" | ||
assert_selector ".govuk-summary-list__value", text: "bar" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Something" | ||
assert_selector ".govuk-summary-list__value", text: "else" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Lead organisation" | ||
assert_selector ".govuk-summary-list__value", text: "Department for Example" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Status" | ||
assert_selector ".govuk-summary-list__value", text: "Published 1 day ago by #{content_block_edition.creator.name}" | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Instructions to publishers" | ||
assert_selector ".govuk-summary-list__value", text: "None" | ||
|
||
assert_selector ".govuk-summary-list__row[data-module='copy-embed-code']", text: "Embed code" | ||
assert_selector ".govuk-summary-list__row[data-embed-code='#{content_block_document.embed_code}']", text: "Embed code" | ||
assert_selector ".govuk-summary-list__key", text: "Embed code" | ||
assert_selector ".govuk-summary-list__value", text: content_block_document.embed_code | ||
end | ||
|
||
it "renders a scheduled content block correctly" do | ||
content_block_document.latest_edition.state = "scheduled" | ||
|
||
render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponent.new(content_block_document:)) | ||
|
||
assert_selector ".govuk-summary-list__row", count: 7 | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Status" | ||
assert_selector ".govuk-summary-list__value", text: "Scheduled for publication at #{I18n.l(content_block_edition.scheduled_publication, format: :long_ordinal)}" | ||
assert_selector ".govuk-summary-list__actions", text: "Edit schedule" | ||
assert_selector ".govuk-summary-list__actions a[href='#{content_block_manager_content_block_document_schedule_edit_path(content_block_document)}']" | ||
end | ||
|
||
describe "when there are instructions to publishers" do | ||
it "renders them" do | ||
content_block_document.latest_edition.instructions_to_publishers = "instructions" | ||
|
||
render_inline(ContentBlockManager::ContentBlock::Document::Show::SummaryCardComponent.new(content_block_document:)) | ||
|
||
assert_selector ".govuk-summary-list__key", text: "Instructions to publishers" | ||
assert_selector ".govuk-summary-list__value", text: "instructions" | ||
end | ||
end | ||
end |