From 8f4fe817ebf1d24d5127bc238319124b3fb46d8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20G=C3=A4rdeman?= Date: Wed, 16 Dec 2009 18:31:49 +0100 Subject: [PATCH] Updated the tests to work with the recent changes in the phase workflow --- .../qanban/PhaseControllerTests.groovy | 26 +++++++-- .../qanban/PhaseEventCreateTests.groovy | 28 +++++++--- .../qanban/PhaseEventDeleteTests.groovy | 2 +- test/unit/se/qbranch/qanban/PhaseTests.groovy | 53 +++++++++++-------- 4 files changed, 74 insertions(+), 35 deletions(-) diff --git a/test/unit/se/qbranch/qanban/PhaseControllerTests.groovy b/test/unit/se/qbranch/qanban/PhaseControllerTests.groovy index cea840e..8bedd8c 100644 --- a/test/unit/se/qbranch/qanban/PhaseControllerTests.groovy +++ b/test/unit/se/qbranch/qanban/PhaseControllerTests.groovy @@ -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() @@ -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() { @@ -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 @@ -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 diff --git a/test/unit/se/qbranch/qanban/PhaseEventCreateTests.groovy b/test/unit/se/qbranch/qanban/PhaseEventCreateTests.groovy index 1566b4e..1c7941d 100644 --- a/test/unit/se/qbranch/qanban/PhaseEventCreateTests.groovy +++ b/test/unit/se/qbranch/qanban/PhaseEventCreateTests.groovy @@ -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() @@ -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 @@ -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() + + + } } diff --git a/test/unit/se/qbranch/qanban/PhaseEventDeleteTests.groovy b/test/unit/se/qbranch/qanban/PhaseEventDeleteTests.groovy index 282b6a3..4dd1abc 100644 --- a/test/unit/se/qbranch/qanban/PhaseEventDeleteTests.groovy +++ b/test/unit/se/qbranch/qanban/PhaseEventDeleteTests.groovy @@ -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() diff --git a/test/unit/se/qbranch/qanban/PhaseTests.groovy b/test/unit/se/qbranch/qanban/PhaseTests.groovy index 82d553b..9e52e27 100644 --- a/test/unit/se/qbranch/qanban/PhaseTests.groovy +++ b/test/unit/se/qbranch/qanban/PhaseTests.groovy @@ -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 } + + } }