Skip to content

Commit

Permalink
[MIBM-145][PH] improve AgentDetailsPageSpec (#76)
Browse files Browse the repository at this point in the history
* [MIBM-145][PH] improve AgentDetailsPageSpec

* [MIBM-145][PH] improve /VehicleRegistrationNumberPageSpec
  • Loading branch information
PaulHodgson authored Oct 26, 2020
1 parent 20de327 commit eaba395
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@

package uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs

import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.DeclarationJourney
import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.AgentDetailsPage

class AgentDetailsPageSpec extends BasePageSpec[AgentDetailsPage] {
class AgentDetailsPageSpec extends DeclarationDataCapturePageSpec[String, AgentDetailsPage] {
override lazy val page: AgentDetailsPage = agentDetailsPage
private val title = "Enter the business name of the customs agent"

"the page" should {
behave like aPageWhichRenders(givenAnImportJourneyIsStarted(), title)
behave like aPageWhichRequiresADeclarationJourney()
behave like aPageWhichRenders(givenAnImportJourneyIsStarted(), title)
behave like aPageWhichDisplaysPreviouslyEnteredAnswers()

"allow the user to navigate to the /enter-agent-address" in {
givenAnImportJourneyIsStarted()
val redirectedPath = submitAndEnsurePersistence(givenAnImportJourneyIsStarted(), "test agent")

page.open()
page.fillOutForm("test agent")
page.mustRedirectToAddressLookupFromTheCTA()
val successfulRedirectDependingOnWhetherAddressLookupIsAvailable =
redirectedPath == "/merchandise-in-baggage/enter-agent-address" || redirectedPath.startsWith("/lookup-address")
successfulRedirectDependingOnWhetherAddressLookupIsAvailable mustBe true
}
}

override def extractFormDataFrom(declarationJourney: DeclarationJourney): Option[String] =
declarationJourney.maybeCustomsAgentName
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,14 @@ trait BasePageSpec[P <: BasePage] extends BaseSpecWithApplication with WireMockS
}
}
}

def aPageWhichRequiresACustomsAgentDeclaration() : Unit = {
s"redirect to ${InvalidRequestPage.path}" when {
"the declaration has been started but the user has not declared whether or not they are a customs agent" in {
givenADeclarationJourney(completedDeclarationJourney.copy(maybeIsACustomsAgent = None))
page.open() mustBe InvalidRequestPage.path
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ trait DeclarationDataCapturePageSpec[F, P <: DeclarationDataCapturePage[F]] exte
def aDataCapturePageWithConditionalRouting(setUp: => Unit = Unit, formData: F, expectedPath: String): Unit = {
s"redirect to $expectedPath" when {
s"the form is filled with $formData" in {
submitAndEnsurePersistence(setUp, formData, expectedPath)
submitAndEnsurePersistence(setUp, formData) mustBe expectedPath
}
}
}
Expand All @@ -47,13 +47,13 @@ trait DeclarationDataCapturePageSpec[F, P <: DeclarationDataCapturePage[F]] exte
s"redirect to $expectedPath" when {
allFormData.foreach { formData =>
s"the form is filled with $formData" in {
submitAndEnsurePersistence(setUp, formData, expectedPath)
submitAndEnsurePersistence(setUp, formData) mustBe expectedPath
}
}
}
}

private def submitAndEnsurePersistence(setUp: => Unit = Unit, formData: F, expectedPath: String) = {
def submitAndEnsurePersistence(setUp: => Unit = Unit, formData: F): String = {
def ensurePersistence = {
val persistedJourneys = declarationJourneyRepository.findAll().futureValue
persistedJourneys.size mustBe 1
Expand All @@ -63,8 +63,10 @@ trait DeclarationDataCapturePageSpec[F, P <: DeclarationDataCapturePage[F]] exte
setUp
page.open()
page.fillOutForm(formData)
page.clickOnCTA() mustBe expectedPath
val path = page.clickOnCTA()

ensurePersistence

path
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class EoriNumberPageSpec extends DeclarationDataCapturePageSpec[Eori, EoriNumber
givenADeclarationJourney(startedDeclarationJourney.copy(maybeIsACustomsAgent = Some(No)))

"the eori number page" should {
behave like aPageWhichRequiresADeclarationJourney()
behave like aPageWhichRequiresACustomsAgentDeclaration()
behave like aPageWhichRenders(givenAnAgentJourney(), expectedAgentTitle)
behave like aPageWhichRenders(givenANonAgentJourney(), expectedNonAgentTitle)
behave like aPageWhichDisplaysPreviouslyEnteredAnswers()
behave like aPageWhichRequiresADeclarationJourney()
behave like aDataCapturePageWithSimpleRouting(givenACompleteDeclarationJourney(), Seq(eori), TravellerDetailsPage.path)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@

package uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs

import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.VehicleRegistrationNumberPage
import uk.gov.hmrc.merchandiseinbaggagefrontend.model.core.DeclarationJourney
import uk.gov.hmrc.merchandiseinbaggagefrontend.pagespecs.pages.{CheckYourAnswersPage, InvalidRequestPage, VehicleRegistrationNumberPage}

class VehicleRegistrationNumberPageSpec extends BasePageSpec[VehicleRegistrationNumberPage] {
class VehicleRegistrationNumberPageSpec extends DeclarationDataCapturePageSpec[String, VehicleRegistrationNumberPage] {
override lazy val page: VehicleRegistrationNumberPage = vehicleRegistrationNumberPage

private val expectedTitle = "What is the registration number of the vehicle?"
private val registrationNumber = "reg 123"

"the page" should {
behave like aPageWhichRenders(givenAnImportJourneyIsStarted(), expectedTitle)
behave like aPageWhichRequiresADeclarationJourney()

"redirect user to /check-your-answers onSubmit" in {
givenACompleteDeclarationJourney()

page.open()
page.fillOutForm("AB51 CDE")
page.mustRedirectToCheckYourAnswersFromTheCTA()
}
behave like aPageWhichRenders(givenAnImportJourneyIsStarted(), expectedTitle)
behave like aPageWhichDisplaysPreviouslyEnteredAnswers()
behave like aDataCapturePageWithConditionalRouting(givenACompleteDeclarationJourney(), registrationNumber, CheckYourAnswersPage.path)
behave like aDataCapturePageWithConditionalRouting(givenAnImportJourneyIsStarted(), registrationNumber, InvalidRequestPage.path)
}

override def extractFormDataFrom(declarationJourney: DeclarationJourney): Option[String] =
declarationJourney.maybeRegistrationNumber
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,20 @@ import org.openqa.selenium.WebDriver
import org.scalatest.Assertion
import org.scalatestplus.selenium.WebBrowser

class AgentDetailsPage(baseUrl: BaseUrl)(implicit webDriver: WebDriver) extends PageWithCTA(baseUrl) {
class AgentDetailsPage(baseUrl: BaseUrl)(implicit webDriver: WebDriver) extends DeclarationDataCapturePage[String](baseUrl) {
override val path: String = AgentDetailsPage.path

import WebBrowser._

def fillOutForm(value: String): Unit = {
click on find(NameQuery("value")).get
enter(value)
}

def mustRedirectToAddressLookupFromTheCTA(): Assertion = {
click on find(NameQuery("continue")).get
private def input = find(NameQuery("value")).get

val redirectedTo = readPath()
val successfulRedirectDependingOnWhetherAddressLookupIsAvailable =
redirectedTo == "/merchandise-in-baggage/enter-agent-address" || redirectedTo.startsWith("/lookup-address")
successfulRedirectDependingOnWhetherAddressLookupIsAvailable mustBe true
override def fillOutForm(agentDetails: String): Unit = {
click on input
enter(agentDetails)
}

override def previouslyEnteredValuesAreDisplayed(agentDetails: String): Assertion =
input.attribute("value") mustBe Some(agentDetails)
}

object AgentDetailsPage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ class EoriNumberPage(baseUrl: BaseUrl)(implicit webDriver: WebDriver)

override val path = "/merchandise-in-baggage/enter-eori-number"

private def input: Element = find(IdQuery("eori")).get

override def previouslyEnteredValuesAreDisplayed(eori: Eori): Assertion =
find(IdQuery("eori")).get.attribute("value") mustBe Some(eori.value)
input.attribute("value") mustBe Some(eori.value)

override def fillOutForm(eori: Eori): Unit = {
click on find(IdQuery("eori")).get
click on input
enter(eori.value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ import org.openqa.selenium.WebDriver
import org.scalatest.Assertion
import org.scalatestplus.selenium.WebBrowser

class VehicleRegistrationNumberPage(baseUrl: BaseUrl)(implicit webDriver: WebDriver) extends PageWithCTA(baseUrl) {
class VehicleRegistrationNumberPage(baseUrl: BaseUrl)(implicit webDriver: WebDriver) extends DeclarationDataCapturePage[String](baseUrl) {
override val path = "/merchandise-in-baggage/vehicle-registration-number"

import WebBrowser._

def fillOutForm(value: String): Unit = {
click on find(NameQuery("value")).get
enter(value)
}

def mustRedirectToCheckYourAnswersFromTheCTA(): Assertion = {
click on find(NameQuery("continue")).get
def input: Element = find(NameQuery("value")).get

readPath() mustBe "/merchandise-in-baggage/check-your-answers"
override def fillOutForm(registrationNumber: String): Unit = {
click on input
enter(registrationNumber)
}

override def previouslyEnteredValuesAreDisplayed(registrationNumber: String): Assertion =
input.attribute("value") mustBe Some(registrationNumber)
}

0 comments on commit eaba395

Please sign in to comment.