adapt jasmine specs to the new structure
This commit is contained in:
parent
a3477b7691
commit
200887ca45
3 changed files with 234 additions and 235 deletions
|
|
@ -1,4 +1,10 @@
|
|||
/* Copyright (c) 2010-2012, Diaspora Inc. This file is
|
||||
* licensed under the Affero General Public License version 3 or later. See
|
||||
* the COPYRIGHT file.
|
||||
*/
|
||||
|
||||
describe("app.views.Publisher", function() {
|
||||
context("plain publisher", function() {
|
||||
beforeEach(function() {
|
||||
// should be jasmine helper
|
||||
loginAs({name: "alice", avatar : {small : "http://avatar.com/photo.jpg"}});
|
||||
|
|
@ -37,7 +43,7 @@ describe("app.views.Publisher", function() {
|
|||
spyOn(this.view, "close");
|
||||
|
||||
this.view.clear($.Event());
|
||||
expect(this.view.close);
|
||||
expect(this.view.close).toHaveBeenCalled();
|
||||
})
|
||||
|
||||
it("clears all textareas", function(){
|
||||
|
|
@ -56,12 +62,12 @@ describe("app.views.Publisher", function() {
|
|||
it("removes all photos from the dropzone area", function(){
|
||||
var self = this;
|
||||
_.times(3, function(){
|
||||
self.view.$("#photodropzone").append($("<li>"))
|
||||
self.view.el_photozone.append($("<li>"))
|
||||
});
|
||||
|
||||
expect(this.view.$("#photodropzone").html()).not.toBe("");
|
||||
expect(this.view.el_photozone.html()).not.toBe("");
|
||||
this.view.clear($.Event());
|
||||
expect(this.view.$("#photodropzone").html()).toBe("");
|
||||
expect(this.view.el_photozone.html()).toBe("");
|
||||
})
|
||||
|
||||
it("removes all photo values appended by the photo uploader", function(){
|
||||
|
|
@ -74,3 +80,173 @@ describe("app.views.Publisher", function() {
|
|||
})
|
||||
});
|
||||
});
|
||||
|
||||
context("#toggleService", function(){
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('aspects_index_services');
|
||||
this.view = new app.views.Publisher();
|
||||
});
|
||||
|
||||
it("toggles the 'dim' class on a clicked item", function() {
|
||||
var first = $(".service_icon").eq(0);
|
||||
var second = $(".service_icon").eq(1);
|
||||
|
||||
expect(first.hasClass('dim')).toBeTruthy();
|
||||
expect(second.hasClass('dim')).toBeTruthy();
|
||||
|
||||
first.trigger('click');
|
||||
|
||||
expect(first.hasClass('dim')).toBeFalsy();
|
||||
expect(second.hasClass('dim')).toBeTruthy();
|
||||
|
||||
first.trigger('click');
|
||||
|
||||
expect(first.hasClass('dim')).toBeTruthy();
|
||||
expect(second.hasClass('dim')).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("#_createCounter", function() {
|
||||
it("gets called in when you toggle service icons", function(){
|
||||
spyOn(this.view, '_createCounter');
|
||||
$(".service_icon").first().trigger('click');
|
||||
expect(this.view._createCounter).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("removes the 'old' .counter span", 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);
|
||||
$(".service_icon").first().trigger('click');
|
||||
expect($('input[name="services[]"]').length).toBe(1);
|
||||
$(".service_icon").first().trigger('click');
|
||||
expect($('input[name="services[]"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it("toggles the correct input", function() {
|
||||
var first = $(".service_icon").eq(0);
|
||||
var second = $(".service_icon").eq(1);
|
||||
|
||||
first.trigger('click');
|
||||
second.trigger('click');
|
||||
|
||||
expect($('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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context("aspect selection", function(){
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('status_message_new');
|
||||
|
||||
this.radio_els = $('#publisher .dropdown li.radio');
|
||||
this.check_els = $('#publisher .dropdown li.aspect_selector');
|
||||
|
||||
this.view = new app.views.Publisher();
|
||||
this.view.open();
|
||||
});
|
||||
|
||||
it("initializes with 'all_aspects'", function(){
|
||||
expect(this.radio_els.first().hasClass('selected')).toBeFalsy();
|
||||
expect(this.radio_els.last().hasClass('selected')).toBeTruthy();
|
||||
|
||||
_.each(this.check_els, function(el){
|
||||
expect($(el).hasClass('selected')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it("toggles the selected entry visually", function(){
|
||||
this.check_els.last().trigger('click');
|
||||
|
||||
_.each(this.radio_els, function(el){
|
||||
expect($(el).hasClass('selected')).toBeFalsy();
|
||||
});
|
||||
|
||||
expect(this.check_els.first().hasClass('selected')).toBeFalsy();
|
||||
expect(this.check_els.last().hasClass('selected')).toBeTruthy();
|
||||
});
|
||||
|
||||
describe("#_updateSelectedAspectIds", 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);
|
||||
expect(selected.first().val()).toBe('all_aspects');
|
||||
|
||||
this.li.trigger('click');
|
||||
|
||||
selected = this.view.$('input[name="aspect_ids[]"]');
|
||||
expect(selected.length).toBe(1);
|
||||
expect(selected.first().val()).toBe('42');
|
||||
});
|
||||
|
||||
it("toggles the same item", function() {
|
||||
expect(this.view.$('input[name="aspect_ids[]"]').length).toBe(1);
|
||||
|
||||
this.li.trigger('click');
|
||||
expect(this.view.$('input[name="aspect_ids[]"]').length).toBe(1);
|
||||
|
||||
this.li.trigger('click');
|
||||
expect(this.view.$('input[name="aspect_ids[]"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it("keeps other fields with different values", function() {
|
||||
var li2 = $("<li data-aspect_id=99></li>");
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@ describe("bookmarklet", function() {
|
|||
});
|
||||
|
||||
it('verifies the publisher is loaded', function(){
|
||||
expect(typeof Publisher === "object").toBeTruthy();
|
||||
expect(typeof app.publisher === "object").toBeTruthy();
|
||||
});
|
||||
|
||||
it('verifies we are using the bookmarklet', function(){
|
||||
expect(Publisher.bookmarklet).toBeTruthy();
|
||||
expect(app.publisher.options.bookmarklet).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,177 +0,0 @@
|
|||
/* Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
* licensed under the Affero General Public License version 3 or later. See
|
||||
* the COPYRIGHT file.
|
||||
*/
|
||||
|
||||
describe("Publisher", function() {
|
||||
|
||||
Publisher.open = function(){ this.form().removeClass("closed"); }
|
||||
|
||||
describe("toggleCounter", function(){
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('aspects_index_services');
|
||||
});
|
||||
|
||||
it("gets called in when you toggle service icons", function(){
|
||||
spyOn(Publisher, 'createCounter');
|
||||
Publisher.toggleServiceField($(".service_icon").first());
|
||||
expect(Publisher.createCounter).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("removes the .counter span", function(){
|
||||
spyOn($.fn, "remove");
|
||||
Publisher.createCounter($(".service_icon").first());
|
||||
expect($.fn.remove).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("bindAspectToggles", function() {
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('status_message_new');
|
||||
Publisher.open();
|
||||
});
|
||||
|
||||
it('gets called on initialize', function(){
|
||||
spyOn(Publisher, 'bindAspectToggles');
|
||||
Publisher.initialize();
|
||||
expect(Publisher.bindAspectToggles).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('correctly initializes an all_aspects state', function(){
|
||||
Publisher.initialize();
|
||||
|
||||
expect($("#publisher .dropdown .dropdown_list li.radio").first().hasClass("selected")).toBeFalsy();
|
||||
expect($("#publisher .dropdown .dropdown_list li.radio").last().hasClass("selected")).toBeTruthy();
|
||||
|
||||
$.each($("#publihser .dropdown .dropdown_list li.aspect_selector"), function(index, element){
|
||||
expect($(element).hasClass("selected")).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('toggles selected only on the clicked icon', function(){
|
||||
Publisher.initialize();
|
||||
|
||||
$("#publisher .dropdown .dropdown_list li.aspect_selector").last().click();
|
||||
|
||||
$.each($("#publisher .dropdown .dropdown_list li.radio"), function(index, element){
|
||||
expect($(element).hasClass("selected")).toBeFalsy();
|
||||
});
|
||||
|
||||
expect($("#publisher .dropdown .dropdown_list li.aspect_selector").first().hasClass("selected")).toBeFalsy();
|
||||
expect($("#publisher .dropdown .dropdown_list li.aspect_selector").last().hasClass("selected")).toBeTruthy();
|
||||
});
|
||||
|
||||
it('calls toggleAspectIds with the clicked element', function(){
|
||||
spyOn(Publisher, 'toggleAspectIds');
|
||||
Publisher.bindAspectToggles();
|
||||
var aspectBadge = $("#publisher .dropdown .dropdown_list li").last();
|
||||
aspectBadge.click();
|
||||
expect(Publisher.toggleAspectIds.mostRecentCall.args[0].get(0)).toEqual(aspectBadge.get(0));
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggleAspectIds', function(){
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('status_message_new');
|
||||
li = $("<li data-aspect_id=42></li>");
|
||||
});
|
||||
|
||||
it('adds a hidden field to the form if there is not one already', function(){
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(1);
|
||||
expect($('#publisher [name="aspect_ids[]"]').last().attr('value')).toBe('all_aspects');
|
||||
Publisher.toggleAspectIds(li);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(1);
|
||||
expect($('#publisher [name="aspect_ids[]"]').last().attr('value')).toBe('42');
|
||||
});
|
||||
|
||||
it('removes the hidden field if its already there', function() {
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(1);
|
||||
|
||||
Publisher.toggleAspectIds(li);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(1);
|
||||
|
||||
Publisher.toggleAspectIds(li);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it('does not remove a hidden field with a different value', function() {
|
||||
var li2 = $("<li data-aspect_id=99></li>");
|
||||
|
||||
Publisher.toggleAspectIds(li);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(1);
|
||||
|
||||
Publisher.toggleAspectIds(li2);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bindServiceIcons", function() {
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('aspects_index_services');
|
||||
});
|
||||
|
||||
it('gets called on initialize', function(){
|
||||
spyOn(Publisher, 'bindServiceIcons');
|
||||
Publisher.initialize();
|
||||
expect(Publisher.bindServiceIcons).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('toggles dim only on the clicked icon', function(){
|
||||
expect($(".service_icon#facebook").hasClass("dim")).toBeTruthy();
|
||||
expect($(".service_icon#twitter").hasClass("dim")).toBeTruthy();
|
||||
|
||||
Publisher.bindServiceIcons();
|
||||
$(".service_icon#facebook").click();
|
||||
|
||||
expect($(".service_icon#facebook").hasClass("dim")).toBeFalsy();
|
||||
expect($(".service_icon#twitter").hasClass("dim")).toBeTruthy();
|
||||
});
|
||||
|
||||
it('binds to the services icons and toggles the hidden field', function(){
|
||||
spyOn(Publisher, 'toggleServiceField');
|
||||
Publisher.bindServiceIcons();
|
||||
$(".service_icon#facebook").click();
|
||||
|
||||
expect(Publisher.toggleServiceField).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggleServiceField', function(){
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('aspects_index_services');
|
||||
});
|
||||
|
||||
it('adds a hidden field to the form if there is not one already', function(){
|
||||
expect($('#publisher [name="services[]"]').length).toBe(0);
|
||||
Publisher.toggleServiceField($(".service_icon#facebook").first());
|
||||
expect($('#publisher [name="services[]"]').length).toBe(1);
|
||||
expect($('#publisher [name="services[]"]').attr('value')).toBe("facebook");
|
||||
});
|
||||
|
||||
it('removes the hidden field if its already there', function() {
|
||||
Publisher.toggleServiceField($(".service_icon#facebook").first());
|
||||
expect($('#publisher [name="services[]"]').length).toBe(1);
|
||||
|
||||
Publisher.toggleServiceField($(".service_icon#facebook").first());
|
||||
expect($('#publisher [name="services[]"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it('does not remove a hidden field with a different value', function() {
|
||||
Publisher.toggleServiceField($(".service_icon#facebook").first());
|
||||
expect($('#publisher [name="services[]"]').length).toBe(1);
|
||||
|
||||
Publisher.toggleServiceField($(".service_icon#twitter").first());
|
||||
expect($('#publisher [name="services[]"]').length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("input", function(){
|
||||
beforeEach(function(){
|
||||
spec.loadFixture('aspects_index_prefill');
|
||||
});
|
||||
it("returns the status_message_fake_text textarea", function(){
|
||||
expect(Publisher.input()[0].id).toBe('status_message_fake_text');
|
||||
expect(Publisher.input().length).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue