init
This commit is contained in:
.gitignoreCHANGELOG.txtLICENSE-GPLLICENSE-MITREADME.mdgrunt.jsjquery.ui.datepicker-ru.jsmakezippackage.json
libs
bootstrap204
css
img
js
bootstrap211
css
img
js
bootstrap221
css
img
js
jquery-ui-1.9.1.custom
css
redmond
images
ui-bg_flat_0_aaaaaa_40x100.pngui-bg_flat_55_fbec88_40x100.pngui-bg_glass_75_d0e5f5_1x400.pngui-bg_glass_85_dfeffc_1x400.pngui-bg_glass_95_fef1ec_1x400.pngui-bg_gloss-wave_55_5c9ccc_500x100.pngui-bg_inset-hard_100_f5f8f9_1x100.pngui-bg_inset-hard_100_fcfdfd_1x100.pngui-icons_217bc0_256x240.pngui-icons_2e83ff_256x240.pngui-icons_469bdd_256x240.pngui-icons_6da8d5_256x240.pngui-icons_cd0a0a_256x240.pngui-icons_d8e7f3_256x240.pngui-icons_f9bd01_256x240.png
jquery-ui-1.9.1.custom.cssjquery-ui-1.9.1.custom.min.csssmoothness
images
ui-bg_flat_0_aaaaaa_40x100.pngui-bg_flat_75_ffffff_40x100.pngui-bg_glass_55_fbf9ee_1x400.pngui-bg_glass_65_ffffff_1x400.pngui-bg_glass_75_dadada_1x400.pngui-bg_glass_75_e6e6e6_1x400.pngui-bg_glass_95_fef1ec_1x400.pngui-bg_highlight-soft_75_cccccc_1x100.pngui-icons_222222_256x240.pngui-icons_2e83ff_256x240.pngui-icons_454545_256x240.pngui-icons_888888_256x240.pngui-icons_cd0a0a_256x240.png
jquery-ui-1.9.1.custom.cssjquery-ui-1.9.1.custom.min.cssjs
jquery-ui-datepicker
jquery
mockjax
poshytip
jquery.poshytip.jsjquery.poshytip.min.jsjquery.poshytip_corrected.js
tip-darkgray
tip-green
tip-skyblue
tip-twitter
tip-violet
tip-yellow
tip-yellowsimple
qunit
src
containers
editable-container.csseditable-container.jseditable-inline.jseditable-popover.jseditable-poshytip.jseditable-tooltip.js
editable-form
editable-form-bootstrap.jseditable-form-jqueryui.jseditable-form-utils.jseditable-form.csseditable-form.js
img
element
inputs
abstract.js
date
bootstrap-datepicker.jsdate.jsdatepicker.css
dateui.jsselect.jstext.jstextarea.jslocales
bootstrap-datepicker.bg.jsbootstrap-datepicker.br.jsbootstrap-datepicker.cs.jsbootstrap-datepicker.da.jsbootstrap-datepicker.de.jsbootstrap-datepicker.es.jsbootstrap-datepicker.fi.jsbootstrap-datepicker.fr.jsbootstrap-datepicker.id.jsbootstrap-datepicker.is.jsbootstrap-datepicker.it.jsbootstrap-datepicker.ja.jsbootstrap-datepicker.kr.jsbootstrap-datepicker.lt.jsbootstrap-datepicker.lv.jsbootstrap-datepicker.ms.jsbootstrap-datepicker.nb.jsbootstrap-datepicker.nl.jsbootstrap-datepicker.pl.jsbootstrap-datepicker.pt-BR.jsbootstrap-datepicker.pt.jsbootstrap-datepicker.ru.jsbootstrap-datepicker.sl.jsbootstrap-datepicker.sv.jsbootstrap-datepicker.th.jsbootstrap-datepicker.tr.jsbootstrap-datepicker.zh-CN.jsbootstrap-datepicker.zh-TW.js
test
365
test/unit/text.js
Normal file
365
test/unit/text.js
Normal file
@@ -0,0 +1,365 @@
|
||||
$(function () {
|
||||
|
||||
module("text", {
|
||||
setup: function() {
|
||||
fx = $('#async-fixture');
|
||||
$.fn.editable.defaults.name = 'name1';
|
||||
}
|
||||
});
|
||||
|
||||
test("if element originally empty: emptytext should be shown and input should contain ''", function () {
|
||||
var emptytext = 'empty!',
|
||||
e = $('<a href="#" id="a"> </a>').appendTo('#qunit-fixture').editable({emptytext: emptytext});
|
||||
|
||||
equal(e.text(), emptytext, 'emptytext shown on init');
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
equal(p.find('input[type=text]').val(), '', 'input val is empty string')
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed')
|
||||
})
|
||||
|
||||
test("option 'placeholder'", function () {
|
||||
var e = $('<a href="#" id="a" data-placeholder="abc"> </a>').appendTo('#qunit-fixture').editable();
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
equal(p.find('input[type=text]').attr('placeholder'), 'abc', 'placeholder exists');
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
});
|
||||
|
||||
test("option 'inputclass'", function () {
|
||||
var e = $('<a href="#" id="a" data-inputclass="span4"> </a>').appendTo('#qunit-fixture').editable();
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
ok(p.find('input[type=text]').hasClass('span4'), 'class set correctly');
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
});
|
||||
|
||||
test("option 'toggle' = manual", function () {
|
||||
var e = $('<a href="#" id="a"></a>').appendTo('#qunit-fixture').editable({
|
||||
toggle: 'manual'
|
||||
});
|
||||
|
||||
e.click();
|
||||
ok(!e.data().editableContainer, 'popover not visible after click');
|
||||
e.editable('show');
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'shown manually');
|
||||
});
|
||||
|
||||
asyncTest("should load correct value and save new entered text (and value)", function () {
|
||||
var v = 'ab<b>"',
|
||||
esc_v = $('<div>').text(v).html(),
|
||||
e = $('<a href="#" data-pk="1" data-name="text1" data-url="post-text.php" data-params="{\'q\': \'w\'}">'+esc_v+'</a>').appendTo(fx).editable({
|
||||
success: function(data) {
|
||||
return false;
|
||||
}
|
||||
}),
|
||||
data,
|
||||
newText = 'cd<e>;"';
|
||||
|
||||
$.mockjax({
|
||||
url: 'post-text.php',
|
||||
response: function(settings) {
|
||||
data = settings.data;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible')
|
||||
ok(p.find('.editableform-loading').length, 'loading class exists')
|
||||
ok(!p.find('.editableform-loading').is(':visible'), 'loading class is hidden')
|
||||
ok(p.find('input[type=text]').length, 'input exists')
|
||||
equal(p.find('input[type=text]').val(), v, 'input contain correct value')
|
||||
p.find('input').val(newText);
|
||||
p.find('button[type=submit]').click();
|
||||
ok(p.find('.editableform-loading').is(':visible'), 'loading class is visible');
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popover closed');
|
||||
equal(e.data('editable').value, newText, 'new text saved to value');
|
||||
equal(e.text(), newText, 'new text shown');
|
||||
ok(data, 'ajax performed');
|
||||
equal(data.name, 'text1', 'name sent');
|
||||
equal(data.pk, 1, 'pk sent');
|
||||
equal(data.value, newText, 'value sent');
|
||||
equal(data.q, 'w', 'params sent');
|
||||
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
asyncTest("should show error on server validation", function () {
|
||||
var msg = 'required',
|
||||
e = $('<a href="#" data-name="text1">abc</a>').appendTo(fx).editable({
|
||||
validate: function(value) { if(value == '') return msg; }
|
||||
}),
|
||||
newText = '';
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover shown');
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(p.is(':visible'), 'popover still shown');
|
||||
ok(p.find('.editable-error-block').length, 'class "editable-error-block" exists');
|
||||
equal(p.find('.editable-error-block').text(), 'required', 'error msg shown');
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
/*
|
||||
test("test validation map", function () {
|
||||
var e = $('<a href="#" class="map" data-name="e" data-name="text1">abc</a>').appendTo('#qunit-fixture'),
|
||||
e1 = $('<a href="#" class="map" data-name="e1" data-name="text1">abc</a>').appendTo('#qunit-fixture'),
|
||||
newText = '';
|
||||
|
||||
$('.map').editable({
|
||||
validate: {
|
||||
e: function(value) { if(value == '') return 'required1';
|
||||
},
|
||||
e1:function(value) { if(value == '') return 'required2';
|
||||
},
|
||||
e2: 'qwerty' //this should not throw error
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
ok(p.is(':visible'), 'popover still shown');
|
||||
ok(p.find('.error').length, 'class "error" exists');
|
||||
equal(p.find('.editable-error-block').text(), 'required1', 'error msg shown');
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
|
||||
e = e1;
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
ok(p.is(':visible'), 'popover still shown');
|
||||
ok(p.find('.error').length, 'class "error" exists');
|
||||
equal(p.find('.editable-error-block').text(), 'required2', 'error msg shown');
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
});
|
||||
*/
|
||||
|
||||
asyncTest("should not perform request if value not changed", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post-no.php" data-name="text1">abc</a>').appendTo(fx).editable(),
|
||||
req = 0;
|
||||
|
||||
$.mockjax({
|
||||
url: 'post-no.php',
|
||||
response: function() {
|
||||
req++;
|
||||
}
|
||||
});
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
p.find('button[type=submit]').click();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popover closed');
|
||||
equal(req, 0, 'request was not performed');
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
asyncTest("should show error if success callback return string", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1">abc</a>').appendTo(fx).editable({
|
||||
success: function(data) {
|
||||
return 'error';
|
||||
}
|
||||
}),
|
||||
newText = 'cd<e>;"'
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
|
||||
ok(p.find('input[type=text]').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(p.is(':visible'), 'popover still shown');
|
||||
ok(p.find('.editable-error-block').length, 'class "editable-error-block" exists');
|
||||
equal(p.find('.editable-error-block').text(), 'error', 'error msg shown');
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
|
||||
})
|
||||
|
||||
asyncTest("should submit all required params", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-url="post-resp.php">abc</a>').appendTo(fx).editable({
|
||||
name: 'username',
|
||||
params: {
|
||||
q: 2
|
||||
},
|
||||
success: function(resp) {
|
||||
equal(resp.dataType, 'json', 'dataType ok');
|
||||
equal(resp.data.pk, 1, 'pk ok');
|
||||
equal(resp.data.name, 'username', 'name ok');
|
||||
equal(resp.data.value, newText, 'value ok');
|
||||
equal(resp.data.q, 2, 'additional params ok');
|
||||
}
|
||||
}),
|
||||
newText = 'cd<e>;"'
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
|
||||
ok(p.find('input[type=text]').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
|
||||
})
|
||||
|
||||
asyncTest("should show emptytext if entered text is empty", function () {
|
||||
var emptytext = 'blabla',
|
||||
e = $('<a href="#" data-pk="1" data-url="post.php" data-name="text1" data-emptytext="'+emptytext+'">abc</a>').appendTo(fx).editable(),
|
||||
newText = ' ';
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.find('input').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popover closed')
|
||||
equal(e.data('editable').value, newText, 'value is empty')
|
||||
equal(e.text(), emptytext, 'emptytext shown')
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
asyncTest("should show responseText on response != 200", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-name="text1">abc</a>').appendTo(fx).editable({
|
||||
url: 'error.php'
|
||||
}),
|
||||
newText = 'cde';
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.find('input').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(p.is(':visible'), 'popover visible')
|
||||
ok(p.find('.editable-error-block').length, 'class "error" exists')
|
||||
equal(p.find('.editable-error-block').text(), 'customtext', 'error shown')
|
||||
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed')
|
||||
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
//error callback deprecated in 2.0
|
||||
/*
|
||||
asyncTest("'error' callback on response != 200", function () {
|
||||
var e = $('<a href="#" data-pk="1" data-name="text1">abc</a>').appendTo(fx).editable({
|
||||
url: 'error.php',
|
||||
error: function(xhr) {
|
||||
if(xhr.status == 500) return 'Internal server error';
|
||||
}
|
||||
}),
|
||||
newText = 'cde';
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.find('input').length, 'input exists')
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(p.is(':visible'), 'popover visible')
|
||||
ok(p.find('.error').length, 'class "error" exists')
|
||||
equal(p.find('.editable-error-block').text(), 'Internal server error', 'error shown')
|
||||
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed')
|
||||
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
test("send: 'auto'. if pk = null --> should save new entered text and value, but no ajax", function () {
|
||||
var e = $('<a href="#" data-name="text1">abc</a>').appendTo('#qunit-fixture').editable({
|
||||
send: 'auto'
|
||||
}),
|
||||
newText = 'cde';
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.find('input').length, 'input exists');
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
equal(e.data('editable').value, newText, 'new text saved to value');
|
||||
equal(e.text(), newText, 'new text shown');
|
||||
ok(e.hasClass('editable-unsaved'), 'has class editable-unsaved');
|
||||
});
|
||||
|
||||
test("send = 'never'. if pk defined --> should save new entered text and value, but no ajax", function () {
|
||||
var e = $('<a href="#" data-name="text1">abc</a>').appendTo('#qunit-fixture').editable({
|
||||
pk: 123,
|
||||
send: 'never'
|
||||
}),
|
||||
newText = 'cde';
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.find('input').length, 'input exists');
|
||||
p.find('input').val(newText);
|
||||
p.find('form').submit();
|
||||
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
equal(e.data('editable').value, newText, 'new text saved to value');
|
||||
equal(e.text(), newText, 'new text shown');
|
||||
ok(e.hasClass('editable-unsaved'), 'has class editable-unsaved');
|
||||
});
|
||||
|
||||
test("if name not defined --> should be taken from id", function () {
|
||||
delete $.fn.editable.defaults.name;
|
||||
var e = $('<a href="#" id="cde">abc</a>').appendTo('#qunit-fixture').editable();
|
||||
equal(e.data('editable').options.name, 'cde', 'name is taken from id');
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user