2014-12-08 14:21:40 -08:00
RootView = require ' views/core/RootView '
2014-12-12 11:36:41 -08:00
template = require ' templates/test-view '
2014-06-14 07:37:31 -07:00
requireUtils = require ' lib/requireUtils '
2016-01-26 11:02:11 -08:00
storage = require ' core/storage '
2014-06-05 16:55:49 -07:00
2014-12-08 14:21:40 -08:00
require ' vendor/jasmine-bundle '
require ' tests '
2014-06-14 07:37:31 -07:00
TEST_REQUIRE_PREFIX = ' test/app/ '
TEST_URL_PREFIX = ' /test/ '
2014-06-05 16:55:49 -07:00
2014-12-08 14:21:40 -08:00
module.exports = TestView = class TestView extends RootView
2014-07-01 10:16:26 +08:00
id: ' test-view '
2014-06-05 16:55:49 -07:00
template: template
reloadOnClose: true
2014-07-31 13:15:35 +02:00
loadedFileIDs: [ ]
2016-01-26 11:02:11 -08:00
events:
' click # show-demos-btn ' : ' onClickShowDemosButton '
' click # hide-demos-btn ' : ' onClickHideDemosButton '
2014-07-01 10:16:26 +08:00
2014-06-05 16:55:49 -07:00
# INITIALIZE
2016-01-26 11:02:11 -08:00
initialize: (options, @subPath='') ->
2014-06-05 16:55:49 -07:00
@subPath = @ subPath [ 1 . . ] if @ subPath [ 0 ] is ' / '
2016-01-26 11:02:11 -08:00
@demosOn = storage . load ( ' demos-on ' )
2014-12-08 14:21:40 -08:00
afterInsert: ->
2014-06-05 16:55:49 -07:00
@ initSpecFiles ( )
@ render ( )
2016-01-26 11:02:11 -08:00
TestView . runTests ( @ specFiles , @ demosOn )
2014-06-16 11:17:48 -07:00
window . runJasmine ( )
2016-01-26 11:02:11 -08:00
# EVENTS
onClickShowDemosButton: ->
storage . save ( ' demos-on ' , true )
document . location . reload ( )
onClickHideDemosButton: ->
storage . remove ( ' demos-on ' )
document . location . reload ( )
2014-07-01 10:16:26 +08:00
2014-06-05 16:55:49 -07:00
# RENDER DATA
2014-07-01 10:16:26 +08:00
2014-06-05 16:55:49 -07:00
getRenderData: ->
c = super ( arguments . . . )
2014-06-14 07:37:31 -07:00
c.parentFolders = requireUtils . getParentFolders ( @ subPath , TEST_URL_PREFIX )
c.children = requireUtils . parseImmediateChildren ( @ specFiles , @ subPath , TEST_REQUIRE_PREFIX , TEST_URL_PREFIX )
2014-06-05 16:55:49 -07:00
parts = @ subPath . split ( ' / ' )
c.currentFolder = parts [ parts . length - 1 ] or parts [ parts . length - 2 ] or ' All '
c
2014-07-01 10:16:26 +08:00
2014-06-05 16:55:49 -07:00
# RUNNING TESTS
2014-07-01 10:16:26 +08:00
2014-06-05 16:55:49 -07:00
initSpecFiles: ->
2014-06-07 18:15:57 -07:00
@specFiles = TestView . getAllSpecFiles ( )
2014-06-05 16:55:49 -07:00
if @ subPath
2014-06-14 07:37:31 -07:00
prefix = TEST_REQUIRE_PREFIX + @ subPath
2015-01-04 08:05:38 -08:00
@specFiles = ( f for f in @ specFiles when _ . string . startsWith f , prefix )
2014-06-05 16:55:49 -07:00
2016-01-26 11:02:11 -08:00
@runTests: (specFiles, demosOn=false) ->
2016-05-09 15:16:54 -07:00
application.testing = true
2014-06-07 18:15:57 -07:00
specFiles ? = @ getAllSpecFiles ( )
2016-01-26 11:02:11 -08:00
if demosOn
jasmine.demoEl = ($el) ->
$ ( ' # demo-area ' ) . append ( $el )
jasmine.demoModal = _ . once (modal) ->
currentView . openModalView ( modal )
else
jasmine.demoEl = _ . noop
jasmine.demoModal = _ . noop
2014-06-05 16:55:49 -07:00
describe ' CodeCombat Client ' , =>
2014-06-06 17:08:49 -07:00
jasmine . Ajax . install ( )
2014-06-05 16:55:49 -07:00
beforeEach ->
2014-06-06 17:08:49 -07:00
jasmine . Ajax . requests . reset ( )
2014-06-07 16:30:01 -07:00
Backbone . Mediator . init ( )
2014-06-07 19:08:07 -07:00
Backbone . Mediator . setValidationEnabled false
2016-03-16 12:37:58 -07:00
spyOn ( application . tracker , ' trackEvent ' )
2014-06-07 16:30:01 -07:00
# TODO Stubbify more things
# * document.location
# * firebase
2014-06-11 13:43:07 -07:00
# * all the services that load in main.html
2014-07-01 10:16:26 +08:00
2014-06-07 16:30:01 -07:00
afterEach ->
# TODO Clean up more things
# * Events
2014-07-01 10:16:26 +08:00
2014-06-07 18:15:57 -07:00
require f for f in specFiles # runs the tests
@getAllSpecFiles = ->
allFiles = window . require . list ( )
( f for f in allFiles when f . indexOf ( ' .spec ' ) > - 1 )
2014-06-05 16:55:49 -07:00
destroy: ->
# hack to get jasmine tests to properly run again on clicking links, and make sure if you
# leave this page (say, back to the main site) that test stuff doesn't follow you.
2014-07-01 10:16:26 +08:00
document . location . reload ( )