Skip to content

Commit

Permalink
Merge pull request #2839 from alphagov/3035-integrate-the-specialist-…
Browse files Browse the repository at this point in the history
…finder-edit-forms-with-support-api-2

Improvements to fields in the request changes form
  • Loading branch information
dnkrj authored Nov 5, 2024
2 parents 27a9e10 + e5ee88f commit b300bd3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 8 deletions.
8 changes: 3 additions & 5 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ def confirm_metadata
@proposed_schema.delete("related")
end

if params["show_summaries"] == "true"
@proposed_schema["show_summaries"] = true
else
@proposed_schema.delete("show_summaries")
end
@proposed_schema["show_summaries"] = params[:show_summaries] == "true"

@proposed_schema.reject! { |_, value| value.blank? }

render :confirm_metadata
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/_metadata_summary_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
} if !(defined? previous_schema) || schema["base_path"] != previous_schema["base_path"]),
({
key: "Organisations the finder should be attached to",
value: schema["organisations"].map { |content_id| organisation_name(content_id) }.compact.join(",")
value: (schema["organisations"] || []).map { |content_id| organisation_name(content_id) }.compact.join(",")
} if !(defined? previous_schema) || schema["organisations"] != previous_schema["organisations"]),
({
key: "Short description (For search engines)",
Expand All @@ -46,7 +46,7 @@
} if !(defined? previous_schema) || schema["show_summaries"] != previous_schema["show_summaries"]),
({
key: "The document noun (How the documents on the finder are referred to)",
value: schema["document_noun"].humanize
value: (schema["document_noun"] || "").humanize
} if !(defined? previous_schema) || schema["document_noun"] != previous_schema["document_noun"]),
].compact,
summary_card_actions:,
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/edit_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

<%= render "govuk_publishing_components/components/textarea", {
label: {
text: "Summary of the finder (Longer description shown below title)",
text: "Summary of the finder (Longer description shown below title) (optional)",
heading_size: "s",
},
hint: "Example: Find notifiable exotic animal disease cases and control zone declarations for England. There are cases of bird flu (avian influenza) in England. Check if you are in a disease control zone on the map. Find an export health certificate - GOV.UK",
Expand Down
29 changes: 29 additions & 0 deletions spec/features/editing_the_cma_case_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@
expect(page).to have_selector(".gem-c-success-alert__message", text: "Your changes have been submitted and Zendesk ticket created.")
end

scenario "deleting all fields" do
visit "admin/cma-cases"
click_link "Request changes"

fill_in "name", with: ""
fill_in "base_path", with: ""
fill_in "description", with: ""
fill_in "summary", with: ""
fill_in "Link 1", with: ""
fill_in "Link 2", with: ""
fill_in "Link 3", with: ""
fill_in "document_noun", with: ""

click_button "Submit changes"

expect(page).to have_selector("dt", text: "")
expect(page).to have_selector("dt", text: "")
expect(page).to have_selector("dt", text: "")
expect(page).to have_selector("dt", text: "")
expect(page).to have_selector("dt", text: "")
expect(page).to have_selector("dt", text: "")
expect(page).to have_selector("dt", text: "")
expect(page).to have_selector("dt", text: "")

click_button "Submit changes"

expect(page).to have_selector(".gem-c-success-alert__message", text: "Your changes have been submitted and Zendesk ticket created.")
end

scenario "fields are not shown on the confirmation page if not changed" do
visit "admin/metadata/cma-cases"
click_button "Submit changes"
Expand Down
22 changes: 22 additions & 0 deletions spec/features/editing_the_farming_grant_finder_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require "spec_helper"

RSpec.feature "Editing the Farming grant finder", type: :feature do
let(:organisations) do
[
{ "content_id" => "de4e9dc6-cca4-43af-a594-682023b84d6c", "title" => "Department for Environment, Food & Rural Affairs" },
{ "content_id" => "e8fae147-6232-4163-a3f1-1c15b755a8a4", "title" => "Rural Payments Agency" },
]
end

before do
log_in_as_editor(:farming_grant_editor)
stub_publishing_api_has_content([], hash_including(document_type: FarmingGrant.document_type))
stub_publishing_api_has_content(organisations, hash_including(document_type: Organisation.document_type))
end

scenario "fields are not shown on the confirmation page if not changed" do
visit "admin/metadata/farming-grants"
click_button "Submit changes"
expect(page).not_to have_selector("dt")
end
end
5 changes: 5 additions & 0 deletions spec/fixtures/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
organisation_content_id { "de4e9dc6-cca4-43af-a594-682023b84d6c" }
end

factory :farming_grant_editor, parent: :editor do
organisation_slug { "department-for-environment-food-rural-affairs" }
organisation_content_id { "de4e9dc6-cca4-43af-a594-682023b84d6c" }
end

# Writer factories:
factory :writer, aliases: [:cma_writer], parent: :editor do
organisation_slug { "competition-and-markets-authority" }
Expand Down

0 comments on commit b300bd3

Please sign in to comment.