diff --git a/src/packages/editor-stats/lib/stats-tracker.coffee b/src/packages/editor-stats/lib/stats-tracker.coffee index d7cc8d1d8c8..2673a75b380 100644 --- a/src/packages/editor-stats/lib/stats-tracker.coffee +++ b/src/packages/editor-stats/lib/stats-tracker.coffee @@ -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 diff --git a/src/packages/editor-stats/spec/editor-stats-spec.coffee b/src/packages/editor-stats/spec/editor-stats-spec.coffee index 3015b3ce8e4..5d8708e42e3 100644 --- a/src/packages/editor-stats/spec/editor-stats-spec.coffee +++ b/src/packages/editor-stats/spec/editor-stats-spec.coffee @@ -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