|
| 1 | +package controllers |
| 2 | + |
| 3 | +import org.scalatestplus.play._ |
| 4 | +import org.scalatestplus.play.guice._ |
| 5 | +import play.api.test._ |
| 6 | +import play.api.test.Helpers._ |
| 7 | + |
| 8 | +/** |
| 9 | + * Add your spec here. |
| 10 | + * You can mock out a whole application including requests, plugins etc. |
| 11 | + * |
| 12 | + * For more information, see https://www.playframework.com/documentation/latest/ScalaTestingWithScalaTest |
| 13 | + */ |
| 14 | +class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting { |
| 15 | + |
| 16 | + "HomeController GET" should { |
| 17 | + |
| 18 | + "render the appSummary page from a new instance of controller" in { |
| 19 | + val controller = new HomeController(stubControllerComponents()) |
| 20 | + val home = controller.appSummary().apply(FakeRequest(GET, "/summary")) |
| 21 | + |
| 22 | + status(home) mustBe OK |
| 23 | + contentType(home) mustBe Some("application/json") |
| 24 | + val resultJson = contentAsJson(home) |
| 25 | + resultJson.toString() mustBe """{"content":"Scala Play Angular Seed"}""" |
| 26 | + } |
| 27 | + |
| 28 | + "render the appSummary page from the application" in { |
| 29 | + val controller = inject[HomeController] |
| 30 | + val home = controller.appSummary().apply(FakeRequest(GET, "/summary")) |
| 31 | + |
| 32 | + status(home) mustBe OK |
| 33 | + contentType(home) mustBe Some("application/json") |
| 34 | + val resultJson = contentAsJson(home) |
| 35 | + resultJson.toString() mustBe """{"content":"Scala Play Angular Seed"}""" |
| 36 | + } |
| 37 | + |
| 38 | + "render the appSummary page from the router" in { |
| 39 | + val request = FakeRequest(GET, "/summary") |
| 40 | + val home = route(app, request).get |
| 41 | + |
| 42 | + status(home) mustBe OK |
| 43 | + contentType(home) mustBe Some("application/json") |
| 44 | + val resultJson = contentAsJson(home) |
| 45 | + resultJson.toString() mustBe """{"content":"Scala Play Angular Seed"}""" |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments