Skip to content

Commit 1004b80

Browse files
committed
Add 'Use default image' option for when fallback image deleted
1 parent 3806d39 commit 1004b80

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

app/components/admin/edition_images/lead_image_card_component.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def summary_card_actions
1717
destructive: true,
1818
},
1919
]
20-
else
20+
elsif show_fallback_image?
2121
[
2222
{
2323
label: "Replace",
@@ -29,11 +29,22 @@ def summary_card_actions
2929
destructive: true,
3030
},
3131
]
32+
else
33+
[
34+
{
35+
label: "Add image",
36+
href: new_admin_edition_image_path(edition_id: edition.id, usage: image_usage.key),
37+
},
38+
{
39+
label: "Use default image",
40+
href: confirm_update_default_lead_image_behaviour_admin_edition_images_path(edition, behaviour: "organisation_image"),
41+
},
42+
]
3243
end
3344
end
3445

3546
def thumbnail
36-
if image.blank?
47+
if image.blank? && show_fallback_image?
3748
if edition.default_lead_image&.all_asset_variants_uploaded?
3849
return sanitize("<img style=\"width: 100%;\" src=\"#{edition.default_lead_image.url(:s300)}\" alt=\"\" class=\"app-view-edition-resource__preview\">")
3950
else
@@ -48,4 +59,8 @@ def lead_image_guidance
4859
tag.p("The lead image appears at the top of the document. The same image should not be used in the body text.", class: "govuk-body") +
4960
tag.p("Uploading your own lead image is optional. If a custom lead image is not uploaded then the default image for your organisation will be used. If neither is available, a placeholder will appear.", class: "govuk-body")
5061
end
62+
63+
def show_fallback_image?
64+
edition.image_display_option.nil? || edition.image_display_option == "organisation_image"
65+
end
5166
end

test/components/admin/edition_images/lead_image_card_component_test.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class Admin::EditionImages::LeadImageCardComponentTest < ViewComponent::TestCase
66
include Rails.application.routes.url_helpers
77

8-
test "Summary card actions contains Edit and Delete options if image present" do
8+
test "Summary card actions contains Edit and Delete options if custom image present" do
99
image_data = create(:image_data, image_kind: "default")
1010
image = build_stubbed(:image, usage: "lead", image_data:)
1111
ConfigurableDocumentType.setup_test_types(build_configurable_document_type("test_type", lead_image_usage_test_type))
@@ -18,7 +18,7 @@ class Admin::EditionImages::LeadImageCardComponentTest < ViewComponent::TestCase
1818
assert_selector ".govuk-link[href='#{confirm_destroy_admin_edition_image_path(edition, image)}']", text: "Delete"
1919
end
2020

21-
test "Summary card actions contains Replace option if image not present" do
21+
test "Summary card actions contains Replace option if only the default image is present" do
2222
ConfigurableDocumentType.setup_test_types(build_configurable_document_type("test_type", lead_image_usage_test_type))
2323
edition = build_stubbed(:standard_edition)
2424
lead_usage = edition.permitted_image_usages.find { |usage| usage.key == "lead" }
@@ -28,6 +28,17 @@ class Admin::EditionImages::LeadImageCardComponentTest < ViewComponent::TestCase
2828
assert_selector ".govuk-link[href='#{new_admin_edition_image_path(edition_id: edition.id, usage: lead_usage.key)}']", text: "Replace"
2929
end
3030

31+
test "Summary card actions contains 'Add image' and 'Use default image' options if no custom or default image is present" do
32+
ConfigurableDocumentType.setup_test_types(build_configurable_document_type("test_type", lead_image_usage_test_type))
33+
edition = build_stubbed(:standard_edition, image_display_option: "no_image")
34+
lead_usage = edition.permitted_image_usages.find { |usage| usage.key == "lead" }
35+
36+
render_inline(Admin::EditionImages::LeadImageCardComponent.new(edition:, image: nil, image_usage: lead_usage))
37+
38+
assert_selector ".govuk-link[href='#{new_admin_edition_image_path(edition_id: edition.id, usage: lead_usage.key)}']", text: "Add image"
39+
assert_selector ".govuk-link[href='#{confirm_update_default_lead_image_behaviour_admin_edition_images_path(edition, behaviour: 'organisation_image')}']", text: "Use default image"
40+
end
41+
3142
test "renders lead image guidance" do
3243
ConfigurableDocumentType.setup_test_types(build_configurable_document_type("test_type", lead_image_usage_test_type))
3344
edition = build_stubbed(:standard_edition)

0 commit comments

Comments
 (0)