<commit_before>/*
 * Copyright 2017 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 iht.views.application

import iht.views.ViewTestHelper
import org.jsoup.nodes.Document
import play.api.data.{Form, FormError}
import play.api.i18n.Messages
import play.api.mvc.{AnyContentAsEmpty, Call}
import play.api.test.FakeRequest
import play.twirl.api.HtmlFormat.Appendable

trait ApplicationPageBehaviour[A] extends ViewTestHelper {
  def pageTitle: String
  def browserTitle: String

  implicit def request: FakeRequest[AnyContentAsEmpty.type] = createFakeRequest()
  def view: String = formToView(form).toString
  def doc: Document = asDocument(view)
  def form:Form[A] = ???
  def formToView:Form[A] => Appendable = ???

  def applicationPage() = {
    "have the correct title" in {
      titleShouldBeCorrect(view, pageTitle)
    }

    "have the correct browser title" in {
      browserTitleShouldBeCorrect(view, browserTitle)
    }

    "have a Continue button" in {
      doc.getElementById("save-continue").text shouldBe Messages("iht.saveAndContinue")
      //doc.getElementsByClass("button").first.attr("value") shouldBe Messages("iht.saveAndContinue")
    }
  }

  def applicationPageWithErrorSummaryBox() = {
    applicationPage()
    "display the 'There's a problem' box if there's an error" in {
      val newForm = form.withError(FormError("field","error message"))
      val document = asDocument(formToView(newForm).toString)
      document.getElementById("errors").children.first.text shouldBe Messages("error.problem")
    }
  }

  def applicationPageInEditModeWithErrorSummaryBox(view: => Document, cancelUrl: => Call) = {
    applicationPageWithErrorSummaryBox()

    "have a continue and cancel link in edit mode" in {
      val continueLink = view.getElementById("continue-button")
      continueLink.attr("value") shouldBe Messages("iht.continue")

      val cancelLink = view.getElementById("cancel-button")
      cancelLink.attr("href") shouldBe cancelUrl.url
      cancelLink.text() shouldBe Messages("site.link.cancel")
    }
  }
}<commit_msg>IHT-4436 Tidy<commit_after>/*
 * Copyright 2017 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 iht.views.application

import iht.views.ViewTestHelper
import org.jsoup.nodes.Document
import play.api.data.{Form, FormError}
import play.api.i18n.Messages
import play.api.mvc.{AnyContentAsEmpty, Call}
import play.api.test.FakeRequest
import play.twirl.api.HtmlFormat.Appendable

trait ApplicationPageBehaviour[A] extends ViewTestHelper {
  def pageTitle: String

  def browserTitle: String

  implicit def request: FakeRequest[AnyContentAsEmpty.type] = createFakeRequest()

  def view: String = formToView(form).toString

  def doc: Document = asDocument(view)

  def form: Form[A] = ???

  def formToView: Form[A] => Appendable = ???

  def applicationPage() = {
    "have the correct title" in {
      titleShouldBeCorrect(view, pageTitle)
    }

    "have the correct browser title" in {
      browserTitleShouldBeCorrect(view, browserTitle)
    }

    "have a Continue button" in {
      doc.getElementById("save-continue").text shouldBe Messages("iht.saveAndContinue")
    }
  }

  def applicationPageWithErrorSummaryBox() = {
    applicationPage()
    "display the 'There's a problem' box if there's an error" in {
      val newForm = form.withError(FormError("field", "error message"))
      val document = asDocument(formToView(newForm).toString)
      document.getElementById("errors").children.first.text shouldBe Messages("error.problem")
    }
  }

  def applicationPageInEditModeWithErrorSummaryBox(view: => Document, cancelUrl: => Call) = {
    applicationPageWithErrorSummaryBox()

    "have a continue and cancel link in edit mode" in {
      val continueLink = view.getElementById("continue-button")
      continueLink.attr("value") shouldBe Messages("iht.continue")

      val cancelLink = view.getElementById("cancel-button")
      cancelLink.attr("href") shouldBe cancelUrl.url
      cancelLink.text() shouldBe Messages("site.link.cancel")
    }
  }
}
{'fraction_non_alphanumeric': 0.10101602188354826, 'fraction_numerical': 0.004689331770222743, 'mean_word_length': 4.098605577689243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7147891', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1422, 'n_words': 427}