HomeControllerSpec.scala 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package controllers
  2. import org.scalatestplus.play._
  3. import org.scalatestplus.play.guice._
  4. import play.api.test._
  5. import play.api.test.Helpers._
  6. /**
  7. * Add your spec here.
  8. * You can mock out a whole application including requests, plugins etc.
  9. *
  10. * For more information, see https://www.playframework.com/documentation/latest/ScalaTestingWithScalaTest
  11. */
  12. class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting {
  13. "HomeController GET" should {
  14. "render the index page from a new instance of controller" in {
  15. val controller = new HomeController(stubControllerComponents())
  16. val home = controller.index().apply(FakeRequest(GET, "/"))
  17. status(home) mustBe OK
  18. contentType(home) mustBe Some("text/html")
  19. contentAsString(home) must include ("Welcome to Play")
  20. }
  21. "render the index page from the application" in {
  22. val controller = inject[HomeController]
  23. val home = controller.index().apply(FakeRequest(GET, "/"))
  24. status(home) mustBe OK
  25. contentType(home) mustBe Some("text/html")
  26. contentAsString(home) must include ("Welcome to Play")
  27. }
  28. "render the index page from the router" in {
  29. val request = FakeRequest(GET, "/")
  30. val home = route(app, request).get
  31. status(home) mustBe OK
  32. contentType(home) mustBe Some("text/html")
  33. contentAsString(home) must include ("Welcome to Play")
  34. }
  35. }
  36. }