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/tmp
test/version_tmp test/version_tmp
tmp tmp
.node-*

View File

@ -7,7 +7,9 @@ Feature: Presentation Timer
Then the counter should show the time "00:00" Then the counter should show the time "00:00"
And the counter should not be running And the counter should not be running
Scenario: Start the timer Scenario: Manage the timer
When I start the timer When I start the timer
Then the counter should be running 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,22 +10,30 @@ class Attentive.PresentationTimer
ensureEl: -> ensureEl: ->
if !@el if !@el
@el = document.createElement('div') @el = this._createDiv()
@el.classList.add('timer') @el.classList.add('timer')
@el @el
_createDiv: -> document.createElement('div')
addClass: (className) ->
@ensureEl().classList.add(className)
start: -> start: ->
@_runner = this.runner() @_runner = this.runner()
@ensureEl().classList.add('running') this.addClass('running')
runner: -> runner: ->
setTimeout( setTimeout(
=> =>
this.handleRunner()
, 1000
)
handleRunner: ->
this.render() this.render()
@time += 1 @time += 1
this.runner() if @_runner? this.runner() if @_runner?
, 1000
)
stop: -> stop: ->
clearTimeout(@_runner) clearTimeout(@_runner)

View File

@ -1,5 +1,31 @@
#= require attentive/presentation_timer #= require attentive/presentation_timer
describe 'Attentive.PresentationTimer', -> describe 'Attentive.PresentationTimer', ->
beforeEach ->
@timer = new Attentive.PresentationTimer()
describe '#render', -> 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', ->