Commit 8e7bf4c1 by Prem Sichanugrist

Fix broken test case

parent afde79da
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
"js_files": [ "js_files": [
"/static/js/jquery-1.6.2.min.js", "/static/js/jquery-1.6.2.min.js",
"/static/js/jquery-ui-1.8.16.custom.min.js", "/static/js/jquery-ui-1.8.16.custom.min.js",
"/static/js/jquery.leanModal.js" "/static/js/jquery.leanModal.js",
"/static/js/jquery.cookie.js"
], ],
"static_files": [ "static_files": [
"js/application.js" "js/application.js"
......
describe 'Courseware', -> describe 'Courseware', ->
describe 'bind', -> describe 'start', ->
it 'bind the navigation', -> it 'create the navigation', ->
spyOn Courseware.Navigation, 'bind' spyOn(window, 'Navigation')
Courseware.bind() Courseware.start()
expect(Courseware.Navigation.bind).toHaveBeenCalled() expect(window.Navigation).toHaveBeenCalled()
it 'create the calculator', ->
spyOn(window, 'Calculator')
Courseware.start()
expect(window.Calculator).toHaveBeenCalled()
it 'creates the FeedbackForm', ->
spyOn(window, 'FeedbackForm')
Courseware.start()
expect(window.FeedbackForm).toHaveBeenCalled()
it 'binds the Logger', ->
spyOn(Logger, 'bind')
Courseware.start()
expect(Logger.bind).toHaveBeenCalled()
describe 'Navigation', -> describe 'bind', ->
beforeEach -> beforeEach ->
loadFixtures 'accordion.html' @courseware = new Courseware
@navigation = new Courseware.Navigation setFixtures """<div id="seq_content"></div>"""
describe 'bind', ->
describe 'when the #accordion exists', ->
describe 'when there is an active section', ->
it 'activate the accordion with correct active section', ->
spyOn $.fn, 'accordion'
$('#accordion').append('<ul><li></li></ul><ul><li class="active"></li></ul>')
Courseware.Navigation.bind()
expect($('#accordion').accordion).toHaveBeenCalledWith
active: 1
header: 'h3'
autoHeight: false
describe 'when there is no active section', ->
it 'activate the accordian with section 1 as active', ->
spyOn $.fn, 'accordion'
$('#accordion').append('<ul><li></li></ul><ul><li></li></ul>')
Courseware.Navigation.bind()
expect($('#accordion').accordion).toHaveBeenCalledWith
active: 1
header: 'h3'
autoHeight: false
it 'binds the accordionchange event', ->
Courseware.Navigation.bind()
expect($('#accordion')).toHandleWith 'accordionchange', @navigation.log
it 'bind the navigation toggle', ->
Courseware.Navigation.bind()
expect($('#open_close_accordion a')).toHandleWith 'click', @navigation.toggle
describe 'when the #accordion does not exists', ->
beforeEach ->
$('#accordion').remove()
it 'does not activate the accordion', -> it 'binds the sequential content change event', ->
spyOn $.fn, 'accordion' @courseware.bind()
Courseware.Navigation.bind() expect($('#seq_content')).toHandleWith 'change', @courseware.render
expect($('#accordion').accordion).wasNotCalled()
describe 'toggle', -> describe 'render', ->
it 'toggle closed class on the wrapper', -> beforeEach ->
$('.course-wrapper').removeClass('closed') @courseware = new Courseware
setFixtures """
@navigation.toggle() <div class="course-content">
expect($('.course-wrapper')).toHaveClass('closed') <div id="video_1" class="video" data-streams="1.0:abc1234"></div>
<div id="video_2" class="video" data-streams="1.0:def5678"></div>
@navigation.toggle() </div>
expect($('.course-wrapper')).not.toHaveClass('closed') """
describe 'log', -> it 'detect the video element and convert them', ->
beforeEach -> spyOn(window, 'Video')
window.log_event = -> @courseware.render()
spyOn window, 'log_event' expect(window.Video).toHaveBeenCalledWith('1', '1.0:abc1234')
expect(window.Video).toHaveBeenCalledWith('2', '1.0:def5678')
it 'submit event log', ->
@navigation.log {}, {
newHeader:
text: -> "new"
oldHeader:
text: -> "old"
}
expect(window.log_event).toHaveBeenCalledWith 'accordion',
newheader: 'new'
oldheader: 'old'
(function() { (function() {
describe('Courseware', function() { describe('Courseware', function() {
describe('bind', function() { describe('start', function() {
return it('bind the navigation', function() { it('create the navigation', function() {
spyOn(Courseware.Navigation, 'bind'); spyOn(window, 'Navigation');
Courseware.bind(); Courseware.start();
return expect(Courseware.Navigation.bind).toHaveBeenCalled(); return expect(window.Navigation).toHaveBeenCalled();
});
it('create the calculator', function() {
spyOn(window, 'Calculator');
Courseware.start();
return expect(window.Calculator).toHaveBeenCalled();
});
it('creates the FeedbackForm', function() {
spyOn(window, 'FeedbackForm');
Courseware.start();
return expect(window.FeedbackForm).toHaveBeenCalled();
});
return it('binds the Logger', function() {
spyOn(Logger, 'bind');
Courseware.start();
return expect(Logger.bind).toHaveBeenCalled();
}); });
}); });
return describe('Navigation', function() { describe('bind', function() {
beforeEach(function() { beforeEach(function() {
loadFixtures('accordion.html'); this.courseware = new Courseware;
return this.navigation = new Courseware.Navigation; return setFixtures("<div id=\"seq_content\"></div>");
}); });
describe('bind', function() { return it('binds the sequential content change event', function() {
describe('when the #accordion exists', function() { this.courseware.bind();
describe('when there is an active section', function() { return expect($('#seq_content')).toHandleWith('change', this.courseware.render);
return it('activate the accordion with correct active section', function() {
spyOn($.fn, 'accordion');
$('#accordion').append('<ul><li></li></ul><ul><li class="active"></li></ul>');
Courseware.Navigation.bind();
return expect($('#accordion').accordion).toHaveBeenCalledWith({
active: 1,
header: 'h3',
autoHeight: false
});
});
});
describe('when there is no active section', function() {
return it('activate the accordian with section 1 as active', function() {
spyOn($.fn, 'accordion');
$('#accordion').append('<ul><li></li></ul><ul><li></li></ul>');
Courseware.Navigation.bind();
return expect($('#accordion').accordion).toHaveBeenCalledWith({
active: 1,
header: 'h3',
autoHeight: false
});
});
});
it('binds the accordionchange event', function() {
Courseware.Navigation.bind();
return expect($('#accordion')).toHandleWith('accordionchange', this.navigation.log);
});
return it('bind the navigation toggle', function() {
Courseware.Navigation.bind();
return expect($('#open_close_accordion a')).toHandleWith('click', this.navigation.toggle);
});
});
return describe('when the #accordion does not exists', function() {
beforeEach(function() {
return $('#accordion').remove();
});
return it('does not activate the accordion', function() {
spyOn($.fn, 'accordion');
Courseware.Navigation.bind();
return expect($('#accordion').accordion).wasNotCalled();
});
});
}); });
describe('toggle', function() { });
return it('toggle closed class on the wrapper', function() { return describe('render', function() {
$('.course-wrapper').removeClass('closed'); beforeEach(function() {
this.navigation.toggle(); this.courseware = new Courseware;
expect($('.course-wrapper')).toHaveClass('closed'); return setFixtures("<div class=\"course-content\">\n <div id=\"video_1\" class=\"video\" data-streams=\"1.0:abc1234\"></div>\n <div id=\"video_2\" class=\"video\" data-streams=\"1.0:def5678\"></div>\n</div>");
this.navigation.toggle();
return expect($('.course-wrapper')).not.toHaveClass('closed');
});
}); });
return describe('log', function() { return it('detect the video element and convert them', function() {
beforeEach(function() { spyOn(window, 'Video');
window.log_event = function() {}; this.courseware.render();
return spyOn(window, 'log_event'); expect(window.Video).toHaveBeenCalledWith('1', '1.0:abc1234');
}); return expect(window.Video).toHaveBeenCalledWith('2', '1.0:def5678');
return it('submit event log', function() {
this.navigation.log({}, {
newHeader: {
text: function() {
return "new";
}
},
oldHeader: {
text: function() {
return "old";
}
}
});
return expect(window.log_event).toHaveBeenCalledWith('accordion', {
newheader: 'new',
oldheader: 'old'
});
});
}); });
}); });
}); });
......
...@@ -2,9 +2,9 @@ describe 'FeedbackForm', -> ...@@ -2,9 +2,9 @@ describe 'FeedbackForm', ->
beforeEach -> beforeEach ->
loadFixtures 'feedback_form.html' loadFixtures 'feedback_form.html'
describe 'bind', -> describe 'constructor', ->
beforeEach -> beforeEach ->
FeedbackForm.bind() new FeedbackForm
spyOn($, 'post').andCallFake (url, data, callback, format) -> spyOn($, 'post').andCallFake (url, data, callback, format) ->
callback() callback()
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
beforeEach(function() { beforeEach(function() {
return loadFixtures('feedback_form.html'); return loadFixtures('feedback_form.html');
}); });
return describe('bind', function() { return describe('constructor', function() {
beforeEach(function() { beforeEach(function() {
FeedbackForm.bind(); new FeedbackForm;
return spyOn($, 'post').andCallFake(function(url, data, callback, format) { return spyOn($, 'post').andCallFake(function(url, data, callback, format) {
return callback(); return callback();
}); });
......
class Calculator class @Calculator
constructor: -> constructor: ->
$('.calc').click @toggle $('.calc').click @toggle
$('form#calculator').submit(@calculate).submit (e) -> $('form#calculator').submit(@calculate).submit (e) ->
......
class window.Courseware class @Courseware
constructor: -> constructor: ->
new CoursewareNavigation new Navigation
new Calculator new Calculator
new FeedbackForm new FeedbackForm
Logger.bind() Logger.bind()
......
class FeedbackForm class @FeedbackForm
constructor: -> constructor: ->
$('#feedback_button').click -> $('#feedback_button').click ->
data = data =
......
describe 'Navigation', ->
beforeEach ->
loadFixtures 'accordion.html'
@navigation = new Navigation
describe 'constructor', ->
describe 'when the #accordion exists', ->
describe 'when there is an active section', ->
beforeEach ->
spyOn $.fn, 'accordion'
$('#accordion').append('<ul><li></li></ul><ul><li class="active"></li></ul>')
new Navigation
it 'activate the accordion with correct active section', ->
expect($('#accordion').accordion).toHaveBeenCalledWith
active: 1
header: 'h3'
autoHeight: false
describe 'when there is no active section', ->
beforeEach ->
spyOn $.fn, 'accordion'
$('#accordion').append('<ul><li></li></ul><ul><li></li></ul>')
new Navigation
it 'activate the accordian with section 1 as active', ->
expect($('#accordion').accordion).toHaveBeenCalledWith
active: 1
header: 'h3'
autoHeight: false
it 'binds the accordionchange event', ->
Navigation.bind()
expect($('#accordion')).toHandleWith 'accordionchange', @navigation.log
it 'bind the navigation toggle', ->
Navigation.bind()
expect($('#open_close_accordion a')).toHandleWith 'click', @navigation.toggle
describe 'when the #accordion does not exists', ->
beforeEach ->
$('#accordion').remove()
it 'does not activate the accordion', ->
spyOn $.fn, 'accordion'
Navigation.bind()
expect($('#accordion').accordion).wasNotCalled()
describe 'toggle', ->
it 'toggle closed class on the wrapper', ->
$('.course-wrapper').removeClass('closed')
@navigation.toggle()
expect($('.course-wrapper')).toHaveClass('closed')
@navigation.toggle()
expect($('.course-wrapper')).not.toHaveClass('closed')
describe 'log', ->
beforeEach ->
window.log_event = ->
spyOn window, 'log_event'
it 'submit event log', ->
@navigation.log {}, {
newHeader:
text: -> "new"
oldHeader:
text: -> "old"
}
expect(window.log_event).toHaveBeenCalledWith 'accordion',
newheader: 'new'
oldheader: 'old'
// Generated by CoffeeScript 1.3.2-pre
(function() {
describe('Navigation', function() {
beforeEach(function() {
loadFixtures('accordion.html');
return this.navigation = new Navigation;
});
describe('constructor', function() {
describe('when the #accordion exists', function() {
describe('when there is an active section', function() {
beforeEach(function() {
spyOn($.fn, 'accordion');
$('#accordion').append('<ul><li></li></ul><ul><li class="active"></li></ul>');
return new Navigation;
});
return it('activate the accordion with correct active section', function() {
return expect($('#accordion').accordion).toHaveBeenCalledWith({
active: 1,
header: 'h3',
autoHeight: false
});
});
});
describe('when there is no active section', function() {
beforeEach(function() {
spyOn($.fn, 'accordion');
$('#accordion').append('<ul><li></li></ul><ul><li></li></ul>');
return new Navigation;
});
return it('activate the accordian with section 1 as active', function() {
return expect($('#accordion').accordion).toHaveBeenCalledWith({
active: 1,
header: 'h3',
autoHeight: false
});
});
});
it('binds the accordionchange event', function() {
Navigation.bind();
return expect($('#accordion')).toHandleWith('accordionchange', this.navigation.log);
});
return it('bind the navigation toggle', function() {
Navigation.bind();
return expect($('#open_close_accordion a')).toHandleWith('click', this.navigation.toggle);
});
});
return describe('when the #accordion does not exists', function() {
beforeEach(function() {
return $('#accordion').remove();
});
return it('does not activate the accordion', function() {
spyOn($.fn, 'accordion');
Navigation.bind();
return expect($('#accordion').accordion).wasNotCalled();
});
});
});
describe('toggle', function() {
return it('toggle closed class on the wrapper', function() {
$('.course-wrapper').removeClass('closed');
this.navigation.toggle();
expect($('.course-wrapper')).toHaveClass('closed');
this.navigation.toggle();
return expect($('.course-wrapper')).not.toHaveClass('closed');
});
});
return describe('log', function() {
beforeEach(function() {
window.log_event = function() {};
return spyOn(window, 'log_event');
});
return it('submit event log', function() {
this.navigation.log({}, {
newHeader: {
text: function() {
return "new";
}
},
oldHeader: {
text: function() {
return "old";
}
}
});
return expect(window.log_event).toHaveBeenCalledWith('accordion', {
newheader: 'new',
oldheader: 'old'
});
});
});
});
}).call(this);
class CoursewareNavigation
constructor: ->
if $('#accordion').length
active = $('#accordion ul:has(li.active)').index('#accordion ul')
$('#accordion').bind('accordionchange', @log).accordion
active: if active >= 0 then active else 1
header: 'h3'
autoHeight: false
$('#open_close_accordion a').click @toggle
$('#accordion').show()
log: (event, ui) ->
log_event 'accordion',
newheader: ui.newHeader.text()
oldheader: ui.oldHeader.text()
toggle: ->
$('.course-wrapper').toggleClass('closed')
class Video class @Video
constructor: (@id, videos) -> constructor: (@id, videos) ->
window.player = null window.player = null
@element = $("#video_#{@id}") @element = $("#video_#{@id}")
......
class Courseware::Navigation class @Navigation
constructor: -> constructor: ->
if $('#accordion').length if $('#accordion').length
active = $('#accordion ul:has(li.active)').index('#accordion ul') active = $('#accordion ul:has(li.active)').index('#accordion ul')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment