fixed all but two jasmine specs...
This commit is contained in:
parent
718cb2c2f4
commit
b61246c168
3 changed files with 61 additions and 85 deletions
|
|
@ -71,7 +71,7 @@ module AspectGlobalHelper
|
|||
klass = checked ? "selected" : ""
|
||||
|
||||
str = <<LISTITEM
|
||||
<li data-aspect_id=#{aspect.id} class='#{klass}'>
|
||||
<li data-aspect_id=#{aspect.id} class='#{klass} aspect_selector'>
|
||||
#{aspect.name}
|
||||
</li>
|
||||
LISTITEM
|
||||
|
|
|
|||
|
|
@ -5,18 +5,21 @@
|
|||
|
||||
//TODO: make this a widget
|
||||
var Publisher = {
|
||||
|
||||
bookmarklet : false,
|
||||
close: function(){
|
||||
Publisher.form().addClass('closed');
|
||||
Publisher.form().find("#publisher_textarea_wrapper").removeClass('active');
|
||||
Publisher.form().find("textarea.ac_input").css('min-height', '');
|
||||
},
|
||||
|
||||
open: function(){
|
||||
Publisher.form().removeClass('closed');
|
||||
Publisher.form().find("#publisher_textarea_wrapper").addClass('active');
|
||||
Publisher.form().find("textarea.ac_input").css('min-height', '42px');
|
||||
Publisher.determineSubmitAvailability();
|
||||
},
|
||||
|
||||
cachedForm : false,
|
||||
form: function(){
|
||||
if(!Publisher.cachedForm){
|
||||
|
|
@ -24,6 +27,7 @@ var Publisher = {
|
|||
}
|
||||
return Publisher.cachedForm;
|
||||
},
|
||||
|
||||
cachedInput : false,
|
||||
input: function(){
|
||||
if(!Publisher.cachedInput){
|
||||
|
|
@ -237,8 +241,7 @@ var Publisher = {
|
|||
|
||||
},
|
||||
|
||||
searchTermFromValue: function(value, cursorIndex)
|
||||
{
|
||||
searchTermFromValue: function(value, cursorIndex) {
|
||||
var stringLoc = Publisher.autocompletion.findStringToReplace(value, cursorIndex);
|
||||
if(stringLoc[0] <= 2){
|
||||
stringLoc[0] = 0;
|
||||
|
|
@ -266,44 +269,32 @@ var Publisher = {
|
|||
);
|
||||
}
|
||||
},
|
||||
|
||||
determineSubmitAvailability: function(){
|
||||
var onlyWhitespaces = (Publisher.input().val().trim() === '');
|
||||
var isSubmitDisabled = Publisher.submit().attr('disabled');
|
||||
var isPhotoAttached = ($("#photodropzone").children().length > 0);
|
||||
var onlyWhitespaces = (Publisher.input().val().trim() === ''),
|
||||
isSubmitDisabled = Publisher.submit().attr('disabled'),
|
||||
isPhotoAttached = ($("#photodropzone").children().length > 0);
|
||||
|
||||
if ((onlyWhitespaces && !isPhotoAttached) && !isSubmitDisabled) {
|
||||
Publisher.submit().attr('disabled', true);
|
||||
} else if ((!onlyWhitespaces || isPhotoAttached) && isSubmitDisabled) {
|
||||
Publisher.submit().removeAttr('disabled');
|
||||
}
|
||||
},
|
||||
|
||||
clear: function(){
|
||||
this.autocompletion.mentionList.clear();
|
||||
$("#photodropzone").find('li').remove();
|
||||
$("#publisher textarea").removeClass("with_attachments").css('paddingBottom', '');
|
||||
},
|
||||
|
||||
bindServiceIcons: function(){
|
||||
$(".service_icon").bind("click", function(evt){
|
||||
$(this).toggleClass("dim");
|
||||
Publisher.toggleServiceField($(this));
|
||||
});
|
||||
},
|
||||
bindPublicIcon: function(){
|
||||
$(".public_icon").bind("click", function(evt){
|
||||
$(this).toggleClass("dim");
|
||||
var public_field = $("#publisher #status_message_public");
|
||||
|
||||
if (public_field.val() == 'false') {
|
||||
public_field.val('true');
|
||||
$(this).attr('title', Diaspora.I18n.t('publisher.public'));
|
||||
} else {
|
||||
public_field.val('false');
|
||||
$(this).attr('title', Diaspora.I18n.t('publisher.limited'));
|
||||
}
|
||||
|
||||
$(this).tipsy(true).fixTitle();
|
||||
$(this).tipsy(true).show();
|
||||
});
|
||||
},
|
||||
toggleServiceField: function(service){
|
||||
Publisher.createCounter(service);
|
||||
|
||||
|
|
@ -346,12 +337,11 @@ var Publisher = {
|
|||
var aspectId = li.attr('data-aspect_id'),
|
||||
hiddenFields = $('#publisher [name="aspect_ids[]"]'),
|
||||
appendId = function(){
|
||||
console.log(aspectId);
|
||||
$("#publisher .content_creation form").append(
|
||||
'<input id="aspect_ids_" name="aspect_ids[]" type="hidden" value="'+aspectId+'">');
|
||||
};
|
||||
|
||||
console.log(aspectId);
|
||||
console.log(li);
|
||||
|
||||
if(li.hasClass('radio')){
|
||||
$.each(hiddenFields, function(index, value){
|
||||
|
|
@ -389,6 +379,7 @@ var Publisher = {
|
|||
$('#status_message_fake_text').charCount({allowed: min, warning: min/10 });
|
||||
}
|
||||
},
|
||||
|
||||
bindAspectToggles: function() {
|
||||
$('#publisher .dropdown .dropdown_list li').bind("click", function(evt){
|
||||
var li = $(this),
|
||||
|
|
@ -462,12 +453,12 @@ var Publisher = {
|
|||
Publisher.form().bind('ajax:failure', Publisher.onFailure);
|
||||
Publisher.form().bind('ajax:success', Publisher.onSuccess);
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
Publisher.cachedForm = Publisher.cachedSubmit =
|
||||
Publisher.cachedInput = Publisher.cachedHiddenInput = false;
|
||||
|
||||
Publisher.bindServiceIcons();
|
||||
Publisher.bindPublicIcon();
|
||||
Publisher.bindAspectToggles();
|
||||
|
||||
/* close text area */
|
||||
|
|
@ -477,7 +468,7 @@ var Publisher = {
|
|||
});
|
||||
Publisher.close();
|
||||
});
|
||||
|
||||
|
||||
Publisher.autocompletion.initialize();
|
||||
Publisher.hiddenInput().val(Publisher.input().val());
|
||||
Publisher.input().autoResize();
|
||||
|
|
|
|||
|
|
@ -43,28 +43,43 @@ describe("Publisher", function() {
|
|||
Publisher.initialize();
|
||||
expect(Publisher.bindAspectToggles).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('toggles removed only on the clicked icon', function(){
|
||||
|
||||
it('correctly initializes an all_aspects state', function(){
|
||||
Publisher.initialize();
|
||||
|
||||
expect($("#publisher .dropdown .dropdown_list li").first().hasClass("selected")).toBeTruthy();
|
||||
expect($("#publihser .dropdown .dropdown_list li").last().hasClass("selected")).toBeFalsy();
|
||||
expect($("#publisher .dropdown .dropdown_list li.radio").first().hasClass("selected")).toBeFalsy();
|
||||
expect($("#publisher .dropdown .dropdown_list li.radio").last().hasClass("selected")).toBeTruthy();
|
||||
|
||||
Publisher.bindAspectToggles();
|
||||
$("#publisher .dropdown .dropdown_list li").last().click();
|
||||
|
||||
expect($("#publisher .dropdown .dropdown_list li").first().hasClass("selected")).toBeTruthy();
|
||||
expect($("#publisher .dropdown .dropdown_list li").last().hasClass("selected")).toBeTruthy();
|
||||
$.each($("#publihser .dropdown .dropdown_list li.aspect_selector"), function(index, element){
|
||||
expect($(element).hasClass("selected")).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
it('binds to the services icons and toggles the hidden field', function(){
|
||||
it('toggles removed only on the clicked icon', function(){
|
||||
Publisher.initialize();
|
||||
Publisher.bindAspectToggles();
|
||||
|
||||
$("#publisher .dropdown .dropdown_list li.aspect_selector").last().click();
|
||||
|
||||
$.each($("#publihser .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('is called with the correct element', function(){
|
||||
spyOn(Publisher, 'toggleAspectIds');
|
||||
Publisher.bindAspectToggles();
|
||||
|
||||
var aspBadge = $("#publisher .dropdown .dropdown_list li").last();
|
||||
var aspNum = aspBadge.attr('data-aspect_id');
|
||||
|
||||
console.log(aspBadge);
|
||||
|
||||
aspBadge.click();
|
||||
|
||||
expect(Publisher.toggleAspectIds).toHaveBeenCalledWith(aspNum);
|
||||
expect(Publisher.toggleAspectIds).toHaveBeenCalledWith(aspBadge);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -72,68 +87,38 @@ describe("Publisher", function() {
|
|||
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(2);
|
||||
Publisher.toggleAspectIds(42);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(3);
|
||||
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() {
|
||||
Publisher.toggleAspectIds(42);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(3);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(1);
|
||||
|
||||
Publisher.toggleAspectIds(42);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(2);
|
||||
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() {
|
||||
Publisher.toggleAspectIds(42);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(3);
|
||||
var li2 = $("<li data-aspect_id=99></li>");
|
||||
|
||||
Publisher.toggleAspectIds(99);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(4);
|
||||
Publisher.toggleAspectIds(li);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(1);
|
||||
|
||||
Publisher.toggleAspectIds(li2);
|
||||
expect($('#publisher [name="aspect_ids[]"]').length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bindPublicIcon", function() {
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('aspects_index_services');
|
||||
Diaspora.I18n.loadLocale(
|
||||
{ 'publisher' :
|
||||
{ 'public' : 'is public', 'limited' : 'is limited' } }, 'en');
|
||||
});
|
||||
|
||||
it('gets called on initialize', function(){
|
||||
spyOn(Publisher, 'bindPublicIcon');
|
||||
Publisher.initialize();
|
||||
expect(Publisher.bindPublicIcon).toHaveBeenCalled();
|
||||
});
|
||||
it('toggles dim only on the clicked icon', function(){
|
||||
expect($(".public_icon").hasClass("dim")).toBeTruthy();
|
||||
|
||||
Publisher.bindPublicIcon();
|
||||
$(".public_icon").click();
|
||||
|
||||
expect($(".public_icon").hasClass("dim")).toBeFalsy();
|
||||
});
|
||||
it('toggles the hidden field', function(){
|
||||
Publisher.bindPublicIcon();
|
||||
expect($('#publisher #status_message_public').val()).toBe('false');
|
||||
|
||||
$(".public_icon").click();
|
||||
expect($('#publisher #status_message_public').val()).toBe('true');
|
||||
});
|
||||
it('toggles the tooltip on the clicked icon', function(){
|
||||
Publisher.bindPublicIcon();
|
||||
$(".public_icon").click();
|
||||
expect($(".public_icon")).toHaveAttr('original-title', 'is public');
|
||||
$(".public_icon").click();
|
||||
expect($(".public_icon")).toHaveAttr('original-title', 'is limited');
|
||||
});
|
||||
});
|
||||
describe("bindServiceIcons", function() {
|
||||
beforeEach( function(){
|
||||
spec.loadFixture('aspects_index_services');
|
||||
|
|
|
|||
Loading…
Reference in a new issue