Desktop version

Home arrow Computer Science arrow Building Applications with Scala

Source

product_index.scala.html

Your product_index.scala.html file should contain the following code:

@(products:Seq[Product])(implicit flash: Flash) @main("Products") {

@if(!products.isEmpty) {

@for(product <- products) {

}

Name Details Price

(product.id.get)">@product.name

@product.details @product.price

"@routes.ProductController.remove(product.id.get)">

}

class="btn btn-success"> Add Product

}

All set. Now we can run our tests on Activators using the console.

$ activator "test-only ProductControllerTestSpec"

This preceding command shows the result in the following screenshot:

Since this test runs the application for real and calls the controller simulating the web browser, this test could take some time. Now it's time to move to the imageController tests.

ImageControNerTestSpec.scala

Your product_index.scala.html should contain the following code:

class ImageControllerTestSpec extends PlaySpec with OneServerPerSuite with OneBrowserPerSuite with HtmlUnitFactory {

"ImageController" should {

"insert a new image should be ok" in {

goTo(s"http://localhost:${port}/product/add") click on id("name") enter("Blue Ball") click on id("details")

enter("Blue Ball is a Awesome and simple product")

click on id("price")

enter("17.55")

submit()

goTo(s"http://localhost:${port}/image/add") singleSel("productId").value = "1" click on id("url")

enter("http://myimage.com/img.jpg")

submit()

}

"details from the image 1 should be ok" in { goTo(s"http://localhost:${port}/image/details/1") textField("url").value mustBe "http://myimage.com/img.jpg"

}

"update image 1 should be ok" in {

goTo(s"http://localhost:${port}/image/details/1") textField("url").value = "http://myimage.com/img2.jpg" submit()

goTo(s"http://localhost:${port}/image/details/1") textField("url").value mustBe "http://myimage.com/img2.jpg"

}

"delete a image should be ok" in {

goTo(s"http://localhost:${port}/image/add") singleSel("productId").value = "1" click on id("url")

enter("http://myimage.com/img.jpg")

submit()

goTo(s"http://localhost:${port}/image") click on id("btnDelete")

}

}

}

First of all, we need to go to the product controller to insert a product; otherwise, we cannot do image operations, since they all need a product ID.

 
Source
Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >

Related topics