more work on features

This commit is contained in:
John Bintz 2012-03-14 08:36:10 -04:00
parent 609b49e64e
commit da840160c3
7 changed files with 47 additions and 10 deletions

1
.gitignore vendored
View File

@ -18,3 +18,4 @@ spec/reports
test/tmp
test/version_tmp
tmp
.node-*

View File

@ -7,7 +7,9 @@ Feature: Presentation Timer
Then the counter should show the time "00:00"
And the counter should not be running
Scenario: Start the timer
Scenario: Manage the timer
When I start the timer
Then the counter should be running
When I stop the timer
Then the counter should not be running

View File

@ -0,0 +1,3 @@
Flowerbox.When /^I stop the timer$/, ->
@timer.stop()

View File

@ -1,3 +0,0 @@
Flowerbox.When /^I wait (\d+) seconds?$/, (secs) ->
Flowerbox.pause(Number(secs) * 1000)

View File

@ -10,23 +10,31 @@ class Attentive.PresentationTimer
ensureEl: ->
if !@el
@el = document.createElement('div')
@el = this._createDiv()
@el.classList.add('timer')
@el
_createDiv: -> document.createElement('div')
addClass: (className) ->
@ensureEl().classList.add(className)
start: ->
@_runner = this.runner()
@ensureEl().classList.add('running')
this.addClass('running')
runner: ->
setTimeout(
=>
this.render()
@time += 1
this.runner() if @_runner?
this.handleRunner()
, 1000
)
handleRunner: ->
this.render()
@time += 1
this.runner() if @_runner?
stop: ->
clearTimeout(@_runner)
@ensureEl().classList.remove('running')

View File

@ -1,5 +1,31 @@
#= require attentive/presentation_timer
describe 'Attentive.PresentationTimer', ->
beforeEach ->
@timer = new Attentive.PresentationTimer()
describe '#render', ->
it 'should do something', ->
time = 'time'
elStub = null
beforeEach ->
elStub = {}
@timer.ensureEl = -> elStub
@timer.formattedTime = -> time
it 'should render', ->
@timer.render()
expect(elStub.innerHTML).toEqual(time)
describe '#ensureEl', ->
context 'with el', ->
el = 'el'
beforeEach ->
@timer.el = el
it 'should return the existing value', ->
expect(@timer.ensureEl()).toEqual(el)
context 'without el', ->