Don't rely on specific time in EditorStats spec

This commit is contained in:
Corey Johnson & Kevin Sawicki
2013-02-22 17:17:07 -08:00
parent ce9c416a3a
commit c7ff431d13
2 changed files with 12 additions and 15 deletions

View File

@@ -2,7 +2,7 @@ module.exports =
class StatsTracker
startDate: new Date
hours: 6
eventLog: []
eventLog: {}
constructor: ->
date = new Date(@startDate)
@@ -16,7 +16,7 @@ class StatsTracker
rootView.on 'mouseup', => @track()
clear: ->
@eventLog = []
@eventLog = {}
track: ->
date = new Date

View File

@@ -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)
@@ -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