From d00f8344bef341b08872cd4b85ea311bda2e4a09 Mon Sep 17 00:00:00 2001 From: Scott Erickson Date: Tue, 26 Jan 2016 11:02:11 -0800 Subject: [PATCH] Add demo controls to TestView --- app/templates/test-view.jade | 6 ++++ app/views/TestView.coffee | 34 ++++++++++++++++--- test/app/views/core/CocoView.spec.coffee | 29 ++++++++-------- .../modal/CourseVictoryModal.spec.coffee | 8 ++--- 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/app/templates/test-view.jade b/app/templates/test-view.jade index c7b850f8e..edc9cf0f8 100644 --- a/app/templates/test-view.jade +++ b/app/templates/test-view.jade @@ -11,6 +11,12 @@ ol.breadcrumb #testing-area .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 li(class=child.type) a(href=child.url).small diff --git a/app/views/TestView.coffee b/app/views/TestView.coffee index defeba422..a7574e759 100644 --- a/app/views/TestView.coffee +++ b/app/views/TestView.coffee @@ -1,6 +1,7 @@ RootView = require 'views/core/RootView' template = require 'templates/test-view' requireUtils = require 'lib/requireUtils' +storage = require 'core/storage' require 'vendor/jasmine-bundle' require 'tests' @@ -13,18 +14,32 @@ module.exports = TestView = class TestView extends RootView template: template reloadOnClose: true loadedFileIDs: [] + + events: + 'click #show-demos-btn': 'onClickShowDemosButton' + 'click #hide-demos-btn': 'onClickHideDemosButton' # INITIALIZE - constructor: (options, @subPath='') -> - super(options) + initialize: (options, @subPath='') -> @subPath = @subPath[1..] if @subPath[0] is '/' - + @demosOn = storage.load('demos-on') + afterInsert: -> @initSpecFiles() @render() - TestView.runTests(@specFiles) + TestView.runTests(@specFiles, @demosOn) window.runJasmine() + + # EVENTS + + onClickShowDemosButton: -> + storage.save('demos-on', true) + document.location.reload() + + onClickHideDemosButton: -> + storage.remove('demos-on') + document.location.reload() # RENDER DATA @@ -44,8 +59,17 @@ module.exports = TestView = class TestView extends RootView prefix = TEST_REQUIRE_PREFIX + @subPath @specFiles = (f for f in @specFiles when _.string.startsWith f, prefix) - @runTests: (specFiles) -> + @runTests: (specFiles, demosOn=false) -> 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', => jasmine.Ajax.install() beforeEach -> diff --git a/test/app/views/core/CocoView.spec.coffee b/test/app/views/core/CocoView.spec.coffee index 7a383938e..f4c8c41d0 100644 --- a/test/app/views/core/CocoView.spec.coffee +++ b/test/app/views/core/CocoView.spec.coffee @@ -26,11 +26,13 @@ describe 'CocoView', -> 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', -> 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') button.click() expect(view.openModalView).toHaveBeenCalled() @@ -44,9 +46,9 @@ describe 'CocoView', -> it 'says "Login Required"', -> 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', -> @@ -58,7 +60,9 @@ describe 'CocoView', -> 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', -> button = view.$el.find('#logout-btn') @@ -67,8 +71,7 @@ describe 'CocoView', -> request = jasmine.Ajax.requests.mostRecent() expect(request.url).toBe('/auth/logout') - it '(demo)', -> - $('#demo-area').append(view.$el) + it '(demo)', -> jasmine.demoEl(view.$el) describe 'when the server returns 404', -> @@ -79,8 +82,7 @@ describe 'CocoView', -> img = view.$el.find('#not-found-img') expect(img.length).toBe(1) - it '(demo)', -> - $('#demo-area').append(view.$el) + it '(demo)', -> jasmine.demoEl(view.$el) describe 'when the server returns 408', -> @@ -93,8 +95,7 @@ describe 'CocoView', -> it 'shows a message encouraging refreshing the page or following links', -> expect(view.$el.text().indexOf('refresh')).toBeGreaterThan(-1) - it '(demo)', -> - $('#demo-area').append(view.$el) + it '(demo)', -> jasmine.demoEl(view.$el) describe 'when no connection is made', -> @@ -105,8 +106,7 @@ describe 'CocoView', -> it 'shows "Connection Failed"', -> expect(view.$el.text().indexOf('Connection Failed')).toBeGreaterThan(-1) - it '(demo)', -> - $('#demo-area').append(view.$el) + it '(demo)', -> jasmine.demoEl(view.$el) 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', -> expect(view.$el.text().indexOf('refresh')).toBeGreaterThan(-1) - it '(demo)', -> - $('#demo-area').append(view.$el) + it '(demo)', -> jasmine.demoEl(view.$el) diff --git a/test/app/views/play/level/modal/CourseVictoryModal.spec.coffee b/test/app/views/play/level/modal/CourseVictoryModal.spec.coffee index fda2de1eb..75ae097be 100644 --- a/test/app/views/play/level/modal/CourseVictoryModal.spec.coffee +++ b/test/app/views/play/level/modal/CourseVictoryModal.spec.coffee @@ -51,7 +51,7 @@ describe 'CourseVictoryModal', -> expect(_.size(modal.views)).toBe(1) expect(modal.views[0] instanceof ProgressView).toBe(true) - xit '(demo)', -> currentView.openModalView(modal) + it '(demo)', -> jasmine.demoModal(modal) describe 'its ProgressView', -> it 'has a next level button which navigates to the next level on click', -> @@ -93,7 +93,7 @@ describe 'CourseVictoryModal', -> button.click() expect(application.router.navigate).toHaveBeenCalled() - xit '(demo)', -> currentView.openModalView(modal) + it '(demo)', -> jasmine.demoModal(modal) describe 'given a course level with a new item', -> @@ -120,5 +120,5 @@ describe 'CourseVictoryModal', -> expect(modal.currentView instanceof NewItemView).toBe(true) modal.$el.find('#continue-btn').click() expect(modal.currentView instanceof ProgressView).toBe(true) - - xit '(demo)', -> currentView.openModalView(modal) + + it '(demo)', -> jasmine.demoModal(modal)