<commit_before>package helpers.steps

import pages.disposal_of_vehicle._
import cucumber.api.java.en.{Then, When, Given}
import org.scalatest.Matchers
import services.fakes.FakeVehicleLookupWebService._
import helpers.disposal_of_vehicle.CookieFactoryForUISpecs
import org.openqa.selenium.WebDriver
import helpers.webbrowser.{WebBrowserDSL, WebBrowserDriver}

class VehicleLookupSteps(webBrowserDriver:WebBrowserDriver) extends WebBrowserDSL with Matchers {

  implicit val webDriver = webBrowserDriver.asInstanceOf[WebDriver]

  @Given("""^a motor trader has entered a doc ref number in a valid format$""")
  def a_motor_trader_has_entered_a_doc_ref_number_in_a_valid_format() = {
    buildVehicleLookupSetup

    VehicleLookupPage.vehicleRegistrationNumber enter registrationNumberValid
    VehicleLookupPage.documentReferenceNumber enter referenceNumberValid
  }

  @Given("""^a motor trader has (.*) a VRM in a valid format$""")
  def a_motor_trader_has_entered_a_vrm_in_a_valid_format(vrm:String) = {
    buildVehicleLookupSetup

    VehicleLookupPage.vehicleRegistrationNumber enter vrm
    VehicleLookupPage.documentReferenceNumber enter referenceNumberValid
  }

  @Given("""^a motor trader has (.*) a VRM in an invalid format$""")
  def a_motor_trader_has_entered_a_vrm_in_an_invalid_format(vrm:String) = {
    buildVehicleLookupSetup

    VehicleLookupPage.vehicleRegistrationNumber enter vrm
    VehicleLookupPage.documentReferenceNumber enter referenceNumberValid
  }

  @Given("""^a motor trader has (.*) a doc ref number in an invalid format$""")
  def a_motor_trader_has_entered_a_doc_ref_number_in_an_invalid_format(invalidDocRef:String) = {
    buildVehicleLookupSetup

    VehicleLookupPage.vehicleRegistrationNumber enter registrationNumberValid
    VehicleLookupPage.documentReferenceNumber enter invalidDocRef
  }

  @When("""^they attempt to submit the VRM in addition to other required information$""")
  def they_attempt_to_submit_the_VRM_in_addition_to_other_required_information() = {
    click on VehicleLookupPage.findVehicleDetails
  }

  @When("""^they attempt to submit the doc ref number in addition to other required information$""")
  def they_attempt_to_submit_the_doc_ref_number_in_addition_to_other_required_information() = {
    click on VehicleLookupPage.findVehicleDetails
  }

  @Then("""^the doc ref number is retained$""")
  def the_doc_ref_number_is_retained() = {
    // nothing can be done here to check for this as doc ref no is not displayed TODO NO!!! CHECK if it is in the cache
  }

  @Then("""^the VRM is retained$""")
  def the_vrm_is_retained() = {
    page.text should include(registrationNumberValid)
  }

  private def buildVehicleLookupSetup() {
    go to BeforeYouStartPage

    CookieFactoryForUISpecs
      .setupTradeDetailsIntegration()
      .dealerDetailsIntegration()<commit_msg>Refactor: Improve a no-op test step to actually check the cache for the correct value being written<commit_after>package helpers.steps

import pages.disposal_of_vehicle._
import cucumber.api.java.en.{Then, When, Given}
import org.scalatest.Matchers
import services.fakes.FakeVehicleLookupWebService._
import helpers.disposal_of_vehicle.CookieFactoryForUISpecs
import org.openqa.selenium.WebDriver
import helpers.webbrowser.{WebBrowserDSL, WebBrowserDriver}
import mappings.disposal_of_vehicle.VehicleLookup._

class VehicleLookupSteps(webBrowserDriver:WebBrowserDriver) extends WebBrowserDSL with Matchers {

  implicit val webDriver = webBrowserDriver.asInstanceOf[WebDriver]

  @Given("""^a motor trader has entered a doc ref number in a valid format$""")
  def a_motor_trader_has_entered_a_doc_ref_number_in_a_valid_format() = {
    buildVehicleLookupSetup

    VehicleLookupPage.vehicleRegistrationNumber enter registrationNumberValid
    VehicleLookupPage.documentReferenceNumber enter referenceNumberValid
  }

  @Given("""^a motor trader has (.*) a VRM in a valid format$""")
  def a_motor_trader_has_entered_a_vrm_in_a_valid_format(vrm:String) = {
    buildVehicleLookupSetup

    VehicleLookupPage.vehicleRegistrationNumber enter vrm
    VehicleLookupPage.documentReferenceNumber enter referenceNumberValid
  }

  @Given("""^a motor trader has (.*) a VRM in an invalid format$""")
  def a_motor_trader_has_entered_a_vrm_in_an_invalid_format(vrm:String) = {
    buildVehicleLookupSetup

    VehicleLookupPage.vehicleRegistrationNumber enter vrm
    VehicleLookupPage.documentReferenceNumber enter referenceNumberValid
  }

  @Given("""^a motor trader has (.*) a doc ref number in an invalid format$""")
  def a_motor_trader_has_entered_a_doc_ref_number_in_an_invalid_format(invalidDocRef:String) = {
    buildVehicleLookupSetup

    VehicleLookupPage.vehicleRegistrationNumber enter registrationNumberValid
    VehicleLookupPage.documentReferenceNumber enter invalidDocRef
  }

  @When("""^they attempt to submit the VRM in addition to other required information$""")
  def they_attempt_to_submit_the_VRM_in_addition_to_other_required_information() = {
    click on VehicleLookupPage.findVehicleDetails
  }

  @When("""^they attempt to submit the doc ref number in addition to other required information$""")
  def they_attempt_to_submit_the_doc_ref_number_in_addition_to_other_required_information() = {
    click on VehicleLookupPage.findVehicleDetails
  }

  @Then("""^the doc ref number is retained$""")
  def the_doc_ref_number_is_retained() = {
    val vrn = webDriver.manage().
      getCookieNamed(vehicleLookupFormModelCacheKey).
      getValue

    vrn should include(referenceNumberValid)
  }

  @Then("""^the VRM is retained$""")
  def the_vrm_is_retained() = {
    page.text should include(registrationNumberValid)
  }

  private def buildVehicleLookupSetup() {
    go to BeforeYouStartPage

    CookieFactoryForUISpecs
      .setupTradeDetailsIntegration()
      .dealerDetailsIntegration()
{'fraction_non_alphanumeric': 0.07239200956120881, 'fraction_numerical': 0.0, 'mean_word_length': 5.811627906976744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7239114', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1757, 'n_words': 394}