Skip to content

Commit

Permalink
Updated the tests to work with the recent changes in the phase workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gardeman committed Dec 16, 2009
1 parent 4c4fb1a commit 8f4fe81
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 35 deletions.
26 changes: 21 additions & 5 deletions test/unit/se/qbranch/qanban/PhaseControllerTests.groovy
Expand Up @@ -61,7 +61,7 @@ class PhaseControllerTests extends ControllerUnitTestCase {

def phaseEventCreate1 = new PhaseEventCreate(title: "First phase", cardLimit: 5, phasePos: 0, user: user1, board: board)
def phaseEventCreate2 = new PhaseEventCreate(title: "Second phase", cardLimit: 10, phasePos: 1, user: user1 , board: board)
def phaseEventCreate3 = new PhaseEventCreate(title: "Third phase", user: user1, phasePos: 2, board: board)
def phaseEventCreate3 = new PhaseEventCreate(title: "Third phase", cardLimit: 0,user: user1, phasePos: 2, board: board)

phaseEventCreate1.beforeInsert()
phaseEventCreate1.save()
Expand Down Expand Up @@ -158,6 +158,7 @@ class PhaseControllerTests extends ControllerUnitTestCase {

assertEquals 4, Phase.list().size()
assertEquals "myPhase", model.createEvent.phase.title
assertEquals 0, model.createEvent.phase.cardLimit
}

void testCreateWithoutTitleAndPos() {
Expand All @@ -166,6 +167,20 @@ class PhaseControllerTests extends ControllerUnitTestCase {
assertEquals 2, model.createEvent.errors.getAllErrors().size()
}

void testCreateWithLimitParam(){
mockParams.title = "myPhase"
mockParams.'board.id' = board.id
mockParams.phasePos = "3"
mockParams.cardLimit = "5"
assertEquals 3, Phase.list().size()

def model = controller.create()

assertEquals 4, Phase.list().size()
assertEquals "myPhase", model.createEvent.phase.title
assertEquals 5, model.createEvent.phase.cardLimit
}

void testShowWithoutId(){
controller.show()
assertEquals 400, renderArgs.status
Expand Down Expand Up @@ -240,15 +255,16 @@ class PhaseControllerTests extends ControllerUnitTestCase {
assertEquals 0, board.phases.indexOf(Phase.get(1))

def id = '1'
mockParams.id = id
def newTitle = "New Phase Title"
mockParams.title = newTitle
def newPos = 2
mockParams.cardLimit = "1337"
def cmd1 = new MovePhaseCommand(id: id, phasePos: newPos )
cmd1.validate()
def cmd2 = new UpdatePhaseCommand(id: id, title: newTitle, cardLimit: "1337")
cmd2.validate()

controller.update(cmd1,cmd2)
controller.update(cmd1)

assertEquals newPos, board.phases.indexOf(Phase.get(1))
assertEquals newTitle, renderArgs.model.updateEvent.phase.title

Expand Down
28 changes: 20 additions & 8 deletions test/unit/se/qbranch/qanban/PhaseEventCreateTests.groovy
Expand Up @@ -58,7 +58,7 @@ class PhaseEventCreateTests extends GrailsUnitTestCase {

def phaseEventCreate1 = new PhaseEventCreate(title: "First phase", cardLimit: 5, phasePos: 0, user: user1, board: board)
def phaseEventCreate2 = new PhaseEventCreate(title: "Second phase", cardLimit: 10, phasePos: 1, user: user1 , board: board)
def phaseEventCreate3 = new PhaseEventCreate(title: "Third phase", user: user1, phasePos: 2, board: board)
def phaseEventCreate3 = new PhaseEventCreate(title: "Third phase", cardLimit: 0, user: user1, phasePos: 2, board: board)

phaseEventCreate1.beforeInsert()
phaseEventCreate1.save()
Expand Down Expand Up @@ -105,13 +105,6 @@ class PhaseEventCreateTests extends GrailsUnitTestCase {

// Assertions to validate the mock setup

board.phases.each {
println it
it.cards.each {
println " $it"
}
}

assertEquals 1, board.id
assertEquals 3, board.phases.size()
assertEquals 1, phase1.id
Expand Down Expand Up @@ -177,4 +170,23 @@ class PhaseEventCreateTests extends GrailsUnitTestCase {
assertNull "There should not be a phase", createEvent.phase

}

void testCreatingAPhaseWithLiteralsAsLimit(){
String cardLimit = "limit with literals"
String title = "Fourth phase"
def createEvent = new PhaseEventCreate(
title: title,
cardLimit: cardLimit,
board: board,
user: user1 ,
phasePos: 1
)

createEvent.validate();
println "$cardLimit - $createEvent.cardLimit"

assertTrue "Shiould have errors", createEvent.hasErrors()


}
}
2 changes: 1 addition & 1 deletion test/unit/se/qbranch/qanban/PhaseEventDeleteTests.groovy
Expand Up @@ -67,7 +67,7 @@ class PhaseEventDeleteTests extends GrailsUnitTestCase {

def phaseEventCreate1 = new PhaseEventCreate(title: "First phase", cardLimit: 5, phasePos: 0, user: user1, board: board)
def phaseEventCreate2 = new PhaseEventCreate(title: "Second phase", cardLimit: 10, phasePos: 1, user: user1 , board: board)
def phaseEventCreate3 = new PhaseEventCreate(title: "Third phase", user: user1, phasePos: 2, board: board)
def phaseEventCreate3 = new PhaseEventCreate(title: "Third phase", cardLimit: 0, user: user1, phasePos: 2, board: board)

phaseEventCreate1.beforeInsert()
phaseEventCreate1.save()
Expand Down
53 changes: 32 additions & 21 deletions test/unit/se/qbranch/qanban/PhaseTests.groovy
Expand Up @@ -19,34 +19,45 @@ package se.qbranch.qanban
import grails.test.*

class PhaseTests extends GrailsUnitTestCase {
protected void setUp() {
super.setUp()
}
protected void setUp() {
super.setUp()
mockDomain(Board, [ new Board(domainId: "bdid")])
mockDomain(Phase)
}

protected void tearDown() {
super.tearDown()
}
protected void tearDown() {
super.tearDown()
}

void testCreatePhase() {
mockDomain(Phase)
void testCreatePhase() {

def phase = new Phase(title: "testPhase")
assertEquals "testPhase", phase.title

def notAllowedTitlePhase = new Phase(title: "")
assertFalse 'validate should have failed', notAllowedTitlePhase.validate()
def phase = new Phase(title: "testPhase")
assertEquals "testPhase", phase.title

}
def notAllowedTitlePhase = new Phase(title: "")
assertFalse 'validate should have failed', notAllowedTitlePhase.validate()

}

void testPhaseWithCard() {
mockDomain(Card)
mockDomain(Phase)
Card card = new Card(description: "myCard")
Phase phase = new Phase(title: "myPhase")
void testPhaseWithCard() {
mockDomain(Card)

phase.addToCards(card)
Card card = new Card(description: "myCard")
Phase phase = new Phase(title: "myPhase")

assertEquals 1, phase.cards.size()
phase.addToCards(card)

assertEquals 1, phase.cards.size()

}
void testCreatingAPhaseWithLiteralCardLimit(){

Phase phase = new Phase(title: "Title", domainId: "did", cardLimit: "qwe", board: Board.get(1))
phase.validate()
assertTrue "There should be errors", phase.hasErrors()
phase.errors.getAllErrors().each{
println it
}

}
}

0 comments on commit 8f4fe81

Please sign in to comment.