Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] Change devolved nations component type option #4535

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Unreleased

* **BREAKING** Change devolved nations component type option ([PR #4535](https://github.com/alphagov/govuk_publishing_components/pull/4535))
* Use component wrapper on subscription links ([PR #4525](https://github.com/alphagov/govuk_publishing_components/pull/4525))
* Use component wrapper on success alert component ([PR #4527](https://github.com/alphagov/govuk_publishing_components/pull/4527))
* Use component wrapper on summary card component ([PR #4528](https://github.com/alphagov/govuk_publishing_components/pull/4528))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ examples:
northern_ireland:
applicable: false
alternative_url: /
type: consultation
content_type: consultation
applies_to_one_nation_individual_guidance_available:
description: Specify alternative type for the content e.g. Guidance
data:
Expand All @@ -82,7 +82,7 @@ examples:
northern_ireland:
applicable: false
alternative_url: /
type: detailed_guide
content_type: detailed_guide
specific_heading level:
description: Use a different heading level for the main link title. Defaults to `h2` if not passed.
data:
Expand All @@ -104,5 +104,5 @@ examples:
northern_ireland:
applicable: false
alternative_url: /
type: detailed_guide
content_type: detailed_guide
disable_ga4: true
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module GovukPublishingComponents
module Presenters
class DevolvedNationsHelper
attr_reader :national_applicability, :type
attr_reader :national_applicability, :content_type

def initialize(local_assigns)
@national_applicability = local_assigns[:national_applicability]
@type = local_assigns[:type] || "publication"
@content_type = local_assigns[:content_type] || "publication"
end

def applicable_nations_title_text(use_english_translation = nil)
Expand Down Expand Up @@ -42,8 +42,8 @@ def nations_with_urls
def alternative_content_text(name)
nation = I18n.t("components.devolved_nations.#{name}")

if I18n.exists?("components.devolved_nations.type.#{@type}")
I18n.t("components.devolved_nations.type.#{@type}", nation:)
if I18n.exists?("components.devolved_nations.type.#{@content_type}")
I18n.t("components.devolved_nations.type.#{@content_type}", nation:)
else
I18n.t("components.devolved_nations.type.publication", nation:)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/components/devolved_nations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def component_name
alternative_url: "/consultation-northern-ireland",
},
},
type: "consultation",
content_type: "consultation",
)
assert_select ".gem-c-devolved-nations > h2", text: "Applies to England"
assert_select ".gem-c-devolved-nations > ul > li:nth-child(1) > [href='/consultation-northern-ireland']", text: "Consultation for Northern Ireland"
Expand All @@ -123,7 +123,7 @@ def component_name
alternative_url: "/guidance-northern-ireland",
},
},
type: "detailed_guide",
content_type: "detailed_guide",
)
assert_select ".gem-c-devolved-nations > h2", text: "Applies to England"
assert_select ".gem-c-devolved-nations > ul > li:nth-child(1) > [href='/guidance-northern-ireland']", text: "Guidance for Northern Ireland"
Expand All @@ -140,7 +140,7 @@ def component_name
alternative_url: "/publication-northern-ireland",
},
},
type: "invalid_type",
content_type: "invalid_type",
)
assert_select ".gem-c-devolved-nations > h2", text: "Applies to England"
assert_select ".gem-c-devolved-nations > ul > li:nth-child(1) > [href='/publication-northern-ireland']", text: "Publication for Northern Ireland"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
alternative_url: "/consultation-northern-ireland",
},
},
type: "consultation",
content_type: "consultation",
)
expect(devolved_nations_helper.applicable_nations_title_text).to eql("England")
expect(devolved_nations_helper.alternative_content_text("northern_ireland")).to eql("Consultation for Northern Ireland")
Expand All @@ -108,7 +108,7 @@
alternative_url: "/guidance-northern-ireland",
},
},
type: "detailed_guide",
content_type: "detailed_guide",
)
expect(devolved_nations_helper.applicable_nations_title_text).to eql("England")
expect(devolved_nations_helper.alternative_content_text("northern_ireland")).to eql("Guidance for Northern Ireland")
Expand All @@ -125,7 +125,7 @@
alternative_url: "/publication-northern-ireland",
},
},
type: "invalid_type",
content_type: "invalid_type",
)
expect(devolved_nations_helper.applicable_nations_title_text).to eql("England")
expect(devolved_nations_helper.alternative_content_text("northern_ireland")).to eql("Publication for Northern Ireland")
Expand Down
Loading