<commit_before>/*
 * 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 views.status

import forms.EmptyForm
import generators.AmlsReferenceNumberGenerator
import models.FeeResponse
import models.ResponseType.SubscriptionResponseType
import models.status._
import org.joda.time.{DateTime, DateTimeZone, LocalDate}
import org.scalatest.MustMatchers
import play.api.i18n.Messages
import play.api.mvc.Call
import play.twirl.api.{Html, HtmlFormat}
import utils.{AmlsViewSpec, DateHelper}
import views.Fixture
import views.html.include.status._
import views.html.status.components.{fee_information, registration_status, withdraw_or_deregister_information}

class your_registrationSpec extends AmlsViewSpec with MustMatchers with AmlsReferenceNumberGenerator {

  trait ViewFixture extends Fixture {
    implicit val requestWithToken = addTokenForView()

    val feeResponse = FeeResponse(
      SubscriptionResponseType,
      amlsRegistrationNumber,
      150.00,
      Some(100.0),
      None,
      300.0,
      550.0,
      Some("XA000000000000"),
      None,
      new DateTime(2017, 12, 1, 1, 3, DateTimeZone.UTC)
    )

  }

  "your_registration view" must {

    val pageTitle = "Your registration - " + Messages("title.amls") + " - " + Messages("title.gov")

    "have correct title, heading and sub heading" in new ViewFixture {

      val form2 = EmptyForm

      def view = views.html.status.your_registration(amlsRegistrationNumber,
        Some("business Name"),
        Some(feeResponse),
        yourRegistrationInfo = HtmlFormat.empty,
        registrationStatus = HtmlFormat.empty,
        feeInformation = HtmlFormat.empty)

      doc.title must be(pageTitle)
      heading.html must be(Messages("your.registration"))
    }

    "contain registration information" in new ViewFixture {

      def view = views.html.status.your_registration(amlsRegistrationNumber,
        Some("business Name"),
        Some(feeResponse),
        yourRegistrationInfo = Html("some registration information"),
        registrationStatus = HtmlFormat.empty,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("registration-info").html() must include("some registration information")
    }

    "contain registration information for status NotCompleted" in new ViewFixture {

      def view = views.html.status.your_registration(amlsRegistrationNumber,
        Some("business Name"),
        Some(feeResponse),
        yourRegistrationInfo = application_incomplete(Some("business Name")),
        registrationStatus = HtmlFormat.empty,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("incomplete-description").html() must be("Your application to register with HMRC is incomplete. You have 28 days to complete your application from when you last saved your progress.")
      doc.getElementById("return-to-saved-application").html() must include("Return to your application")
      doc.getElementById("return-to-saved-application").html() must include("for business Name")
      doc.getElementById("return-to-saved-application").attr("href") must be(controllers.routes.RegistrationProgressController.get().url)
    }

    "contain correct content for status SubmissionWithdrawn" in new ViewFixture {
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_withdrawn(Some("business Name")),
        registrationStatus = registration_status(status = SubmissionWithdrawn),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-withdrawn-description-1").text() must be("You have withdrawn your application to register with HMRC.")
      doc.getElementById("application-withdrawn-description-2").text() must be("Your business is not registered with HMRC under the Money Laundering Regulations.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Application withdrawn.")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain correct content for status SubmissionDecisionRejected" in new ViewFixture {
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_rejected(Some("business Name")),
        registrationStatus = registration_status(status = SubmissionDecisionRejected),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-rejected-description-1").text() must be("Your application to register with HMRC has been rejected.")
      doc.getElementById("application-rejected-description-2").text() must be("Your business is not registered with HMRC. Your business must not carry out activities that are covered by the Money Laundering Regulations.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Application rejected.")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain correct content for status SubmissionDecisionRevoked" in new ViewFixture {
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_revoked(Some("business Name")),
        registrationStatus = registration_status(status = SubmissionDecisionRevoked),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-revoked-description-1").text() must be("Your registration has been revoked.")
      doc.getElementById("application-revoked-description-2").text() must be("Your business is not registered with HMRC. Your business must not carry out activities that are covered by the Money Laundering Regulations.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Registration revoked.")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain correct content for status SubmissionDecisionExpired" in new ViewFixture {
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_expired(Some("business Name")),
        registrationStatus = registration_status(status = SubmissionDecisionExpired),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-expired-description-1").text() must be("Your registration has expired.")
      doc.getElementById("application-expired-description-2").text() must be("Your business is not registered with HMRC under the Money Laundering Regulations.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Registration expired.")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain correct content for status DeRegistered" in new ViewFixture {
      val deregistrationDate = Some(LocalDate.now())
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_deregistered(Some("business Name")),
        registrationStatus = registration_status(status = DeRegistered, endDate = deregistrationDate),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-deregistered-description-1").text() must be("You have deregistered your business.")
      doc.getElementById("application-deregistered-description-2").text() must be("Your business is not registered with HMRC under the Money Laundering Regulations.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Deregistered on " + DateHelper.formatDate(deregistrationDate.value) + ".")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain registration information for status SubmissionReady" in new ViewFixture {

      def view = views.html.status.your_registration(amlsRegistrationNumber,
        Some("business Name"),
        Some(feeResponse),
        yourRegistrationInfo = application_submission_ready(Call("GET", "/some/url"), Some("business Name")),
        registrationStatus = HtmlFormat.empty,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("registration-info").html() must include("Your application to register with HMRC is ready to submit. You have 28 days to submit your application from when you last saved your progress.")
      doc.getElementById("status-submit").html() must include("Check and submit your application")
      doc.getElementById("status-submit").html() must include("for business Name")
      doc.getElementById("status-submit").attr("href") must be("/some/url")
    }<commit_msg>AMLS-5823 | Unit tests<commit_after>/*
 * 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 views.status

import forms.EmptyForm
import generators.AmlsReferenceNumberGenerator
import models.FeeResponse
import models.ResponseType.SubscriptionResponseType
import models.status._
import org.joda.time.{DateTime, DateTimeZone, LocalDate}
import org.scalatest.MustMatchers
import play.api.i18n.Messages
import play.api.mvc.Call
import play.twirl.api.{Html, HtmlFormat}
import utils.{AmlsViewSpec, DateHelper}
import views.Fixture
import views.html.include.status._
import views.html.status.components.{fee_information, registration_status, withdraw_or_deregister_information}

class your_registrationSpec extends AmlsViewSpec with MustMatchers with AmlsReferenceNumberGenerator {

  trait ViewFixture extends Fixture {
    implicit val requestWithToken = addTokenForView()

    val feeResponse = FeeResponse(
      SubscriptionResponseType,
      amlsRegistrationNumber,
      150.00,
      Some(100.0),
      None,
      300.0,
      550.0,
      Some("XA000000000000"),
      None,
      new DateTime(2017, 12, 1, 1, 3, DateTimeZone.UTC)
    )

  }

  "your_registration view" must {

    val pageTitle = "Your registration - " + Messages("title.amls") + " - " + Messages("title.gov")

    "have correct title, heading and sub heading" in new ViewFixture {

      val form2 = EmptyForm

      def view = views.html.status.your_registration(amlsRegistrationNumber,
        Some("business Name"),
        Some(feeResponse),
        yourRegistrationInfo = HtmlFormat.empty,
        registrationStatus = HtmlFormat.empty,
        feeInformation = HtmlFormat.empty)

      doc.title must be(pageTitle)
      heading.html must be(Messages("your.registration"))
    }

    "contain registration information" in new ViewFixture {

      def view = views.html.status.your_registration(amlsRegistrationNumber,
        Some("business Name"),
        Some(feeResponse),
        yourRegistrationInfo = Html("some registration information"),
        registrationStatus = HtmlFormat.empty,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("registration-info").html() must include("some registration information")
    }

    "contain registration information for status NotCompleted" in new ViewFixture {

      def view = views.html.status.your_registration(amlsRegistrationNumber,
        Some("business Name"),
        Some(feeResponse),
        yourRegistrationInfo = application_incomplete(Some("business Name")),
        registrationStatus = HtmlFormat.empty,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("incomplete-description").html() must be("Your application to register with HMRC is incomplete. You have 28 days to complete your application from when you last saved your progress.")
      doc.getElementById("return-to-saved-application").html() must include("Return to your application")
      doc.getElementById("return-to-saved-application").html() must include("for business Name")
      doc.getElementById("return-to-saved-application").attr("href") must be(controllers.routes.RegistrationProgressController.get().url)
    }

    "contain correct content for status SubmissionWithdrawn" in new ViewFixture {
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_withdrawn(Some("business Name")),
        registrationStatus = registration_status(status = SubmissionWithdrawn),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-withdrawn-description-1").text() must be("You have withdrawn your application to register with HMRC.")
      doc.getElementById("application-withdrawn-description-2").text() must be("If the Money Laundering Regulations apply to your business, you need to be registered with an appropriate supervisory body.")
      doc.getElementById("application-withdrawn-description-3").text() must be("If you’re not registered and carry out activities covered by the Money Laundering Regulations, you may be subject to civil sanctions or criminal proceedings.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Application withdrawn.")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain correct content for status SubmissionDecisionRejected" in new ViewFixture {
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_rejected(Some("business Name")),
        registrationStatus = registration_status(status = SubmissionDecisionRejected),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-rejected-description-1").text() must be("Your application to register with HMRC has been rejected.")
      doc.getElementById("application-rejected-description-2").text() must be("Your business is not registered with HMRC. Your business must not carry out activities that are covered by the Money Laundering Regulations.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Application rejected.")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain correct content for status SubmissionDecisionRevoked" in new ViewFixture {
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_revoked(Some("business Name")),
        registrationStatus = registration_status(status = SubmissionDecisionRevoked),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-revoked-description-1").text() must be("Your registration has been revoked.")
      doc.getElementById("application-revoked-description-2").text() must be("Your business is not registered with HMRC. Your business must not carry out activities that are covered by the Money Laundering Regulations.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Registration revoked.")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain correct content for status SubmissionDecisionExpired" in new ViewFixture {
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_expired(Some("business Name")),
        registrationStatus = registration_status(status = SubmissionDecisionExpired),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-expired-description-1").text() must be("Your registration has expired.")
      doc.getElementById("application-expired-description-2").text() must be("Your business is not registered with HMRC under the Money Laundering Regulations.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Registration expired.")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain correct content for status DeRegistered" in new ViewFixture {
      val deregistrationDate = Some(LocalDate.now())
      def view = views.html.status.your_registration("",
        Some("business Name"),
        displayCheckOrUpdateLink = false,
        yourRegistrationInfo = application_deregistered(Some("business Name")),
        registrationStatus = registration_status(status = DeRegistered, endDate = deregistrationDate),
        unreadNotifications = 10,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("application-deregistered-description-1").text() must be("You have deregistered your business.")
      doc.getElementById("application-deregistered-description-2").text() must be("If the Money Laundering Regulations apply to your business, you need to be registered with an appropriate supervisory body.")
      doc.getElementById("application-deregistered-description-3").text() must be("If you’re not registered and carry out activities covered by the Money Laundering Regulations, you may be subject to civil sanctions or criminal proceedings.")
      Option(doc.getElementById("update-information")) must be(None)
      doc.getElementById("registration-status").html() must include("Not supervised. Deregistered on " + DateHelper.formatDate(deregistrationDate.value) + ".")
      doc.getElementById("new.application.button").html() must include("Start a new application")
    }

    "contain registration information for status SubmissionReady" in new ViewFixture {

      def view = views.html.status.your_registration(amlsRegistrationNumber,
        Some("business Name"),
        Some(feeResponse),
        yourRegistrationInfo = application_submission_ready(Call("GET", "/some/url"), Some("business Name")),
        registrationStatus = HtmlFormat.empty,
        feeInformation = HtmlFormat.empty)

      doc.getElementById("registration-info").html() must include("Your application to register with HMRC is ready to submit. You have 28 days to submit your application from when you last saved your progress.")
      doc.getElementById("status-submit").html() must include("Check and submit your application")
      doc.getElementById("status-submit").html() must include("for business Name")
      doc.getElementById("status-submit").attr("href") must be("/some/url")
    }
{'fraction_non_alphanumeric': 0.09819951338199513, 'fraction_numerical': 0.007396593673965937, 'mean_word_length': 4.157089084065245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '4255200', 'n_tokens_mistral': 5213, 'n_tokens_neox': 4918, 'n_words': 1448}