more work on features
This commit is contained in:
parent
609b49e64e
commit
da840160c3
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@ spec/reports
|
|||||||
test/tmp
|
test/tmp
|
||||||
test/version_tmp
|
test/version_tmp
|
||||||
tmp
|
tmp
|
||||||
|
.node-*
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
3
js-features/steps/when/i_stop_the_timer.js.coffee
Normal file
3
js-features/steps/when/i_stop_the_timer.js.coffee
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Flowerbox.When /^I stop the timer$/, ->
|
||||||
|
@timer.stop()
|
||||||
|
|
@ -1,3 +0,0 @@
|
|||||||
Flowerbox.When /^I wait (\d+) seconds?$/, (secs) ->
|
|
||||||
Flowerbox.pause(Number(secs) * 1000)
|
|
||||||
|
|
@ -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)
|
||||||
|
@ -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', ->
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user