From f44bbf02abc5210aace99bdbebc4fbc4b5913f18 Mon Sep 17 00:00:00 2001 From: syed-ali-tw Date: Mon, 23 Sep 2024 16:05:51 +0100 Subject: [PATCH] Render text for metadata fields for published edition --- app/controllers/artefacts_controller.rb | 2 +- app/controllers/editions_controller.rb | 13 ++ .../secondary_nav_tabs/_metadata.html.erb | 15 ++- test/functional/editions_controller_test.rb | 2 +- test/integration/edit_artefact_test.rb | 2 + test/integration/edition_edit_test.rb | 114 ++++++++++++------ 6 files changed, 105 insertions(+), 43 deletions(-) diff --git a/app/controllers/artefacts_controller.rb b/app/controllers/artefacts_controller.rb index cd369cf76..b022dc5ad 100644 --- a/app/controllers/artefacts_controller.rb +++ b/app/controllers/artefacts_controller.rb @@ -31,7 +31,7 @@ def update private def show_success_message - if FeatureConstraint.new("design_system_edit") + if Flipflop.enabled?("design_system_edit".to_sym) flash[:success] = "Metadata has successfully updated".html_safe else flash[:notice] = "Metadata updated" diff --git a/app/controllers/editions_controller.rb b/app/controllers/editions_controller.rb index d89e13cca..4aedee99c 100644 --- a/app/controllers/editions_controller.rb +++ b/app/controllers/editions_controller.rb @@ -5,6 +5,8 @@ class EditionsController < InheritedResources::Base defaults resource_class: Edition, collection_name: "editions", instance_name: "resource" before_action :setup_view_paths, except: %i[index] + helper_method :locale_to_language + def index redirect_to root_path end @@ -45,4 +47,15 @@ def setup_view_paths_for(publication) prepend_view_path "app/views/editions" prepend_view_path template_folder_for(publication) end + + def locale_to_language(locale) + case locale + when "en" + "English" + when "cy" + "Welsh" + else + "" + end + end end diff --git a/app/views/editions/secondary_nav_tabs/_metadata.html.erb b/app/views/editions/secondary_nav_tabs/_metadata.html.erb index 01f29bab9..608688bc2 100644 --- a/app/views/editions/secondary_nav_tabs/_metadata.html.erb +++ b/app/views/editions/secondary_nav_tabs/_metadata.html.erb @@ -15,13 +15,15 @@ hint: "If you change the slug of a published page, the old slug will automatically redirect to the new one.", name: "artefact[slug]", value: publication.slug, - heading_level: 2, + heading_level: 3, heading_size: "m", } %> <%= render "govuk_publishing_components/components/radio", { heading: "Language", name: "artefact[language]", + heading_level: 3, + heading_size: "m", inline: true, items: [ { @@ -41,4 +43,15 @@ } %> <% end %> <% else %> + <% @artefact.attributes.slice("slug", "language").each do |key, value| %> + <%= render "govuk_publishing_components/components/heading", { + text: key.humanize, + heading_level: 3, + font_size: "m", + margin_bottom: 3, + } %> +

+ <%= key.eql?("slug") ? value : locale_to_language(value) %> +

+ <% end %> <% end %> diff --git a/test/functional/editions_controller_test.rb b/test/functional/editions_controller_test.rb index acb752939..1f60e6fe8 100644 --- a/test/functional/editions_controller_test.rb +++ b/test/functional/editions_controller_test.rb @@ -61,7 +61,7 @@ class EditionsControllerTest < ActionController::TestCase end should "alias to show method" do - assert EditionsController.new.method(:metadata).super_method.name.eql?(:show) + assert_equal EditionsController.new.method(:metadata).super_method.name, :show end end end diff --git a/test/integration/edit_artefact_test.rb b/test/integration/edit_artefact_test.rb index 4ead24b8c..b6a270241 100644 --- a/test/integration/edit_artefact_test.rb +++ b/test/integration/edit_artefact_test.rb @@ -5,6 +5,8 @@ class EditArtefactTest < LegacyIntegrationTest setup_users stub_linkables stub_holidays_used_by_fact_check + test_strategy = Flipflop::FeatureSet.current.test! + test_strategy.switch!(:design_system_edit, false) end should "edit a draft artefact" do diff --git a/test/integration/edition_edit_test.rb b/test/integration/edition_edit_test.rb index 443147b3f..0d06654f2 100644 --- a/test/integration/edition_edit_test.rb +++ b/test/integration/edition_edit_test.rb @@ -6,58 +6,92 @@ class EditionEditTest < IntegrationTest test_strategy = Flipflop::FeatureSet.current.test! test_strategy.switch!(:design_system_edit, true) stub_linkables - edition = FactoryBot.create(:guide_edition, title: "Edit page title", state: "draft") - visit edition_path(edition) end - should "show document summary and title" do - assert page.has_title?("Edit page title") + context "when edition is draft" do + setup do + edition = FactoryBot.create(:guide_edition, title: "Edit page title", state: "draft") + visit edition_path(edition) + end - row = find_all(".govuk-summary-list__row") - assert row[0].has_content?("Assigned to") - assert row[1].has_text?("Content type") - assert row[1].has_text?("Guide") - assert row[2].has_text?("Edition") - assert row[2].has_text?("1") - assert row[2].has_text?("Draft") - end + should "show document summary and title" do + assert page.has_title?("Edit page title") - should "show all the tabs for the edit" do - assert page.has_text?("Edit") - assert page.has_text?("Tagging") - assert page.has_text?("Metadata") - assert page.has_text?("History and notes") - assert page.has_text?("Admin") - assert page.has_text?("Related external links") - assert page.has_text?("Unpublish") - end + row = find_all(".govuk-summary-list__row") + assert row[0].has_content?("Assigned to") + assert row[1].has_text?("Content type") + assert row[1].has_text?("Guide") + assert row[2].has_text?("Edition") + assert row[2].has_text?("1") + assert row[2].has_text?("Draft") + end - context "#metadata" do - setup do - click_link("Metadata") + should "show all the tabs for the edit" do + assert page.has_text?("Edit") + assert page.has_text?("Tagging") + assert page.has_text?("Metadata") + assert page.has_text?("History and notes") + assert page.has_text?("Admin") + assert page.has_text?("Related external links") + assert page.has_text?("Unpublish") end - should "'Metadata' header and an update button" do - within :css, ".gem-c-heading" do - assert page.has_text?("Metadata") + context "metadata tab" do + setup do + click_link("Metadata") + end + + should "show 'Metadata' header and an update button" do + within :css, ".gem-c-heading" do + assert page.has_text?("Metadata") + end + assert page.has_button?("Update") end - assert page.has_button?("Update") - end - should "show slug input box prefilled" do - assert page.has_text?("Slug") - assert page.has_text?("If you change the slug of a published page, the old slug will automatically redirect to the new one.") - assert page.has_field?("artefact[slug]", with: /slug/) + should "show slug input box prefilled" do + assert page.has_text?("Slug") + assert page.has_text?("If you change the slug of a published page, the old slug will automatically redirect to the new one.") + assert page.has_field?("artefact[slug]", with: /slug/) + end + + should "update and show success message" do + fill_in "artefact[slug]", with: "changed-slug" + choose("Welsh") + click_button("Update") + + assert find(".gem-c-radio input[value='cy']").checked? + assert page.has_text?("Metadata has successfully updated") + assert page.has_field?("artefact[slug]", with: "changed-slug") + end end + end - should "update and show success message" do - fill_in "artefact[slug]", with: "changed-slug" - choose("Welsh") - click_button("Update") + context "when edition is published" do + context "metadata tab" do + setup do + edition = FactoryBot.create( + :completed_transaction_edition, + panopticon_id: FactoryBot.create( + :artefact, + slug: "can-i-get-a-driving-licence", + ).id, + state: "published", + slug: "can-i-get-a-driving-licence", + ) - assert find(".gem-c-radio input[value='cy']").checked? - assert page.has_text?("Metadata has successfully updated") - assert page.has_field?("artefact[slug]", with: "changed-slug") + visit edition_path(edition) + click_link("Metadata") + end + + should "show un-editable current value for slug and language" do + assert page.has_no_field?("artefact[slug]") + assert page.has_no_field?("artefact[language]") + + assert page.has_text?("Slug") + assert page.has_text?(/can-i-get-a-driving-licence/) + assert page.has_text?("Language") + assert page.has_text?(/English/) + end end end end