From 5af0b5fd9d76e2b3df313919fae7f2c76367b528 Mon Sep 17 00:00:00 2001 From: Paul Hodgson Date: Mon, 2 Nov 2020 14:02:34 +0000 Subject: [PATCH] [MIBM-145][PH] add TravellerDetailsPageSpec (#92) --- .../views/TravellerDetailsPage.scala.html | 2 +- .../pagespecs/BasePageSpec.scala | 3 +- .../pagespecs/CustomsAgentPageSpec.scala | 4 +-- .../pagespecs/TravellerDetailsPageSpec.scala | 36 +++++++++++++++++++ .../pages/TravellerDetailsPage.scala | 31 +++++++++++++++- 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/TravellerDetailsPageSpec.scala diff --git a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/TravellerDetailsPage.scala.html b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/TravellerDetailsPage.scala.html index 59c3cd728..b7fad84de 100644 --- a/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/TravellerDetailsPage.scala.html +++ b/app/uk/gov/hmrc/merchandiseinbaggagefrontend/views/TravellerDetailsPage.scala.html @@ -50,6 +50,6 @@ isPageHeading = false ) - @button("site.continue") + @button("site.continue", name=Some("continue")) } } diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/BasePageSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/BasePageSpec.scala index 453c6eb71..9c444429f 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/BasePageSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/BasePageSpec.scala @@ -20,7 +20,7 @@ import com.softwaremill.macwire.wire import org.openqa.selenium.htmlunit.HtmlUnitDriver import org.scalatestplus.selenium.WebBrowser import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{DeclarationJourney, GoodsDestination, GoodsVatRate, YesNo} -import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.{RadioButtonPage, _} +import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.{RadioButtonPage, TravellerDetailsPage, _} import uk.gov.hmrc.merchandiseinbaggagefrontend.{BaseSpecWithApplication, CoreTestData, WireMockSupport} trait BasePageSpec[P <: BasePage] extends BaseSpecWithApplication with WireMockSupport with CoreTestData { @@ -55,6 +55,7 @@ trait BasePageSpec[P <: BasePage] extends BaseSpecWithApplication with WireMockS lazy val agentDetailsPage: AgentDetailsPage = wire[AgentDetailsPage] lazy val paymentCalculationPage: PaymentCalculationPage = wire[PaymentCalculationPage] lazy val eoriNumberPage: EoriNumberPage = wire[EoriNumberPage] + lazy val travellerDetailsPage: TravellerDetailsPage = wire[TravellerDetailsPage] lazy val journeyDetailsPage: JourneyDetailsPage = wire[JourneyDetailsPage] lazy val vehicleRegistrationNumberPage: VehicleRegistrationNumberPage = wire[VehicleRegistrationNumberPage] lazy val checkYourAnswersPage: CheckYourAnswersPage = wire[CheckYourAnswersPage] diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/CustomsAgentPageSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/CustomsAgentPageSpec.scala index a31210e3b..4510390b8 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/CustomsAgentPageSpec.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/CustomsAgentPageSpec.scala @@ -28,8 +28,8 @@ class CustomsAgentPageSpec extends DeclarationDataCapturePageSpec[YesNo, RadioBu "the page" should { behave like aPageWhichRequiresADeclarationJourney(path) - behave like aDataCapturePageWithConditionalRouting(path, setup, Yes, AgentDetailsPage.path) - behave like aDataCapturePageWithConditionalRouting(path, setup, No, EoriNumberPage.path) + behave like aDataCapturePageWithConditionalRouting(path, setup(), Yes, AgentDetailsPage.path) + behave like aDataCapturePageWithConditionalRouting(path, setup(), No, EoriNumberPage.path) "render correctly" when { "the declaration has missing customs agent answer" in { diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/TravellerDetailsPageSpec.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/TravellerDetailsPageSpec.scala new file mode 100644 index 000000000..f79d957bb --- /dev/null +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/TravellerDetailsPageSpec.scala @@ -0,0 +1,36 @@ +/* + * Copyright 2020 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 uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs + +import org.scalatest.concurrent.ScalaFutures +import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.{DeclarationJourney, Name} +import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.{JourneyDetailsPage, TravellerDetailsPage} +import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.TravellerDetailsPage._ + +class TravellerDetailsPageSpec extends DeclarationDataCapturePageSpec[Name, TravellerDetailsPage] with ScalaFutures { + override lazy val page: TravellerDetailsPage = travellerDetailsPage + + "the traveller details page" should { + behave like aPageWhichRequiresADeclarationJourney(path) + behave like aPageWhichRenders(path, givenAnImportJourneyIsStarted(), title) + behave like aPageWhichDisplaysPreviouslyEnteredAnswers(path) + behave like aDataCapturePageWithSimpleRouting(path, givenAnImportJourneyIsStarted(), Seq(Name("Terry", "Test")), JourneyDetailsPage.path) + } + + override def extractFormDataFrom(declarationJourney: DeclarationJourney): Option[Name] = + declarationJourney.maybeNameOfPersonCarryingTheGoods +} diff --git a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/pages/TravellerDetailsPage.scala b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/pages/TravellerDetailsPage.scala index 6b0f098eb..2a5fdddc4 100644 --- a/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/pages/TravellerDetailsPage.scala +++ b/test/uk/gov/hmrc/merchandiseinbaggagefrontend/pagespecs/pages/TravellerDetailsPage.scala @@ -17,9 +17,38 @@ package uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages import org.openqa.selenium.WebDriver +import org.scalatest.Assertion +import org.scalatestplus.selenium.WebBrowser +import uk.gov.hmrc.merchandiseinbaggagefrontend.forms.TravellerDetailsForm +import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.Name -class TravellerDetailsPage(implicit webDriver: WebDriver) extends BasePage +class TravellerDetailsPage(implicit webDriver: WebDriver) extends DeclarationDataCapturePage[Name]{ + + import WebBrowser._ + + def firstNameInput: Element = find(NameQuery(TravellerDetailsForm.firstName)).get + def lastNameInput: Element = find(NameQuery(TravellerDetailsForm.lastName)).get + + override def fillOutForm(formData: Name): Unit = { + def fill(input: Element, value: String): Unit = { + input.underlying.clear() + input.underlying.sendKeys(value) + } + + fill(firstNameInput, formData.firstName) + fill(lastNameInput, formData.lastName) + } + + override def previouslyEnteredValuesAreDisplayed(formData: Name): Assertion = { + def valueMustEqual(element: Element, value: String) = + element.underlying.getAttribute("value") mustBe value + + valueMustEqual(firstNameInput, formData.firstName) + valueMustEqual(lastNameInput, formData.lastName) + } +} object TravellerDetailsPage { val path: String = "/merchandise-in-baggage/traveller-details" + val title: String = "Enter the name of the person carrying the goods" }