|
| 1 | +#<< use_case |
| 2 | +#<< clock |
| 3 | +#<< blind |
| 4 | + |
| 5 | +describe 'UseCase', -> |
| 6 | + beforeEach => |
| 7 | + @clock = new Clock() |
| 8 | + @useCase = new UseCase(@clock) |
| 9 | + |
| 10 | + it "resets clock on start", => |
| 11 | + spyOn(@clock, 'reset') |
| 12 | + @useCase.start() |
| 13 | + expect(@clock.reset).toHaveBeenCalled() |
| 14 | + |
| 15 | + it "adds a blind", => |
| 16 | + blind = new Blind(10, 20) |
| 17 | + @useCase.blindAdded(blind) |
| 18 | + expect(@useCase.blinds).toContain(blind) |
| 19 | + |
| 20 | + describe 'when time changed', => |
| 21 | + |
| 22 | + it 'adds one second to clock', => |
| 23 | + spyOn(@clock, 'addSecond') |
| 24 | + @useCase.secondElapsed() |
| 25 | + expect(@clock.addSecond).toHaveBeenCalled() |
| 26 | + |
| 27 | + it 'does not switch to next round until current has finished', => |
| 28 | + spyOn(@useCase, 'switchToNextRound') |
| 29 | + @useCase.setRoundLength(3) |
| 30 | + 2.times @useCase.secondElapsed |
| 31 | + expect(@useCase.switchToNextRound).not.toHaveBeenCalled() |
| 32 | + |
| 33 | + it 'switches to next round if current round has finished', => |
| 34 | + spyOn(@useCase, 'switchToNextRound') |
| 35 | + @useCase.setRoundLength(3) |
| 36 | + 3.times @useCase.secondElapsed |
| 37 | + expect(@useCase.switchToNextRound).toHaveBeenCalled() |
| 38 | + |
| 39 | + describe 'switch to next round', => |
| 40 | + |
| 41 | + it 'resets clock', => |
| 42 | + spyOn(@clock, 'reset') |
| 43 | + @useCase.switchToNextRound() |
| 44 | + expect(@clock.reset).toHaveBeenCalled() |
| 45 | + |
| 46 | + it 'increases blinds', => |
| 47 | + oldBlind = @useCase.currentBlind() |
| 48 | + @useCase.switchToNextRound() |
| 49 | + newBlind = @useCase.currentBlind() |
| 50 | + expect(newBlind.big).toBeGreaterThan(oldBlind.big) |
| 51 | + |
0 commit comments