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/version_tmp
|
||||
tmp
|
||||
.node-*
|
||||
|
@ -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
|
||||
|
||||
|
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,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')
|
||||
|
@ -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', ->
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user