Skip to content

Commit

Permalink
Render text for metadata fields for published edition
Browse files Browse the repository at this point in the history
  • Loading branch information
syed-ali-tw committed Sep 23, 2024
1 parent fa994b5 commit 9d7ad89
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 21 deletions.
11 changes: 11 additions & 0 deletions app/models/artefact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,17 @@ def exact_route?
prefixes.empty?
end

def locale_to_language(locale)
case locale
when "en"
"English"
when "cy"
"Welsh"
else
""
end
end

private

# We need to do this because Mongoid doesn't implement 'saved_change_to_attribute?' methods like ActiveRecord does
Expand Down
15 changes: 14 additions & 1 deletion app/views/editions/secondary_nav_tabs/_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand All @@ -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,
} %>
<p class="govuk-body">
<%= key.eql?("slug") ? value : @artefact.locale_to_language(value) %>
</p>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/editions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<%= render partial: "secondary_navigation" %>
</div>

<div class="govuk-grid-column-two-thirds">
<div class="govuk-grid-column-two-thirds govuk-!-margin-bottom-7">
<%= render partial: "secondary_nav_tabs/#{current_tab}", :locals => { :publication => @resource } %>
</div>
</div>
64 changes: 45 additions & 19 deletions test/integration/edition_edit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,57 @@ class EditionEditTest < IntegrationTest
end

context "#metadata" do
setup do
click_link("Metadata")
end
context "#draft" do
setup do
click_link("Metadata")
end

should "'Metadata' header and an update button" do
within :css, ".gem-c-heading" do
assert page.has_text?("Metadata")
should "'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

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
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 "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

should "update and show success message" do
fill_in "artefact[slug]", with: "changed-slug"
choose("Welsh")
click_button("Update")
context "#published" 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 current value for slug and language as texts" do
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

0 comments on commit 9d7ad89

Please sign in to comment.