forked from grails-samples/grails-petclinic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request grails-samples#22 from caseyscarborough/master
Fix adding/editing pets and add functional tests
- Loading branch information
Showing
6 changed files
with
153 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.grails.samples | ||
|
||
import org.grails.samples.pages.AddPetPage | ||
import org.grails.samples.pages.AddOwnerPage | ||
import org.grails.samples.pages.ShowOwnerPage | ||
import spock.lang.Shared | ||
|
||
class AddPetSpec extends PetclinicSpecs { | ||
|
||
@Shared | ||
def ownerId | ||
|
||
def setupSpec() { | ||
addOwner() | ||
} | ||
|
||
def setup() { | ||
to AddPetPage, "?owner.id=${ownerId}" | ||
} | ||
|
||
def 'can NOT add an invalid Pet'() { | ||
when: | ||
addPet.click() | ||
|
||
then: | ||
at AddPetPage | ||
errors.size() == 3 | ||
} | ||
|
||
def 'can add a valid Pet'() { | ||
given: | ||
name.value 'Fido' | ||
id.value ownerId | ||
|
||
when: | ||
addPet.click() | ||
|
||
then: | ||
at ShowOwnerPage | ||
} | ||
|
||
protected void addOwner() { | ||
to AddOwnerPage | ||
firstName.value 'Sally' | ||
lastName.value 'Jones' | ||
address.value '987 State St.' | ||
city.value 'MSN' | ||
telephone.value '1234567890' | ||
addOwner.click() | ||
ownerId = $("form").find("input", name: "owner.id").value() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.grails.samples | ||
|
||
import org.grails.samples.pages.AddOwnerPage | ||
import org.grails.samples.pages.AddPetPage | ||
import org.grails.samples.pages.EditPetPage | ||
import org.grails.samples.pages.ShowOwnerPage | ||
import spock.lang.Shared | ||
|
||
class EditPetSpec extends PetclinicSpecs { | ||
|
||
@Shared | ||
def ownerId | ||
|
||
def setupSpec() { | ||
addOwner() | ||
addPetToOwner(ownerId) | ||
} | ||
|
||
def setup() { | ||
to EditPetPage, 1 | ||
} | ||
|
||
def 'can NOT edit an invalid Pet'() { | ||
when: | ||
name.value '' | ||
editPet.click() | ||
|
||
then: | ||
at EditPetPage | ||
errors.size() == 3 | ||
} | ||
|
||
def 'can edit a valid Pet'() { | ||
given: | ||
name.value 'Fido' | ||
id.value ownerId | ||
|
||
when: | ||
editPet.click() | ||
|
||
then: | ||
at ShowOwnerPage | ||
} | ||
|
||
protected void addOwner() { | ||
to AddOwnerPage | ||
firstName.value 'Sally' | ||
lastName.value 'Jones' | ||
address.value '987 State St.' | ||
city.value 'MSN' | ||
telephone.value '1234567890' | ||
addOwner.click() | ||
ownerId = $("form").find("input", name: "owner.id").value() | ||
} | ||
|
||
protected void addPetToOwner(ownerId) { | ||
to AddPetPage, "?owner.id=${ownerId}" | ||
name.value 'Fido' | ||
id.value ownerId | ||
addPet.click() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/functional/org/grails/samples/pages/AddPetPage.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.grails.samples.pages | ||
|
||
class AddPetPage extends PageWithFooter { | ||
|
||
static url = '/petclinic/pet/add' | ||
|
||
static at = { | ||
title == 'Add Pet' | ||
} | ||
|
||
static content = { | ||
name { $('#pet_name') } | ||
id { $('#pet_owner_id') } | ||
addPet { $('input', type: 'submit') } | ||
errors(required: false) { $('.errors') } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
test/functional/org/grails/samples/pages/EditPetPage.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.grails.samples.pages | ||
|
||
class EditPetPage extends PageWithFooter { | ||
|
||
static url = '/petclinic/pet/edit' | ||
|
||
static at = { | ||
title == 'Update Pet' | ||
} | ||
|
||
static content = { | ||
name { $('#pet_name') } | ||
id { $('#pet_owner_id') } | ||
editPet { $('input', type: 'submit') } | ||
errors(required: false) { $('.errors') } | ||
} | ||
} |