Add demo controls to TestView

This commit is contained in:
Scott Erickson 2016-01-26 11:02:11 -08:00
parent 29350bf1de
commit d00f8344be
4 changed files with 53 additions and 24 deletions

View file

@ -11,6 +11,12 @@ ol.breadcrumb
#testing-area #testing-area
.nav.nav-pills.nav-stacked.pull-right.well#test-nav .nav.nav-pills.nav-stacked.pull-right.well#test-nav
if view.demosOn
button#hide-demos-btn.btn.btn-danger.btn-block Hide Demos
else
button#show-demos-btn.btn.btn-info.btn-block Show Demos
hr
for child in children for child in children
li(class=child.type) li(class=child.type)
a(href=child.url).small a(href=child.url).small

View file

@ -1,6 +1,7 @@
RootView = require 'views/core/RootView' RootView = require 'views/core/RootView'
template = require 'templates/test-view' template = require 'templates/test-view'
requireUtils = require 'lib/requireUtils' requireUtils = require 'lib/requireUtils'
storage = require 'core/storage'
require 'vendor/jasmine-bundle' require 'vendor/jasmine-bundle'
require 'tests' require 'tests'
@ -13,18 +14,32 @@ module.exports = TestView = class TestView extends RootView
template: template template: template
reloadOnClose: true reloadOnClose: true
loadedFileIDs: [] loadedFileIDs: []
events:
'click #show-demos-btn': 'onClickShowDemosButton'
'click #hide-demos-btn': 'onClickHideDemosButton'
# INITIALIZE # INITIALIZE
constructor: (options, @subPath='') -> initialize: (options, @subPath='') ->
super(options)
@subPath = @subPath[1..] if @subPath[0] is '/' @subPath = @subPath[1..] if @subPath[0] is '/'
@demosOn = storage.load('demos-on')
afterInsert: -> afterInsert: ->
@initSpecFiles() @initSpecFiles()
@render() @render()
TestView.runTests(@specFiles) TestView.runTests(@specFiles, @demosOn)
window.runJasmine() window.runJasmine()
# EVENTS
onClickShowDemosButton: ->
storage.save('demos-on', true)
document.location.reload()
onClickHideDemosButton: ->
storage.remove('demos-on')
document.location.reload()
# RENDER DATA # RENDER DATA
@ -44,8 +59,17 @@ module.exports = TestView = class TestView extends RootView
prefix = TEST_REQUIRE_PREFIX + @subPath prefix = TEST_REQUIRE_PREFIX + @subPath
@specFiles = (f for f in @specFiles when _.string.startsWith f, prefix) @specFiles = (f for f in @specFiles when _.string.startsWith f, prefix)
@runTests: (specFiles) -> @runTests: (specFiles, demosOn=false) ->
specFiles ?= @getAllSpecFiles() specFiles ?= @getAllSpecFiles()
if demosOn
jasmine.demoEl = ($el) ->
$('#demo-area').append($el)
jasmine.demoModal = _.once (modal) ->
currentView.openModalView(modal)
else
jasmine.demoEl = _.noop
jasmine.demoModal = _.noop
describe 'CodeCombat Client', => describe 'CodeCombat Client', =>
jasmine.Ajax.install() jasmine.Ajax.install()
beforeEach -> beforeEach ->

View file

@ -26,11 +26,13 @@ describe 'CocoView', ->
describe 'when the server returns 401', -> describe 'when the server returns 401', ->
beforeEach -> respond(401) beforeEach ->
me.set('anonymous', true)
respond(401)
it 'shows a login button which opens the AuthModal', -> it 'shows a login button which opens the AuthModal', ->
button = view.$el.find('.login-btn') button = view.$el.find('.login-btn')
expect(button.length).toBe(1) expect(button.length).toBe(3) # including the two in the links section
spyOn(view, 'openModalView').and.callFake (modal) -> expect(modal.mode).toBe('login') spyOn(view, 'openModalView').and.callFake (modal) -> expect(modal.mode).toBe('login')
button.click() button.click()
expect(view.openModalView).toHaveBeenCalled() expect(view.openModalView).toHaveBeenCalled()
@ -44,9 +46,9 @@ describe 'CocoView', ->
it 'says "Login Required"', -> it 'says "Login Required"', ->
expect(view.$el.text().indexOf('Login Required')).toBeGreaterThan(-1) expect(view.$el.text().indexOf('Login Required')).toBeGreaterThan(-1)
it '(demo)', -> jasmine.demoEl(view.$el)
it '(demo)', ->
$('#demo-area').append(view.$el)
describe 'when the server returns 402', -> describe 'when the server returns 402', ->
@ -58,7 +60,9 @@ describe 'CocoView', ->
describe 'when the server returns 403', -> describe 'when the server returns 403', ->
beforeEach -> respond(403) beforeEach ->
me.set('anonymous', false)
respond(403)
it 'includes a logout button which logs out the account', -> it 'includes a logout button which logs out the account', ->
button = view.$el.find('#logout-btn') button = view.$el.find('#logout-btn')
@ -67,8 +71,7 @@ describe 'CocoView', ->
request = jasmine.Ajax.requests.mostRecent() request = jasmine.Ajax.requests.mostRecent()
expect(request.url).toBe('/auth/logout') expect(request.url).toBe('/auth/logout')
it '(demo)', -> it '(demo)', -> jasmine.demoEl(view.$el)
$('#demo-area').append(view.$el)
describe 'when the server returns 404', -> describe 'when the server returns 404', ->
@ -79,8 +82,7 @@ describe 'CocoView', ->
img = view.$el.find('#not-found-img') img = view.$el.find('#not-found-img')
expect(img.length).toBe(1) expect(img.length).toBe(1)
it '(demo)', -> it '(demo)', -> jasmine.demoEl(view.$el)
$('#demo-area').append(view.$el)
describe 'when the server returns 408', -> describe 'when the server returns 408', ->
@ -93,8 +95,7 @@ describe 'CocoView', ->
it 'shows a message encouraging refreshing the page or following links', -> it 'shows a message encouraging refreshing the page or following links', ->
expect(view.$el.text().indexOf('refresh')).toBeGreaterThan(-1) expect(view.$el.text().indexOf('refresh')).toBeGreaterThan(-1)
it '(demo)', -> it '(demo)', -> jasmine.demoEl(view.$el)
$('#demo-area').append(view.$el)
describe 'when no connection is made', -> describe 'when no connection is made', ->
@ -105,8 +106,7 @@ describe 'CocoView', ->
it 'shows "Connection Failed"', -> it 'shows "Connection Failed"', ->
expect(view.$el.text().indexOf('Connection Failed')).toBeGreaterThan(-1) expect(view.$el.text().indexOf('Connection Failed')).toBeGreaterThan(-1)
it '(demo)', -> it '(demo)', -> jasmine.demoEl(view.$el)
$('#demo-area').append(view.$el)
describe 'when the server returns any other number >= 400', -> describe 'when the server returns any other number >= 400', ->
@ -119,8 +119,7 @@ describe 'CocoView', ->
it 'shows a message encouraging refreshing the page or following links', -> it 'shows a message encouraging refreshing the page or following links', ->
expect(view.$el.text().indexOf('refresh')).toBeGreaterThan(-1) expect(view.$el.text().indexOf('refresh')).toBeGreaterThan(-1)
it '(demo)', -> it '(demo)', -> jasmine.demoEl(view.$el)
$('#demo-area').append(view.$el)

View file

@ -51,7 +51,7 @@ describe 'CourseVictoryModal', ->
expect(_.size(modal.views)).toBe(1) expect(_.size(modal.views)).toBe(1)
expect(modal.views[0] instanceof ProgressView).toBe(true) expect(modal.views[0] instanceof ProgressView).toBe(true)
xit '(demo)', -> currentView.openModalView(modal) it '(demo)', -> jasmine.demoModal(modal)
describe 'its ProgressView', -> describe 'its ProgressView', ->
it 'has a next level button which navigates to the next level on click', -> it 'has a next level button which navigates to the next level on click', ->
@ -93,7 +93,7 @@ describe 'CourseVictoryModal', ->
button.click() button.click()
expect(application.router.navigate).toHaveBeenCalled() expect(application.router.navigate).toHaveBeenCalled()
xit '(demo)', -> currentView.openModalView(modal) it '(demo)', -> jasmine.demoModal(modal)
describe 'given a course level with a new item', -> describe 'given a course level with a new item', ->
@ -120,5 +120,5 @@ describe 'CourseVictoryModal', ->
expect(modal.currentView instanceof NewItemView).toBe(true) expect(modal.currentView instanceof NewItemView).toBe(true)
modal.$el.find('#continue-btn').click() modal.$el.find('#continue-btn').click()
expect(modal.currentView instanceof ProgressView).toBe(true) expect(modal.currentView instanceof ProgressView).toBe(true)
xit '(demo)', -> currentView.openModalView(modal) it '(demo)', -> jasmine.demoModal(modal)