From 2c54cc33b30fee2fdccc273a6ce2bea7ec9eacdc Mon Sep 17 00:00:00 2001
From: mywyau <47248104+mywyau@users.noreply.github.com>
Date: Wed, 6 Nov 2024 18:37:35 +0000
Subject: [PATCH] MISUV-8687 Create new Reporting Frequency View
---
.../ReportingFrequencyPageController.scala | 58 +++++--
app/models/ReportingFrequencyViewModel.scala | 26 +++
app/services/optout/OptOutService.scala | 2 +-
app/views/ReportingFrequencyView.scala.html | 68 ++++++++
app/views/components/linkComponent.scala.html | 36 +++++
conf/messages | 17 ++
conf/messages.cy | 12 +-
.../NextUpdatesControllerISpec.scala | 1 +
.../ReportingFrequencyControllerISpec.scala | 15 +-
...IncomeSourceIntegrationTestConstants.scala | 4 +-
...ReportingFrequencyPageControllerSpec.scala | 46 +++++-
test/testUtils/TestSupport.scala | 1 +
test/views/ReportingFrequencyViewSpec.scala | 152 ++++++++++++++++++
.../ReportingFrequencyViewMessages.scala | 30 ++++
14 files changed, 435 insertions(+), 33 deletions(-)
create mode 100644 app/models/ReportingFrequencyViewModel.scala
create mode 100644 app/views/ReportingFrequencyView.scala.html
create mode 100644 app/views/components/linkComponent.scala.html
create mode 100644 test/views/ReportingFrequencyViewSpec.scala
create mode 100644 test/views/messages/ReportingFrequencyViewMessages.scala
diff --git a/app/controllers/ReportingFrequencyPageController.scala b/app/controllers/ReportingFrequencyPageController.scala
index 8d999acc8b..d4ab387503 100644
--- a/app/controllers/ReportingFrequencyPageController.scala
+++ b/app/controllers/ReportingFrequencyPageController.scala
@@ -21,23 +21,28 @@ import auth.authV2.AuthActions
import config.featureswitch.FeatureSwitching
import config.{AgentItvcErrorHandler, FrontendAppConfig, ItvcErrorHandler}
import controllers.agent.predicates.ClientConfirmedController
+import models.ReportingFrequencyViewModel
import models.admin.ReportingFrequencyPage
+import models.optout.{OptOutMultiYearViewModel, OptOutOneYearViewModel}
import play.api.i18n.I18nSupport
import play.api.mvc._
+import services.DateService
import services.optIn.OptInService
+import services.optout.OptOutService
+import views.html.ReportingFrequencyView
import views.html.errorPages.templates.ErrorTemplate
import javax.inject.Inject
import scala.concurrent.ExecutionContext
-// TODO: Needs view to be implemented
class ReportingFrequencyPageController @Inject()(
- val optInService: OptInService,
+ optOutService: OptOutService,
val authorisedFunctions: FrontendAuthorisedFunctions,
val auth: AuthActions,
- errorTemplate: ErrorTemplate
- )
- (
+ dateService: DateService,
+ errorTemplate: ErrorTemplate,
+ view: ReportingFrequencyView
+ )(
implicit val appConfig: FrontendAppConfig,
mcc: MessagesControllerComponents,
val ec: ExecutionContext,
@@ -48,18 +53,39 @@ class ReportingFrequencyPageController @Inject()(
extends ClientConfirmedController with FeatureSwitching with I18nSupport {
def show(): Action[AnyContent] =
- auth.individualOrAgentWithClient { implicit user =>
- if (isEnabled(ReportingFrequencyPage)) {
- Ok("Reporting Frequency Page - Placeholder")
- } else {
- InternalServerError(
- errorTemplate(
- pageTitle = "standardError.heading",
- heading = "standardError.heading",
- message = "standardError.message",
- isAgent = user.isAgent()
+ auth.individualOrAgentWithClient.async { implicit user =>
+
+ for {
+ (checks, optOutJourneyType) <- optOutService.nextUpdatesPageOptOutViewModels()
+ } yield {
+ if (isEnabled(ReportingFrequencyPage)) {
+
+ val optOutUrl: Option[String] =
+ optOutJourneyType.map {
+ case singleYearModel: OptOutOneYearViewModel =>
+ controllers.optOut.routes.ConfirmOptOutController.show(user.isAgent()).url
+ case multiYearModel: OptOutMultiYearViewModel =>
+ controllers.optOut.routes.OptOutChooseTaxYearController.show(user.isAgent()).url
+ }
+
+ Ok(view(
+ ReportingFrequencyViewModel(
+ isAgent = user.isAgent(),
+ currentTaxYear = dateService.getCurrentTaxYear,
+ nextTaxYear = dateService.getCurrentTaxYear.nextYear,
+ optOutJourneyUrl = optOutUrl
+ )
+ ))
+ } else {
+ InternalServerError(
+ errorTemplate(
+ pageTitle = "standardError.heading",
+ heading = "standardError.heading",
+ message = "standardError.message",
+ isAgent = user.isAgent()
+ )
)
- )
+ }
}
}
}
\ No newline at end of file
diff --git a/app/models/ReportingFrequencyViewModel.scala b/app/models/ReportingFrequencyViewModel.scala
new file mode 100644
index 0000000000..a084b30dc2
--- /dev/null
+++ b/app/models/ReportingFrequencyViewModel.scala
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2024 HM Revenue & Customs
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package models
+
+import models.incomeSourceDetails.TaxYear
+
+case class ReportingFrequencyViewModel(
+ isAgent: Boolean,
+ currentTaxYear: TaxYear,
+ nextTaxYear: TaxYear,
+ optOutJourneyUrl: Option[String]
+ )
\ No newline at end of file
diff --git a/app/services/optout/OptOutService.scala b/app/services/optout/OptOutService.scala
index c20d3ca3e4..761dadab33 100644
--- a/app/services/optout/OptOutService.scala
+++ b/app/services/optout/OptOutService.scala
@@ -137,7 +137,7 @@ class OptOutService @Inject()(itsaStatusUpdateConnector: ITSAStatusUpdateConnect
_ <- repository.initialiseOptOutJourney(proposition)
} yield (nextUpdatesQuarterlyReportingContentChecks(proposition), nextUpdatesOptOutViewModel(proposition))
}
-
+
private def nextUpdatesQuarterlyReportingContentChecks(oop: OptOutProposition) = {
val currentYearStatus = oop.currentTaxYear.status
val previousYearStatus = oop.previousTaxYear.status
diff --git a/app/views/ReportingFrequencyView.scala.html b/app/views/ReportingFrequencyView.scala.html
new file mode 100644
index 0000000000..bd176ba788
--- /dev/null
+++ b/app/views/ReportingFrequencyView.scala.html
@@ -0,0 +1,68 @@
+@*
+ * Copyright 2024 HM Revenue & Customs
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *@
+
+@import models.optin.OptInCompletedViewModel
+@import uk.gov.hmrc.govukfrontend.views.html.components._
+@import views.html.components._
+@import views.html.layouts.unifiedLayout
+@import models.ReportingFrequencyViewModel
+
+@this(
+ mainTemplate: unifiedLayout,
+ h1: h1,
+ h2: h2,
+ p: p,
+ linkComponent: linkComponent,
+ bulletList: bulletPointList,
+ govukTable: GovukTable,
+ govukInsetText : GovukInsetText
+)
+
+@(viewModel: ReportingFrequencyViewModel)(implicit messages: Messages, user: auth.MtdItUser[_])
+
+@manageReportingFrequency = {
+
+ @h2(msg = "reporting.frequency.h2", optId = Some("manage-reporting-frequency-heading"))
+
+ @p(id=Some("change-reporting-frequency")){
+ @messages("reporting.frequency.manageReportingFrequency.p1")
+ }
+
+ @p(id=Some("what-you-can-do")){
+ @messages("reporting.frequency.manageReportingFrequency.p2")
+ }
+
+
+ -
+ @linkComponent(controllers.optIn.routes.BeforeYouStartController.show(viewModel.isAgent).url, message = messages("reporting.frequency.manageReportingFrequency.b1.link", viewModel.currentTaxYear.startYear.toString, viewModel.currentTaxYear.endYear.toString))
+
+ @viewModel.optOutJourneyUrl.map{ url =>
+ -
+ @linkComponent(url, message = messages("reporting.frequency.manageReportingFrequency.b2.link", viewModel.nextTaxYear.startYear.toString, viewModel.nextTaxYear.endYear.toString))
+
+ }
+
+}
+
+@mainTemplate(
+ pageTitle = messages("reporting.frequency.title"),
+ isAgent = viewModel.isAgent,
+ btaNavPartial = user.btaNavPartial
+) {
+
+ @h1(msg = "reporting.frequency.h1", id = Some("reporting-frequency-heading"))
+ @manageReportingFrequency
+}
\ No newline at end of file
diff --git a/app/views/components/linkComponent.scala.html b/app/views/components/linkComponent.scala.html
new file mode 100644
index 0000000000..a6e0f2a742
--- /dev/null
+++ b/app/views/components/linkComponent.scala.html
@@ -0,0 +1,36 @@
+@*
+ * Copyright 2023 HM Revenue & Customs
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *@
+
+@this()
+
+@(
+ url: String,
+ classes: String = "",
+ message: String,
+ id: Option[String] = None,
+ target: Option[String] = None,
+ ariaLabel: Option[String] = None,
+ role: Option[String] = None,
+ rel: Option[String] = None,
+ additionalOpenTabMessage: Option[String] = None
+)(implicit messages: Messages)
+
+ s"id=$id") @if(rel.isDefined){rel="@rel.map(c=>s"$c")"} @target.map(target => s"target=$target") @role.map(role => s"role=$role")>
+ @message
+ @if(target == Some("_blank")){
+ @messages("pagehelp.opensInNewTabText")@additionalOpenTabMessage.map(message => message)
+ }
+
diff --git a/conf/messages b/conf/messages
index 3bc9b7f39f..1dcec764e5 100644
--- a/conf/messages
+++ b/conf/messages
@@ -2347,3 +2347,20 @@ optIn.confirmTaxYear.cancel = Cancel
optIn.confirmNextTaxYear.heading = Confirm and opt in from {0} to {1} tax year onwards
optIn.confirmNextTaxYear.desc = If you opt in for the next tax year, from {0} you will need to submit your quarterly updates through compatible software.
+
+
+# Reporting Frequency Page
+
+reporting.frequency.title = Your reporting frequency
+
+reporting.frequency.h1 = Your reporting frequency
+reporting.frequency.h2 = Manage your reporting frequency for all your businesses
+
+reporting.frequency.manageReportingFrequency.p1 = If you are reporting annually or voluntarily reporting quarterly, you may be able to change your reporting frequency for specific tax years.
+reporting.frequency.manageReportingFrequency.p2 = This is what you can do for all your businesses:
+reporting.frequency.manageReportingFrequency.b1.link = Opt in to quarterly reporting for the {0} to {1} tax year
+reporting.frequency.manageReportingFrequency.b2.link = Opt out of quarterly reporting and report annually from the {0} to {1} tax year onwards
+
+
+
+
diff --git a/conf/messages.cy b/conf/messages.cy
index d42282b7bc..bffe3eb9ed 100644
--- a/conf/messages.cy
+++ b/conf/messages.cy
@@ -2281,4 +2281,14 @@ optIn.confirmTaxYear.confirmSaveBtn = Cadarnhau a chadw
optIn.confirmTaxYear.cancel = Canslo
optIn.confirmNextTaxYear.heading = Cadarnhau ac optio i mewn ar gyfer blwyddyn dreth {0} i {1} ymlaen
-optIn.confirmNextTaxYear.desc = Os byddwch yn optio i mewn ar gyfer y flwyddyn dreth nesaf, o {0} ymlaen, bydd angen i chi gyflwyno’ch adroddiadau chwarterol drwy ddefnyddio meddalwedd sy’n cydweddu.
\ No newline at end of file
+optIn.confirmNextTaxYear.desc = Os byddwch yn optio i mewn ar gyfer y flwyddyn dreth nesaf, o {0} ymlaen, bydd angen i chi gyflwyno’ch adroddiadau chwarterol drwy ddefnyddio meddalwedd sy’n cydweddu.
+
+# Reporting Frequency Page
+
+reporting.frequency.h2 = Rheoli amlder eich adroddiadau ar gyfer eich holl fusnesau
+
+reporting.frequency.manageReportingFrequency.p1 = Os ydych yn adrodd yn flynyddol, neu’n adrodd yn chwarterol yn wirfoddol, mae’n bosibl y byddwch yn gallu newid amlder eich adroddiadau ar gyfer blynyddoedd treth penodol.
+reporting.frequency.manageReportingFrequency.p2 = Yr hyn y gallwch ei wneud ar gyfer eich holl fusnesau:
+reporting.frequency.manageReportingFrequency.b1.link = Optio i mewn i adrodd yn chwarterol ar gyfer blwyddyn dreth {0} i {1}
+reporting.frequency.manageReportingFrequency.b2.link = Optio allan o adrodd yn chwarterol, a mynd ati i adrodd yn flynyddol o flwyddyn dreth {0} i {1} ymlaen
+
diff --git a/it/test/controllers/NextUpdatesControllerISpec.scala b/it/test/controllers/NextUpdatesControllerISpec.scala
index d9f27db4e5..334504cee4 100644
--- a/it/test/controllers/NextUpdatesControllerISpec.scala
+++ b/it/test/controllers/NextUpdatesControllerISpec.scala
@@ -182,6 +182,7 @@ class NextUpdatesControllerISpec extends ComponentSpecBase {
}
"the user has a Opt Out Feature Switch Enabled" in {
+
enable(OptOut)
val currentTaxYear = dateService.getCurrentTaxYearEnd
diff --git a/it/test/controllers/ReportingFrequencyControllerISpec.scala b/it/test/controllers/ReportingFrequencyControllerISpec.scala
index 6b80c36e70..345d670c02 100644
--- a/it/test/controllers/ReportingFrequencyControllerISpec.scala
+++ b/it/test/controllers/ReportingFrequencyControllerISpec.scala
@@ -19,9 +19,9 @@ package controllers
import com.github.tomakehurst.wiremock.client.WireMock
import config.FrontendAppConfig
import config.featureswitch.FeatureSwitching
-import helpers.servicemocks.{AuthStub, IncomeTaxViewChangeStub}
+import helpers.servicemocks.{AuthStub, ITSAStatusDetailsStub, IncomeTaxViewChangeStub}
import models.admin.FeatureSwitchName.allFeatureSwitches
-import models.admin.ReportingFrequencyPage
+import models.admin.{OptOut, ReportingFrequencyPage}
import org.jsoup.Jsoup
import play.api.http.HeaderNames
import play.api.http.Status.{INTERNAL_SERVER_ERROR, OK}
@@ -61,11 +61,13 @@ class ReportingFrequencyControllerISpec extends ControllerISpecBase with Feature
"return the ReportingFrequency page, OK - 200" in {
- AuthStub.stubAuthorised()
- IncomeTaxViewChangeStub.stubGetIncomeSourceDetailsResponse(testMtditid)(OK, businessAndPropertyResponseWoMigration)
-
allFeatureSwitches.foreach(switch => disable(switch))
enable(ReportingFrequencyPage)
+ enable(OptOut)
+
+ AuthStub.stubAuthorised()
+ IncomeTaxViewChangeStub.stubGetIncomeSourceDetailsResponse(testMtditid)(OK, businessAndPropertyResponseWoMigration)
+ ITSAStatusDetailsStub.stubGetITSAStatusFutureYearsDetails(dateService.getCurrentTaxYearEnd)
val res =
httpClient
@@ -74,8 +76,7 @@ class ReportingFrequencyControllerISpec extends ControllerISpecBase with Feature
.execute[HttpResponse]
res.futureValue.status shouldBe OK
- // Jsoup.parse(res.futureValue.body).title shouldBe "New page title" //TODO: change the test to look for the title of the new page when implemented
- res.futureValue.body shouldBe "Reporting Frequency Page - Placeholder"
+ Jsoup.parse(res.futureValue.body).title shouldBe "Your reporting frequency - Manage your Income Tax updates - GOV.UK"
}
}
}
diff --git a/it/test/testConstants/IncomeSourceIntegrationTestConstants.scala b/it/test/testConstants/IncomeSourceIntegrationTestConstants.scala
index c325670c4a..26a20ec39b 100644
--- a/it/test/testConstants/IncomeSourceIntegrationTestConstants.scala
+++ b/it/test/testConstants/IncomeSourceIntegrationTestConstants.scala
@@ -153,8 +153,8 @@ object IncomeSourceIntegrationTestConstants {
)
val multipleBusinessesResponse: IncomeSourceDetailsResponse = IncomeSourceDetailsModel(
- testNino,
- testMtdItId,
+ nino = testNino,
+ mtdbsa = testMtdItId,
businesses = List(
business1,
business2
diff --git a/test/controllers/ReportingFrequencyPageControllerSpec.scala b/test/controllers/ReportingFrequencyPageControllerSpec.scala
index 121dd875fe..abcddc6d26 100644
--- a/test/controllers/ReportingFrequencyPageControllerSpec.scala
+++ b/test/controllers/ReportingFrequencyPageControllerSpec.scala
@@ -21,8 +21,10 @@ import auth.authV2.actions._
import config.{AgentItvcErrorHandler, FrontendAppConfig, ItvcErrorHandler}
import mocks.auth.MockOldAuthActions
import mocks.controllers.predicates.MockIncomeSourceDetailsPredicate
+import models.ReportingFrequencyViewModel
import models.admin.ReportingFrequencyPage
-import models.incomeSourceDetails.IncomeSourceDetailsModel
+import models.incomeSourceDetails.{IncomeSourceDetailsModel, TaxYear}
+import models.optout.{NextUpdatesQuarterlyReportingContentChecks, OptOutMultiYearViewModel}
import org.mockito.ArgumentMatchers
import org.mockito.ArgumentMatchers.any
import org.mockito.Mockito.when
@@ -30,10 +32,12 @@ import org.scalatestplus.mockito.MockitoSugar
import play.api.http.Status.{INTERNAL_SERVER_ERROR, OK}
import play.api.mvc.MessagesControllerComponents
import play.api.test.Helpers.{contentAsString, defaultAwaitTimeout, status}
-import services.optIn.OptInService
+import services.DateService
+import services.optout.OptOutService
import testConstants.BaseTestConstants
import testConstants.BaseTestConstants.testNino
import testConstants.BusinessDetailsTestConstants.{business1, testMtdItId}
+import views.html.ReportingFrequencyView
import views.html.errorPages.templates.ErrorTemplate
import scala.concurrent.Future
@@ -42,21 +46,25 @@ import scala.concurrent.Future
class ReportingFrequencyPageControllerSpec extends MockOldAuthActions with MockIncomeSourceDetailsPredicate with MockitoSugar {
val mockFrontendAppConfig: FrontendAppConfig = mock[FrontendAppConfig]
- val mockOptInService: OptInService = mock[OptInService]
+ val mockOptOutService: OptOutService = mock[OptOutService]
val mockFrontendAuthorisedFunctions: FrontendAuthorisedFunctions = mock[FrontendAuthorisedFunctions]
val mockNonAgentItvcErrorHandler: ItvcErrorHandler = mock[ItvcErrorHandler]
val mockAgentItvcErrorHandler: AgentItvcErrorHandler = mock[AgentItvcErrorHandler]
+ val mockDateService: DateService = mock[DateService]
val errorTemplateView: ErrorTemplate = app.injector.instanceOf[ErrorTemplate]
+ val reportingFrequencyView: ReportingFrequencyView = app.injector.instanceOf[ReportingFrequencyView]
val mockAuthoriseAndRetrieve: AuthoriseAndRetrieve = mock[AuthoriseAndRetrieve]
val controller =
new ReportingFrequencyPageController(
- optInService = mockOptInService,
+ optOutService = mockOptOutService,
authorisedFunctions = mockFrontendAuthorisedFunctions,
auth = mockAuthActions,
- errorTemplate = errorTemplateView
+ dateService = dateService,
+ errorTemplate = errorTemplateView,
+ view = reportingFrequencyView
)(
appConfig = mockFrontendAppConfig,
mcc = app.injector.instanceOf[MessagesControllerComponents],
@@ -81,6 +89,15 @@ class ReportingFrequencyPageControllerSpec extends MockOldAuthActions with MockI
setupMockAuthRetrievalSuccess(BaseTestConstants.testIndividualAuthSuccessWithSaUtrResponse())
+ when(mockOptOutService.nextUpdatesPageOptOutViewModels()(any(), any(), any())).thenReturn(
+ Future(
+ (
+ NextUpdatesQuarterlyReportingContentChecks(currentYearItsaStatus = true, previousYearItsaStatus = true, previousYearCrystallisedStatus = true),
+ Some(OptOutMultiYearViewModel())
+ )
+ )
+ )
+
when(mockFrontendAppConfig.readFeatureSwitchesFromMongo).thenReturn(false)
when(
@@ -90,7 +107,15 @@ class ReportingFrequencyPageControllerSpec extends MockOldAuthActions with MockI
val result = controller.show()(fakeRequestWithActiveSession)
status(result) shouldBe OK
- contentAsString(result) shouldBe "Reporting Frequency Page - Placeholder"
+ contentAsString(result) shouldBe
+ reportingFrequencyView(
+ ReportingFrequencyViewModel(
+ isAgent = false,
+ currentTaxYear = TaxYear(2023, 2024),
+ nextTaxYear = TaxYear(2024, 2025),
+ Some(controllers.optOut.routes.OptOutChooseTaxYearController.show(false).url)
+ )
+ ).toString
}
}
@@ -103,6 +128,15 @@ class ReportingFrequencyPageControllerSpec extends MockOldAuthActions with MockI
val singleBusinessIncome = IncomeSourceDetailsModel(testNino, testMtdItId, Some("2017"), List(business1), Nil)
+ when(mockOptOutService.nextUpdatesPageOptOutViewModels()(any(), any(), any())).thenReturn(
+ Future(
+ (
+ NextUpdatesQuarterlyReportingContentChecks(currentYearItsaStatus = true, previousYearItsaStatus = true, previousYearCrystallisedStatus = true),
+ Some(OptOutMultiYearViewModel())
+ )
+ )
+ )
+
when(mockFrontendAppConfig.readFeatureSwitchesFromMongo)
.thenReturn(false)
diff --git a/test/testUtils/TestSupport.scala b/test/testUtils/TestSupport.scala
index 5ad2463a13..d652bdcbcf 100644
--- a/test/testUtils/TestSupport.scala
+++ b/test/testUtils/TestSupport.scala
@@ -85,6 +85,7 @@ trait TestSupport extends UnitSpec with GuiceOneAppPerSuite with BeforeAndAfterA
// Set fixed date for DateService
lazy val fixedDate: LocalDate = LocalDate.of(2023, 12, 15)
+
implicit val dateService: DateService = new DateService {
override def getCurrentDate: LocalDate = fixedDate
diff --git a/test/views/ReportingFrequencyViewSpec.scala b/test/views/ReportingFrequencyViewSpec.scala
new file mode 100644
index 0000000000..59022cf37c
--- /dev/null
+++ b/test/views/ReportingFrequencyViewSpec.scala
@@ -0,0 +1,152 @@
+/*
+ * Copyright 2023 HM Revenue & Customs
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package views
+
+import models.ReportingFrequencyViewModel
+import models.incomeSourceDetails.TaxYear
+import org.jsoup.Jsoup
+import org.jsoup.nodes.Document
+import play.api.test.Helpers._
+import testUtils.TestSupport
+import views.html.ReportingFrequencyView
+import views.messages.ReportingFrequencyViewMessages._
+
+
+class ReportingFrequencyViewSpec extends TestSupport {
+
+ val view: ReportingFrequencyView = app.injector.instanceOf[ReportingFrequencyView]
+
+ def beforeYouStartUrl(isAgent: Boolean): String = controllers.optIn.routes.BeforeYouStartController.show(isAgent).url
+
+ def optOutChooseTaxYearUrl(isAgent: Boolean): String = controllers.optOut.routes.OptOutChooseTaxYearController.show(isAgent).url
+
+ def confirmOptOutUrl(isAgent: Boolean): String = controllers.optOut.routes.ConfirmOptOutController.show(isAgent).url
+
+ def bullet(i: Int): String = s"#main-content > div > div > div > ul > li:nth-child($i) > a"
+
+ object Selectors {
+ val h1 = "reporting-frequency-heading"
+ val h2 = "manage-reporting-frequency-heading"
+ val p1 = "change-reporting-frequency"
+ val p2 = "what-you-can-do"
+ }
+
+ "ReportingFrequencyView" when {
+
+ "the user is an Agent" should {
+
+ "return the correct content" in {
+
+ val isAgentFlag = true
+
+ val reportingFrequencyViewModel: ReportingFrequencyViewModel =
+ ReportingFrequencyViewModel(
+ isAgent = isAgentFlag,
+ TaxYear(2024, 2025),
+ TaxYear(2025, 2026),
+ Some(optOutChooseTaxYearUrl(isAgentFlag))
+ )
+
+ val pageDocument: Document =
+ Jsoup.parse(
+ contentAsString(
+ view.apply(
+ viewModel = reportingFrequencyViewModel
+ )
+ )
+ )
+
+ def testContentByIds(idsAndContent: Seq[(String, String)]): Unit =
+ idsAndContent.foreach {
+ case (selectors, content) =>
+ pageDocument.getElementById(selectors).text() shouldBe content
+ }
+
+ val expectedContent: Seq[(String, String)] =
+ Seq(
+ Selectors.h1 -> h1Content,
+ Selectors.h2 -> h2Content,
+ Selectors.p1 -> p1Content,
+ Selectors.p2 -> p2Content,
+ )
+
+ pageDocument.title() shouldBe agentTitle
+
+ testContentByIds(expectedContent)
+
+ pageDocument.select(bullet(1)).text() shouldBe bullet1Content
+
+ pageDocument.select(bullet(1)).attr("href") shouldBe beforeYouStartUrl(isAgentFlag)
+
+ pageDocument.select(bullet(2)).text() shouldBe bullet2Content
+
+ pageDocument.select(bullet(2)).attr("href") shouldBe optOutChooseTaxYearUrl(isAgentFlag)
+ }
+ }
+
+ "the user is Non-Agent" should {
+
+ "return the correct content" in {
+
+ val isAgentFlag = false
+
+ val reportingFrequencyViewModel: ReportingFrequencyViewModel =
+ ReportingFrequencyViewModel(
+ isAgent = isAgentFlag,
+ TaxYear(2024, 2025),
+ TaxYear(2025, 2026),
+ Some(confirmOptOutUrl(isAgentFlag))
+ )
+
+ val pageDocument: Document =
+ Jsoup.parse(
+ contentAsString(
+ view.apply(
+ viewModel = reportingFrequencyViewModel
+ )
+ )
+ )
+
+ def testContentByIds(idsAndContent: Seq[(String, String)]): Unit =
+ idsAndContent.foreach {
+ case (selectors, content) =>
+ pageDocument.getElementById(selectors).text() shouldBe content
+ }
+
+ val expectedContent: Seq[(String, String)] =
+ Seq(
+ Selectors.h1 -> h1Content,
+ Selectors.h2 -> h2Content,
+ Selectors.p1 -> p1Content,
+ Selectors.p2 -> p2Content,
+ )
+
+ pageDocument.title() shouldBe title
+
+ testContentByIds(expectedContent)
+
+ pageDocument.select(bullet(1)).text() shouldBe bullet1Content
+
+ pageDocument.select(bullet(1)).attr("href") shouldBe beforeYouStartUrl(isAgentFlag)
+
+ pageDocument.select(bullet(2)).text() shouldBe bullet2Content
+
+ pageDocument.select(bullet(2)).attr("href") shouldBe confirmOptOutUrl(isAgentFlag)
+ }
+ }
+ }
+}
diff --git a/test/views/messages/ReportingFrequencyViewMessages.scala b/test/views/messages/ReportingFrequencyViewMessages.scala
new file mode 100644
index 0000000000..b429ac2af3
--- /dev/null
+++ b/test/views/messages/ReportingFrequencyViewMessages.scala
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2024 HM Revenue & Customs
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package views.messages
+
+object ReportingFrequencyViewMessages {
+
+ val title = "Your reporting frequency - Manage your Income Tax updates - GOV.UK"
+ val agentTitle = "Your reporting frequency - Manage your client’s Income Tax updates - GOV.UK"
+ val h1Content = "Your reporting frequency"
+ val h2Content = "Manage your reporting frequency for all your businesses"
+ val p1Content = "If you are reporting annually or voluntarily reporting quarterly, you may be able to change your reporting frequency for specific tax years."
+ val p2Content = "This is what you can do for all your businesses:"
+ val bullet1Content = "Opt in to quarterly reporting for the 2024 to 2025 tax year"
+ val bullet2Content = "Opt out of quarterly reporting and report annually from the 2025 to 2026 tax year onwards"
+
+}