Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tests #74

Merged
merged 7 commits into from
Jun 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
</head>
<body>
<section id="react"></section>
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/jquery-minicolors/jquery.minicolors.min.js"></script>
<script src="bower_components/bootstrap-sass/assets/javascripts/bootstrap.min.js"></script>
<script src="bower_components/moment/min/moment.min.js"></script>
<script src="bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
<script src="scripts/app.js"></script>
</body>
</html>
6 changes: 6 additions & 0 deletions app/scripts/__mocks__/clock.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
clockMock = jest.genMockFromModule('../clock')
clockMock.ClockManager.prototype.getOrAddClock.mockImplementation () ->
new clockMock.Clock()
clockMock.ClockManager.prototype.addClock.mockImplementation () ->
new clockMock.Clock()
module.exports = clockMock
2 changes: 2 additions & 0 deletions app/scripts/app.cjsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$ = require 'jquery'
require 'bootstrap'
React = require 'react'
GamePicker = require './components/game_picker.cjsx'
React.render <GamePicker />, document.getElementById('react')
1 change: 1 addition & 0 deletions app/scripts/components/announcers_feed.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
cx = React.addons.classSet
module.exports = React.createClass
componentDidMount: () ->
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/game.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
constants = require '../constants.coffee'
functions = require '../functions.coffee'
Titlebar = require './titlebar.cjsx'
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/game_notes.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
cx = React.addons.classSet
module.exports = React.createClass
componentDidMount: () ->
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/game_setup.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
GameForm = require './game_setup/game_form'
Skater = require '../models/skater'
AppDispatcher = require '../dispatcher/app_dispatcher'
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/components/game_setup/game_form.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
React = require 'react/addons'
$ = require 'jquery'
require 'bootstrap-datetimepicker'
moment = require 'moment'
TeamFields = require './team_fields'
cx = React.addons.classSet
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/components/game_setup/team_fields.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
React = require 'react/addons'
$ = require 'jquery'
require 'jquery-minicolors'
RosterFields = require './roster_fields'
cx = React.addons.classSet
module.exports = React.createClass
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/jam_timer.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
AppDispatcher = require '../dispatcher/app_dispatcher.coffee'
constants = require '../constants.coffee'
{ActionTypes} = require '../constants.coffee'
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/navbar.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
cx = React.addons.classSet
module.exports = React.createClass
buildOptions: (opts = {}) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
AppDispatcher = require '../../dispatcher/app_dispatcher.coffee'
{ActionTypes} = require '../../constants.coffee'
cx = React.addons.classSet
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/penalty_tracker/team_penalties.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
AppDispatcher = require '../../dispatcher/app_dispatcher.coffee'
{ActionTypes} = require '../../constants.coffee'
PenaltiesSummary = require './penalties_summary.cjsx'
Expand Down
14 changes: 10 additions & 4 deletions app/scripts/components/scoreboard.cjsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
React = require 'react/addons'
$ = require 'jquery'
Jam = require '../models/jam.coffee'
ScoreboardClocks = require './scoreboard/scoreboard_clocks.cjsx'
cx = React.addons.classSet
Expand All @@ -15,6 +13,14 @@ module.exports = React.createClass
homeJamPoints = homeJam.getPoints()
if awayJam
awayJamPoints = awayJam.getPoints()
periodNumber = switch @props.gameState.period
when 'period 1' then '1'
when 'period 2' then '2'
when 'pregame' then 'Pre'
when 'halftime' then 'Half'
when 'unofficial final' then 'UF'
when 'official final' then 'OF'
else ''
adsCS = cx
'ads': true
'hidden': $.inArray(@props.gameState.state, ["timeout"]) == -1
Expand Down Expand Up @@ -144,7 +150,7 @@ module.exports = React.createClass
<div className="period">
<label className="hidden-xs">Period</label>
<label className="visible-xs-block">Per</label>
<div className="number period-number">{@props.gameState.periodNumber}</div>
<div className="number period-number">{periodNumber}</div>
</div>
<div className="jam">
<label>Jam</label>
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/scorekeeper/jams_list.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
AppDispatcher = require '../../dispatcher/app_dispatcher.coffee'
{ActionTypes} = require '../../constants.coffee'
functions = require '../../functions.coffee'
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/scorekeeper/pass_edit_panel.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
AppDispatcher = require '../../dispatcher/app_dispatcher.coffee'
{ActionTypes} = require '../../constants.coffee'
functions = require '../../functions.coffee'
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/scorekeeper/pass_item.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
functions = require '../../functions.coffee'
AppDispatcher = require '../../dispatcher/app_dispatcher.coffee'
{ActionTypes} = require '../../constants.coffee'
Expand Down
1 change: 1 addition & 0 deletions app/scripts/components/scorekeeper/passes_list.cjsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
React = require 'react/addons'
$ = require 'jquery'
AppDispatcher = require '../../dispatcher/app_dispatcher.coffee'
{ActionTypes} = require '../../constants.coffee'
PassItem = require './pass_item.cjsx'
Expand Down
1 change: 0 additions & 1 deletion app/scripts/dispatcher/app_dispatcher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class AppDispatcher
@delays = []
@delay
@socket = IO(config.get('socketUrl'))
console.log "Socket opened on #{@socket.io.uri}"
@socket.on 'app dispatcher', (payload) =>
@dispatch(payload)
@socket.on 'sync games', (payload) =>
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/models/__mocks__/jam.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jamMock = jest.genMockFromModule('../jam')
jamMock.findBy.mockReturnValue([])
jamMock.prototype.getPositionsInBox.mockReturnValue([])
module.exports = jamMock
5 changes: 5 additions & 0 deletions app/scripts/models/__mocks__/pass.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
passMock = jest.genMockFromModule('../pass')
passMock.find.mockImplementation (id) ->
id
passMock.findBy.mockReturnValue([])
module.exports = passMock
5 changes: 5 additions & 0 deletions app/scripts/models/__mocks__/skater.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
skaterMock = jest.genMockFromModule('../skater')
skaterMock.find.mockImplementation (id) ->
id
skaterMock.findBy.mockReturnValue ([])
module.exports = skaterMock
33 changes: 12 additions & 21 deletions app/scripts/models/game_state.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
moment = require 'moment'
$ = require 'jquery'
_ = require 'underscore'
functions = require '../functions'
AppDispatcher = require '../dispatcher/app_dispatcher'
Expand Down Expand Up @@ -95,6 +96,8 @@ class GameState extends Store
new GameState(obj).save() for obj in action.games
game.save() if game?
@emitChange()
#return instance operated on for testing
game
constructor: (options={}) ->
super options
@name = options.name
Expand Down Expand Up @@ -160,13 +163,9 @@ class GameState extends Store
@advancePeriod()
@periodClock.start()
@state = "jam"
@home.jamPoints = 0
@away.jamPoints = 0
@jamNumber = @jamNumber + 1
for i in [@away.jams.length+1 .. @jamNumber] by 1
@away.createNextJam()
for i in [@home.jams.length+1 .. @jamNumber] by 1
@home.createNextJam()
@home.createJamsThrough @jamNumber
@away.createJamsThrough @jamNumber
stopJam: () =>
@jamClock.stop()
@startLineup()
Expand Down Expand Up @@ -210,9 +209,7 @@ class GameState extends Store
@startTimeout()
@_clearTimeouts()
@timeout = "home_team_timeout"
@home.timeouts = @home.timeouts - 1
@home.isTakingTimeout = true
console.log "timeouts=#{@home.timeouts}"
@home.startTimeout()
setTimeoutAsHomeTeamOfficialReview: () =>
if @_inTimeout() == false
@startTimeout()
Expand All @@ -226,9 +223,7 @@ class GameState extends Store
@_clearTimeouts()
@state = "timeout"
@timeout = "away_team_timeout"
@away.timeouts = @away.timeouts - 1
@away.isTakingTimeout = true
console.log "timeouts=#{@away.timeouts}"
@away.startTimeout()
setTimeoutAsAwayTeamOfficialReview: () =>
if @_inTimeout() == false
@startTimeout()
Expand All @@ -255,19 +250,15 @@ class GameState extends Store
setJamNumber: (val) =>
@jamNumber = parseInt(val)
removeHomeTeamOfficialReview: () =>
@home.hasOfficialReview = false
@home.officialReviewsRetained = @home.officialReviewsRetained - 1
@home.removeOfficialReview()
removeAwayTeamOfficialReview: () =>
@away.hasOfficialReview = false
@away.officialReviewsRetained = @away.officialReviewsRetained - 1
@away.removeOfficialReview()
restoreHomeTeamOfficialReview: () =>
@home.hasOfficialReview = true
@_clearTimeouts()
@home.officialReviewsRetained = @home.officialReviewsRetained + 1
restoreAwayTeamOfficialReview: (retained = false) =>
@away.hasOfficialReview = true
@home.restoreOfficialReview()
restoreAwayTeamOfficialReview: () =>
@_clearTimeouts()
@away.officialReviewsRetained = @away.officialReviewsRetained + 1
@away.restoreOfficialReview()
_inTimeout: ()->
@state == "timeout"
_clearAlerts: () =>
Expand Down
13 changes: 10 additions & 3 deletions app/scripts/models/jam.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,67 @@ class Jam extends Store
jam.toggleNoPivot()
jam.save()
@emitChange()
return jam
when ActionTypes.TOGGLE_STAR_PASS
jam = @find(action.jamId)
jam.toggleStarPass()
jam.save()
@emitChange()
return jam
when ActionTypes.SET_STAR_PASS
pass = Pass.find(action.passId)
jam = Jam.find(pass.jamId)
jam.setStarPass(pass)
jam.createNextPass(action.newPassId) if pass.id is jam.getLastPass().id
jam.save()
@emitChange()
return jam
when ActionTypes.SET_SKATER_POSITION
jam = @find(action.jamId)
jam.setSkaterPosition(action.position, action.skaterId)
jam.save()
@emitChange()
return jam
when ActionTypes.CYCLE_LINEUP_STATUS
jam = @find(action.jamId)
jam.cycleLineupStatus(action.statusIndex, action.position)
jam.save()
@emitChange()
return jam
when ActionTypes.TOGGLE_LEAD
AppDispatcher.waitFor([Pass.dispatchToken])
pass = Pass.find(action.passId)
jam = Jam.find(pass.jamId)
jam.createNextPass(action.newPassId) if pass.id is jam.getLastPass().id
jam.save()
@emitChange()
return jam
when ActionTypes.SET_POINTS
AppDispatcher.waitFor([Pass.dispatchToken])
pass = Pass.find(action.passId)
jam = Jam.find(pass.jamId)
jam.createNextPass(action.newPassId) if pass.id is jam.getLastPass().id
jam.save()
@emitChange()
return jam
when ActionTypes.REORDER_PASS
jam = @find(action.jamId)
jam.reorderPass(action.sourcePassIndex, action.targetPassIndex)
jam.save()
@emitChange()
return jam
when ActionTypes.SET_PASS_JAMMER
AppDispatcher.waitFor([Pass.dispatchToken])
pass = Pass.find(action.passId)
jam = Jam.find(pass.jamId)
if not jam.jammer?
jam.setSkaterPosition('jammer', action.skaterId)
return jam
when ActionTypes.SAVE_JAM
jam = new Jam(action.jam)
jam.save()
@emitChange()
return jam
constructor: (options={}) ->
super options
@teamId = options.teamId
Expand Down Expand Up @@ -110,10 +120,8 @@ class Jam extends Store
Object.keys(flags).filter (key) ->
flags[key]
toggleNoPivot: () ->
console.log "toggling no pivot #{@id}"
@noPivot = not @noPivot
toggleStarPass: () ->
console.log "toggling star pass #{@id}"
@starPass = not @starPass
setStarPass: (pass) ->
@starPass = not @starPass or @starPassNumber isnt pass.passNumber
Expand Down Expand Up @@ -141,7 +149,6 @@ class Jam extends Store
currentStatus = @lineupStatuses[statusIndex][position]
@lineupStatuses[statusIndex][position] = @statusTransition(currentStatus)
createNextPass: (passId) ->
console.log ("Creating new pass with id #{passId}")
lastPass = @getLastPass()
newPass = new Pass(id: passId, passNumber: lastPass.passNumber + 1, jamId: @id)
@passes.push newPass
Expand Down
8 changes: 8 additions & 0 deletions app/scripts/models/pass.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,49 @@ class Pass extends Store
pass.toggleInjury()
pass.save()
@emitChange()
return pass
when ActionTypes.TOGGLE_NOPASS
pass = @find(action.passId)
pass.toggleNopass()
pass.save()
@emitChange()
return pass
when ActionTypes.TOGGLE_CALLOFF
pass = @find(action.passId)
pass.toggleCalloff()
pass.save()
@emitChange()
return pass
when ActionTypes.TOGGLE_LOST_LEAD
pass = @find(action.passId)
pass.toggleLostLead()
pass.save()
@emitChange()
return pass
when ActionTypes.TOGGLE_LEAD
pass = @find(action.passId)
pass.toggleLead()
pass.save()
@emitChange()
return pass
when ActionTypes.SET_STAR_PASS
pass = @find(action.passId)
pass.setPoints(0)
pass.save()
@emitChange()
return pass
when ActionTypes.SET_POINTS
pass = @find(action.passId)
pass.setPoints(action.points)
pass.save()
@emitChange()
return pass
when ActionTypes.SET_PASS_JAMMER
pass = @find(action.passId)
pass.setJammer(action.skaterId)
pass.save()
@emitChange()
return pass
constructor: (options={}) ->
super options
@jamId = options.jamId
Expand Down
Loading