Skip to content

Commit

Permalink
Fix issues with tests by not merging
Browse files Browse the repository at this point in the history
Values that existed in the content_item were not being overwritten in our merge, so forcefully override values instead. This surfaced some issues with the tests overall.
  • Loading branch information
AshGDS committed Nov 30, 2023
1 parent c29889a commit 4820b0d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
12 changes: 7 additions & 5 deletions lib/govuk_publishing_components/presenters/meta_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ def add_political_tags(meta_tags)
def add_ga4_political_tags(meta_tags)
government = content_item.dig(:links, :government, 0)

# political: true/false is in a different place to current: true/false, which is why we have 'details' and 'government[:details]'
# political: true/false is in a different place to current: true/false, which is why we have 'details' and 'government.dig(:details)'
if government && details[:political]
current_government = government.dig(:details, :current)
meta_tags["govuk:ga4-political-status"] = current_government ? "political" : "historic"
unless current_government
meta_tags["govuk:ga4-political-status"] = "historic"

government_title = government[:title]
if government_title && !current_government
meta_tags["govuk:ga4-publishing-government"] = government_title
government_title = government[:title]
if government_title
meta_tags["govuk:ga4-publishing-government"] = government_title
end
end
end

Expand Down
46 changes: 24 additions & 22 deletions spec/components/meta_tags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,10 @@ def example_document_for(schema_name, example_name)
end

it "doesn't render govuk:ga4-browse-topic if the dig doesn't return anything" do
content_item = {
"links": nil,
}
render_component(content_item: example_document_for("transaction", "transaction").merge(content_item))
content_item = example_document_for("html_publication", "published_with_history_mode")
content_item.delete("links")

render_component(content_item:)
assert_no_meta_tag("govuk:ga4-browse-topic")
end

Expand All @@ -454,12 +454,10 @@ def example_document_for(schema_name, example_name)
end

it "doesn't render GA4 political tags if the government object doesn't exist in the content item" do
content_item = {
"links": {
"government": nil,
},
}
render_component(content_item: example_document_for("html_publication", "published_with_history_mode").merge(content_item))
content_item = example_document_for("html_publication", "published_with_history_mode")
content_item["links"].delete("government")

render_component(content_item:)
assert_no_meta_tag("govuk:ga4-publishing-government")
assert_no_meta_tag("govuk:ga4-political-status")
end
Expand All @@ -474,35 +472,39 @@ def example_document_for(schema_name, example_name)
end

it "doesn't render GA4 political tags if the government object exists in the content item, but political is false" do
content_item = {
"political": false,
"links": {
"government": {
content_item = example_document_for("html_publication", "published_with_history_mode")
content_item["details"]["political"] = false
content_item["links"] = {
"government": [
{
"details": {
"current": false,
},
"title": "2005 to 2010 Labour government",
},
},
],
}
render_component(content_item: example_document_for("html_publication", "published_with_history_mode").merge(content_item))

render_component(content_item:)
assert_no_meta_tag("govuk:ga4-publishing-government")
assert_no_meta_tag("govuk:ga4-political-status")
end

it "doesn't render GA4 political tags if the government object exists in the content item, but it refers to the current government" do
content_item = {
"political": true,
"links": {
"government": {
content_item = example_document_for("html_publication", "published_with_history_mode")
content_item["details"]["political"] = true
content_item["links"] = {
"government": [
{
"details": {
"current": true,
},
"title": "2015 Conservative government",
},
},
],
}
render_component(content_item: example_document_for("html_publication", "published_with_history_mode").merge(content_item))

render_component(content_item:)
assert_no_meta_tag("govuk:ga4-publishing-government")
assert_no_meta_tag("govuk:ga4-political-status")
end
Expand Down

0 comments on commit 4820b0d

Please sign in to comment.