Skip to content

Commit

Permalink
Don't rely on specific time in EditorStats spec
Browse files Browse the repository at this point in the history
  • Loading branch information
probablykevin committed Feb 23, 2013
1 parent ce9c416 commit c7ff431
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/packages/editor-stats/lib/stats-tracker.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports =
class StatsTracker
startDate: new Date
hours: 6
eventLog: []
eventLog: {}

constructor: ->
date = new Date(@startDate)
Expand All @@ -16,7 +16,7 @@ class StatsTracker
rootView.on 'mouseup', => @track()

clear: ->
@eventLog = []
@eventLog = {}

track: ->
date = new Date
Expand Down
23 changes: 10 additions & 13 deletions src/packages/editor-stats/spec/editor-stats-spec.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
$ = require 'jquery'
_ = require 'underscore'
RootView = require 'root-view'
EditorStats = require 'editor-stats/lib/editor-stats-view'

describe "EditorStats", ->
[editorStats, time] = []
[editorStats] = []

simulateKeyUp = (key) ->
e = $.Event "keydown", keyCode: key.charCodeAt(0)
Expand All @@ -16,26 +17,22 @@ describe "EditorStats", ->
beforeEach ->
window.rootView = new RootView
rootView.open('sample.js')

date = new Date()
mins = date.getMinutes()
hours = date.getHours()

mins = if mins == 60 then '01' else mins + 1
time = "#{hours}:#{mins}"

editorStats = window.loadPackage('editor-stats').packageMain.stats

describe "when a keyup event is triggered", ->
beforeEach ->
expect(_.values(editorStats.eventLog)).not.toContain 1
expect(_.values(editorStats.eventLog)).not.toContain 2

it "records the number of times a keyup is triggered", ->
simulateKeyUp('a')
expect(editorStats.eventLog[time]).toBe 1
expect(_.values(editorStats.eventLog)).toContain 1
simulateKeyUp('b')
expect(editorStats.eventLog[time]).toBe 2
expect(_.values(editorStats.eventLog)).toContain 2

describe "when a mouseup event is triggered", ->
it "records the number of times a mouseup is triggered", ->
simulateClick()
expect(editorStats.eventLog[time]).toBe 1
expect(_.values(editorStats.eventLog)).toContain 1
simulateClick()
expect(editorStats.eventLog[time]).toBe 2
expect(_.values(editorStats.eventLog)).toContain 2

0 comments on commit c7ff431

Please sign in to comment.