Skip to content

Commit

Permalink
PLATUI-2422: Add default content and Welsh translation for GovukTabs … (
Browse files Browse the repository at this point in the history
#256)

* PLATUI-2422: Add default content and Welsh translation for GovukTabs title using Option for title
  • Loading branch information
JoPintoPaul committed Oct 9, 2023
1 parent e6131c6 commit 4a55049
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 9 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
For compatibility information see `govukFrontendVersion` and `hmrcFrontendVersion` in
[LibDependencies](project/LibDependencies.scala)

## [7.23.0] - 2023-10-09

### Changed

- Added Welsh translation of default title `Contents` to `GovukTabs`
- Change type of `title` from `String` to `Option[String]` in `Tab` to support the translation change
- Require an implicit instance of `Messages` to be passed through the `GovukTabs` component

### Compatible with

- [hmrc/hmrc-frontend v5.49.0](https://github.com/hmrc/hmrc-frontend/releases/tag/v5.49.0)
- [alphagov/govuk-frontend v4.7.0](https://github.com/alphagov/govuk-frontend/releases/tag/v4.7.0)

## [7.22.0] - 2023-10-05

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,32 @@

package uk.gov.hmrc.govukfrontend.views.components

import uk.gov.hmrc.govukfrontend.support.TemplateIntegrationSpec
import play.api.mvc.RequestHeader
import play.api.test.FakeRequest
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.govukfrontend.views.GovukFrontendDependency.govukFrontendVersion
import uk.gov.hmrc.govukfrontend.views.html.components._
import uk.gov.hmrc.govukfrontend.views.viewmodels.tabs.Tabs
import uk.gov.hmrc.govukfrontend.views.viewmodels.tabs.Generators._
import uk.gov.hmrc.helpers.MessagesSupport
import uk.gov.hmrc.support.TemplateIntegrationBaseSpec

import scala.util.Try

object GovukTabsIntegrationSpec
extends TemplateIntegrationSpec[Tabs, GovukTabs](govukComponentName = "govukTabs", seed = None)
extends TemplateIntegrationBaseSpec[Tabs](
componentName = "govukTabs",
seed = None
)
with MessagesSupport {

protected val libraryName: String = "govuk"

protected val libraryVersion: String = govukFrontendVersion

private val component = app.injector.instanceOf[GovukTabs]

override def render(tabs: Tabs): Try[HtmlFormat.Appendable] = {
implicit val request: RequestHeader = FakeRequest("GET", "/foo")
Try(component(tabs))
}
}
1 change: 1 addition & 0 deletions src/main/resources/messages
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ govuk.pagination.page=Page
govuk.warningText.iconFallbackText=Warning
govuk.exitThisPage.contentFallbackText=Exit this page
govuk.exitThisPage.redirectUrlFallback=https://www.bbc.co.uk/weather
govuk.tabs.titleFallbackText=Contents
1 change: 1 addition & 0 deletions src/main/resources/messages.cy
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ govuk.pagination.page=Tudalen
govuk.warningText.iconFallbackText=Rhybudd
govuk.exitThisPage.contentFallbackText=Gadael y dudalen hon
govuk.exitThisPage.redirectUrlFallback=https://www.bbc.co.uk/weather
govuk.tabs.titleFallbackText=Cynnwys
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import uk.gov.hmrc.govukfrontend.views.viewmodels.CommonJsonFormats._
case class Tabs(
id: Option[String] = None,
idPrefix: Option[String] = None,
title: String = "Contents",
title: Option[String] = None,
items: Seq[TabItem] = Seq.empty,
classes: String = "",
attributes: Map[String, String] = Map.empty
Expand All @@ -36,7 +36,7 @@ object Tabs {
implicit def jsonReads: Reads[Tabs] = (
(__ \ "id").readNullable[String] and
(__ \ "idPrefix").readNullable[String] and
(__ \ "title").readWithDefault[String](defaultObject.title) and
(__ \ "title").readNullable[String] and
(__ \ "items").readWithDefault[Seq[TabItem]](defaultObject.items)(forgivingSeqReads[TabItem]) and
(__ \ "classes").readWithDefault[String](defaultObject.classes) and
(__ \ "attributes").readWithDefault[Map[String, String]](defaultObject.attributes)(attributesReads)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

@this()

@(params: Tabs)
@(params: Tabs)(implicit messages: Messages)
@import params._
<div@id.mapNonEmpty {id => id="@id"} class="@toClasses("govuk-tabs", classes)"@toAttributes(attributes) data-module="govuk-tabs">
<h2 class="govuk-tabs__title">
@HtmlFormat.escape(title)
@{title.getOrElse(messages("govuk.tabs.titleFallbackText"))}
</h2>

@if(items.nonEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,52 @@
package uk.gov.hmrc.govukfrontend.views
package components

import play.api.i18n.{Lang, Messages}
import play.api.mvc.RequestHeader
import play.api.test.FakeRequest
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.govukfrontend.views.html.components._
import uk.gov.hmrc.helpers.MessagesSupport

class GovukTabsSpec extends TemplateUnitSpec[Tabs, GovukTabs]("govukTabs")
import scala.util.Try

class GovukTabsSpec extends TemplateUnitBaseSpec[Tabs]("govukTabs") with MessagesSupport {

private val component = app.injector.instanceOf[GovukTabs]

def render(templateParams: Tabs): Try[HtmlFormat.Appendable] = {
implicit val request: RequestHeader = FakeRequest("GET", "/foo")

Try(component(templateParams))
}

"GovukTabs" when {
"implicit messages language is English" should {
"display English default title if none passed in" in {
val tabs = Tabs(
title = None
)

val content = component(tabs)

val button = content.select(".govuk-tabs__title")
button.text() shouldBe "Contents"
}
}

"implicit messages language is Welsh" should {
val welshMessages: Messages = messagesApi.preferred(Seq(Lang("cy")))

"display Welsh translation of default title if none passed in" in {
val tabs = Tabs(
title = None
)

val content = component(tabs)(welshMessages)

val button = content.select(".govuk-tabs__title")
button.text() shouldBe "Cynnwys"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object Generators {
for {
id <- Gen.option(genAlphaStr())
idPrefix <- Gen.option(genAlphaStr())
title <- genAlphaStr()
title <- Gen.option(genAlphaStr())
n <- Gen.chooseNum(0, 5)
items <- Gen.listOfN(n, arbTabItem.arbitrary)
classes <- genClasses()
Expand Down

0 comments on commit 4a55049

Please sign in to comment.