Menu
Home
Log in / Register
 
Home arrow Computer Science arrow Building Applications with Scala
Source

image_index.scala.html

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

@(images:Seq[Image])(implicit flash:Flash)

@main("Images") {

@if(!images.isEmpty) {

@for(image <- images) {

}

ProductID URL

(image.id.get)">@image.id

@image.productId @image.url

"@routes.ImageController.remove(image.id.get)">

}

class="btn btn-success">

Add Image

}

All set. Now we can run the ImageController tests.

$ activator "test-only ImageControllerTestSpec"

The result is shown in the following screenshot:

ImageController has passed all its tests. Now we will move to the ReviewController tests.

ReviewControNerTestSpec.scala

Your ReviewControllerTestSpec.scala file should contain the following code:

class ReviewControllerTestSpec extends PlaySpec with OneServerPerSuite with OneBrowserPerSuite

with HtmlUnitFactory {

"ReviewController" should {

"insert a new review 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}/review/add")

singleSel("productId").value = "1"

click on id("author")

enter("diegopacheco")

click on id("comment")

enter("Tests are amazing!")

submit()

}

"details from the review 1 should be ok" in {

goTo(s"http://localhost:${port}/review/details/1") textField("author").value mustBe "diegopacheco" textField("comment").value mustBe "Tests are amazing!"

}

"update review 1 should be ok" in {

goTo(s"http://localhost:${port}/review/details/1") textField("author").value = "diegopacheco2" textField("comment").value = "Tests are amazing 2!" submit()

goTo(s"http://localhost:${port}/review/details/1") textField("author").value mustBe "diegopacheco2" textField("comment").value mustBe "Tests are amazing 2!"

}

"delete a review should be ok" in {

goTo(s"http://localhost:${port}/review/add")

singleSel("productId").value = "1"

click on id("author")

enter("diegopacheco")

click on id("comment")

enter("Tests are amazing!")

submit()

goTo(s"http://localhost:${port}/review") 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.

For insert, we go to the new product form using goto. We use $port as a variable. We do this because the Play framework will boot up the application for us, but we don't know on which port, so we need to use this variable in order to get to the product controller.

Then we click on each text field using the click function, and we enter values using the enter function. After filling in the whole form, we submit it using the submit function.

For details, we just go to the product details page and check if the text fields have the values that we expect. We do that using the textField.value function.

In order to check the product update function, we need to first update the product definition, and then go to the details to see if the values we changed are there.

Finally, we test the delete function. For this function, we need to click on a button. We need to set the ID of the button in order to have this working. Then we do a small refactoring in our UI to have the ID there.

 
Source
Found a mistake? Please highlight the word and press Shift + Enter  
< Prev   CONTENTS   Next >
 
Subjects
Accounting
Business & Finance
Communication
Computer Science
Economics
Education
Engineering
Environment
Geography
Health
History
Language & Literature
Law
Management
Marketing
Mathematics
Political science
Philosophy
Psychology
Religion
Sociology
Travel