fix jasmine tests
This commit is contained in:
parent
4da696253a
commit
bedfacecfd
2 changed files with 49 additions and 97 deletions
|
|
@ -9,8 +9,7 @@
|
|||
//= require ./publisher/uploader
|
||||
//= require jquery.textchange
|
||||
|
||||
app.views.Publisher = Backbone.View.extend(_.extend(
|
||||
app.views.PublisherGettingStarted, {
|
||||
app.views.Publisher = Backbone.View.extend({
|
||||
|
||||
el : "#publisher",
|
||||
|
||||
|
|
@ -151,14 +150,15 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
showLocation: function(){
|
||||
if($('#location').length == 0){
|
||||
$('#publisher_textarea_wrapper').after('<div id="location"></div>');
|
||||
app.views.location = new app.views.Location();
|
||||
this.view_locator = new app.views.Location();
|
||||
}
|
||||
},
|
||||
|
||||
// destroys the location
|
||||
destroyLocation: function(){
|
||||
if(app.views.location){
|
||||
app.views.location.remove();
|
||||
if(this.view_locator){
|
||||
this.view_locator.remove();
|
||||
delete this.view_locator;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -346,7 +346,7 @@ app.views.Publisher = Backbone.View.extend(_.extend(
|
|||
});
|
||||
}
|
||||
|
||||
}));
|
||||
});
|
||||
|
||||
// jQuery helper for serializing a <form> into JSON
|
||||
$.fn.serializeObject = function()
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ describe("app.views.Publisher", function() {
|
|||
})
|
||||
});
|
||||
|
||||
context("#toggleService", function(){
|
||||
context("services", function(){
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('aspects_index_services');
|
||||
this.view = new app.views.Publisher();
|
||||
|
|
@ -156,33 +156,24 @@ describe("app.views.Publisher", function() {
|
|||
expect(second.hasClass('dim')).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("#_createCounter", function() {
|
||||
it("gets called in when you toggle service icons", function(){
|
||||
spyOn(this.view, '_createCounter');
|
||||
it("creates a counter element", function(){
|
||||
expect(this.view.$('.counter').length).toBe(0);
|
||||
$(".service_icon").first().trigger('click');
|
||||
expect(this.view._createCounter).toHaveBeenCalled();
|
||||
expect(this.view.$('.counter').length).toBe(1);
|
||||
});
|
||||
|
||||
it("removes the 'old' .counter span", function(){
|
||||
it("removes any old counters", function(){
|
||||
spyOn($.fn, "remove");
|
||||
$(".service_icon").first().trigger('click');
|
||||
expect($.fn.remove).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("#_toggleServiceField", function() {
|
||||
it("gets called when you toggle service icons", function(){
|
||||
spyOn(this.view, '_toggleServiceField');
|
||||
$(".service_icon").first().trigger('click');
|
||||
expect(this.view._toggleServiceField).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("toggles the hidden input field", function(){
|
||||
expect($('input[name="services[]"]').length).toBe(0);
|
||||
expect(this.view.$('input[name="services[]"]').length).toBe(0);
|
||||
$(".service_icon").first().trigger('click');
|
||||
expect($('input[name="services[]"]').length).toBe(1);
|
||||
expect(this.view.$('input[name="services[]"]').length).toBe(1);
|
||||
$(".service_icon").first().trigger('click');
|
||||
expect($('input[name="services[]"]').length).toBe(0);
|
||||
expect(this.view.$('input[name="services[]"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it("toggles the correct input", function() {
|
||||
|
|
@ -192,16 +183,15 @@ describe("app.views.Publisher", function() {
|
|||
first.trigger('click');
|
||||
second.trigger('click');
|
||||
|
||||
expect($('input[name="services[]"]').length).toBe(2);
|
||||
expect(this.view.$('input[name="services[]"]').length).toBe(2);
|
||||
|
||||
first.trigger('click');
|
||||
|
||||
var prov1 = first.attr('id');
|
||||
var prov2 = second.attr('id');
|
||||
|
||||
expect($('input[name="services[]"][value="'+prov1+'"]').length).toBe(0);
|
||||
expect($('input[name="services[]"][value="'+prov2+'"]').length).toBe(1);
|
||||
});
|
||||
expect(this.view.$('input[name="services[]"][value="'+prov1+'"]').length).toBe(0);
|
||||
expect(this.view.$('input[name="services[]"][value="'+prov2+'"]').length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -236,18 +226,12 @@ describe("app.views.Publisher", function() {
|
|||
expect(this.check_els.last().hasClass('selected')).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("#_updateSelectedAspectIds", function(){
|
||||
describe("hidden form elements", function(){
|
||||
beforeEach(function(){
|
||||
this.li = $('<li data-aspect_id="42" />');
|
||||
this.view.$('.dropdown_list').append(this.li);
|
||||
});
|
||||
|
||||
it("gets called when aspects are selected", function(){
|
||||
spyOn(this.view, "_updateSelectedAspectIds");
|
||||
this.check_els.last().trigger('click');
|
||||
expect(this.view._updateSelectedAspectIds).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("removes a previous selection and inserts the current one", function() {
|
||||
var selected = this.view.$('input[name="aspect_ids[]"]');
|
||||
expect(selected.length).toBe(1);
|
||||
|
|
@ -261,13 +245,13 @@ describe("app.views.Publisher", function() {
|
|||
});
|
||||
|
||||
it("toggles the same item", function() {
|
||||
expect(this.view.$('input[name="aspect_ids[]"]').length).toBe(1);
|
||||
expect(this.view.$('input[name="aspect_ids[]"][value="42"]').length).toBe(0);
|
||||
|
||||
this.li.trigger('click');
|
||||
expect(this.view.$('input[name="aspect_ids[]"]').length).toBe(1);
|
||||
expect(this.view.$('input[name="aspect_ids[]"][value="42"]').length).toBe(1);
|
||||
|
||||
this.li.trigger('click');
|
||||
expect(this.view.$('input[name="aspect_ids[]"]').length).toBe(0);
|
||||
expect(this.view.$('input[name="aspect_ids[]"][value="42"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it("keeps other fields with different values", function() {
|
||||
|
|
@ -275,30 +259,13 @@ describe("app.views.Publisher", function() {
|
|||
this.view.$('.dropdown_list').append(li2);
|
||||
|
||||
this.li.trigger('click');
|
||||
expect(this.view.$('input[name="aspect_ids[]"]').length).toBe(1);
|
||||
|
||||
li2.trigger('click');
|
||||
expect(this.view.$('input[name="aspect_ids[]"]').length).toBe(2);
|
||||
|
||||
expect(this.view.$('input[name="aspect_ids[]"][value="42"]').length).toBe(1);
|
||||
expect(this.view.$('input[name="aspect_ids[]"][value="99"]').length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#_addHiddenAspectInput", function(){
|
||||
it("gets called when aspects are selected", function(){
|
||||
spyOn(this.view, "_addHiddenAspectInput");
|
||||
this.check_els.last().trigger('click');
|
||||
expect(this.view._addHiddenAspectInput).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("adds a hidden input to the form", function(){
|
||||
var id = 42;
|
||||
|
||||
this.view._addHiddenAspectInput(id);
|
||||
var input = this.view.$('input[name="aspect_ids[]"][value="'+id+'"]');
|
||||
|
||||
expect(input.length).toBe(1);
|
||||
expect(input.val()).toBe('42');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context("locator", function() {
|
||||
|
|
@ -333,26 +300,11 @@ describe("app.views.Publisher", function() {
|
|||
|
||||
describe('#destroyLocation', function(){
|
||||
it("Destroy location if exists", function(){
|
||||
|
||||
// inserts location to the DOM; it is the location's view element
|
||||
setFixtures('<div id="location"></div>');
|
||||
|
||||
//Backup original view
|
||||
var original_location = app.views.Location;
|
||||
|
||||
// creates a new Location view with the #location element
|
||||
app.views.Location = new Backbone.View({el:"#location"});
|
||||
|
||||
// creates the mock
|
||||
app.views.location = sinon.mock(app.views.Location).object;
|
||||
|
||||
// calls the destroy function and test the expected result
|
||||
this.view.view_locator = new app.views.Location({el: "#location"});
|
||||
this.view.destroyLocation();
|
||||
|
||||
expect($("#location").length).toBe(0);
|
||||
|
||||
//Restore view
|
||||
app.views.Location = original_location;
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue