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
453
test/unit/select.js
Normal file
453
test/unit/select.js
Normal file
@ -0,0 +1,453 @@
|
||||
$(function () {
|
||||
|
||||
window.groups = {
|
||||
0: 'Guest',
|
||||
1: 'Service',
|
||||
2: 'Customer',
|
||||
3: 'Operator',
|
||||
4: 'Support',
|
||||
5: 'Admin',
|
||||
6: '',
|
||||
'': 'Nothing'
|
||||
};
|
||||
|
||||
window.size = 0;
|
||||
|
||||
for (e in groups) { size++; }
|
||||
|
||||
$.mockjax({
|
||||
url: 'groups.php',
|
||||
responseText: groups
|
||||
});
|
||||
|
||||
$.mockjax({
|
||||
url: 'groups-error.php',
|
||||
status: 500,
|
||||
responseText: 'Internal Server Error'
|
||||
});
|
||||
|
||||
module("select", {
|
||||
setup: function(){
|
||||
sfx = $('#qunit-fixture'),
|
||||
fx = $('#async-fixture');
|
||||
$.fn.editable.defaults.name = 'name1';
|
||||
//clear cache
|
||||
$(document).removeData('groups.php-'+$.fn.editable.defaults.name);
|
||||
}
|
||||
});
|
||||
|
||||
test("popover should contain SELECT even if value & source not defined", function () {
|
||||
var e = $('<a href="#" data-type="select">w</a>').appendTo('#qunit-fixture').editable();
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
ok(p.find('select').length, 'select exists')
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
})
|
||||
|
||||
asyncTest("load options from server", function () {
|
||||
var e = $('<a href="#" data-type="select" data-name="load-srv" data-value="2" data-source="groups.php">customer</a>').appendTo(fx).editable();
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
ok(p.find('.editableform-loading').length, 'loading class exists');
|
||||
ok(p.find('.editableform-loading').is(':visible'), 'loading class is visible');
|
||||
|
||||
setTimeout(function() {
|
||||
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('select').length, 'select exists');
|
||||
equal(p.find('select').find('option').length, size, 'options loaded');
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct') ;
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
})
|
||||
|
||||
test("load options from json", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo('#qunit-fixture').editable({
|
||||
pk: 1,
|
||||
source: groups
|
||||
});
|
||||
|
||||
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('select').length, 'select exists')
|
||||
equal(p.find('select').find('option').length, size, 'options loaded')
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct')
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
});
|
||||
|
||||
test("load options from native array", function () {
|
||||
var arr = ['q', 'w', 'x'],
|
||||
e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo('#qunit-fixture').editable({
|
||||
pk: 1,
|
||||
autotext: true,
|
||||
source: arr
|
||||
});
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible')
|
||||
ok(p.find('select').length, 'select exists')
|
||||
equal(p.find('select').find('option').length, arr.length, 'options loaded')
|
||||
equal(p.find('select').val(), 2, 'selected value correct')
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
})
|
||||
|
||||
test("load options from html (single quotes)", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="M" data-source=\'{"L":"Low", "": "None", "M": "Medium", "H": "High"}\'>customer</a>').appendTo('#qunit-fixture').editable({
|
||||
pk: 1
|
||||
}),
|
||||
size = 4;
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
ok(p.find('select').length, 'select exists');
|
||||
equal(p.find('select').find('option').length, size, 'options loaded');
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct') ;
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
})
|
||||
|
||||
test("load options from html (double quotes)", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="M" data-source="{\'L\':\'Low\', \'\': \'None\', \'M\': \'Medium\', \'H\': \'High\'}">customer</a>').appendTo('#qunit-fixture').editable({
|
||||
pk: 1
|
||||
}),
|
||||
size = 4;
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
ok(p.find('select').length, 'select exists');
|
||||
equal(p.find('select').find('option').length, size, 'options loaded');
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct') ;
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
})
|
||||
|
||||
test("load options from html (json syntax error)", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="M" data-source=\'{L :Low, "": "None", "M": "Medium", "H": "High"}\'>customer</a>').appendTo('#qunit-fixture').editable({
|
||||
pk: 1,
|
||||
sourceError: 'error'
|
||||
}),
|
||||
size = 4;
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
ok(p.find('select').length, 'select exists');
|
||||
equal(p.find('select').find('option').length, 0, 'options not loaded');
|
||||
equal(p.find('.editable-error-block').text(), 'error', 'sourceError message shown');
|
||||
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
})
|
||||
|
||||
|
||||
asyncTest("should show error if options cant be loaded", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="2" data-source="groups-error.php">customer</a>').appendTo(fx).editable();
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
|
||||
setTimeout(function() {
|
||||
ok(p.is(':visible'), 'popover visible')
|
||||
ok(p.find('select:disabled').length, 'select disabled')
|
||||
ok(!p.find('select').find('option').length, 'options not loaded')
|
||||
ok(p.find('button[type=submit]:disabled').length, 'submit-btn disabled')
|
||||
ok(p.find('.editable-error-block').text().length, 'error shown')
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
})
|
||||
|
||||
asyncTest("popover should save new selected value", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo(fx).editable({
|
||||
pk: 1,
|
||||
source: groups
|
||||
}),
|
||||
selected = 3;
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
ok(p.find('select').length, 'select exists');
|
||||
equal(p.find('select').find('option').length, size, 'options loaded');
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct');
|
||||
|
||||
p.find('select').val(selected);
|
||||
p.find('form').submit();
|
||||
ok(p.find('.editableform-loading').is(':visible'), 'loading class is visible');
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popover closed')
|
||||
equal(e.data('editable').value, selected, 'new value saved')
|
||||
equal(e.text(), groups[selected], 'new text shown')
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
asyncTest("if new text is empty --> show emptytext on save", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo(fx).editable({
|
||||
pk: 1,
|
||||
source: groups
|
||||
}),
|
||||
selected = 6;
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible')
|
||||
ok(p.find('select').length, 'select exists')
|
||||
equal(p.find('select').find('option').length, size, 'options loaded')
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct')
|
||||
|
||||
p.find('select').val(selected);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popover closed')
|
||||
equal(e.data('editable').value, selected, 'new value saved')
|
||||
equal(e.text(), e.data('editable').options.emptytext, 'emptytext shown')
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
})
|
||||
|
||||
|
||||
asyncTest("if new value is empty --> show work correct", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="2" data-url="post.php">customer</a>').appendTo(fx).editable({
|
||||
pk: 1,
|
||||
source: groups
|
||||
}),
|
||||
selected = '';
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible')
|
||||
ok(p.find('select').length, 'select exists')
|
||||
equal(p.find('select').find('option').length, size, 'options loaded')
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct')
|
||||
|
||||
p.find('select').val(selected);
|
||||
p.find('form').submit();
|
||||
|
||||
setTimeout(function() {
|
||||
ok(!p.is(':visible'), 'popover closed')
|
||||
equal(e.data('editable').value, selected, 'new value saved')
|
||||
equal(e.text(), groups[selected], 'text shown correctly')
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
asyncTest("cache request for same selects", function () {
|
||||
var e = $('<a href="#" data-type="select" data-pk="1" data-value="2" data-url="post.php" data-source="groups-cache.php">customer</a>').appendTo(fx).editable(),
|
||||
e1 = $('<a href="#" data-type="select" data-pk="1" data-value="2" data-url="post.php" data-source="groups-cache.php">customer</a>').appendTo(fx).editable(),
|
||||
req = 0;
|
||||
|
||||
$.mockjax({
|
||||
url: 'groups-cache.php',
|
||||
response: function() {
|
||||
req++;
|
||||
this.responseText = groups;
|
||||
}
|
||||
});
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
|
||||
setTimeout(function() {
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
equal(p.find('select').find('option').length, size, 'options loaded');
|
||||
equal(req, 1, 'one request performed');
|
||||
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
|
||||
//click second
|
||||
e1.click();
|
||||
p = tip(e1);
|
||||
|
||||
setTimeout(function() {
|
||||
ok(p.is(':visible'), 'popover2 visible');
|
||||
equal(p.find('select').find('option').length, size, 'options loaded');
|
||||
equal(req, 1, 'no extra request, options taken from cache');
|
||||
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
|
||||
e.remove();
|
||||
e1.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
}, timeout);
|
||||
|
||||
});
|
||||
|
||||
asyncTest("cache simultaneous requests", function () {
|
||||
expect(4);
|
||||
var req = 0;
|
||||
$.mockjax({
|
||||
url: 'groups-cache-sim.php',
|
||||
responseTime: 200,
|
||||
response: function() {
|
||||
req++;
|
||||
this.responseText = groups;
|
||||
}
|
||||
});
|
||||
|
||||
var e = $('<a href="#" data-type="select" data-pk="1" data-value="1" data-url="post.php" data-source="groups-cache-sim.php"></a>').appendTo(fx).editable(),
|
||||
e1 = $('<a href="#" data-type="select" data-pk="1" data-value="2" data-url="post.php" data-source="groups-cache-sim.php"></a>').appendTo(fx).editable(),
|
||||
e2 = $('<a href="#" data-type="select" data-pk="1" data-value="3" data-url="post.php" data-source="groups-cache-sim.php"></a>').appendTo(fx).editable();
|
||||
|
||||
setTimeout(function() {
|
||||
|
||||
equal(req, 1, 'one request');
|
||||
equal(e.text(), groups[1], 'text1 correct');
|
||||
equal(e1.text(), groups[2], 'text2 correct');
|
||||
equal(e2.text(), groups[3], 'text3 correct');
|
||||
|
||||
e.remove();
|
||||
e1.remove();
|
||||
e2.remove();
|
||||
start();
|
||||
}, 300);
|
||||
|
||||
});
|
||||
|
||||
asyncTest("cache simultaneous requests (loading error)", function () {
|
||||
expect(4);
|
||||
var req = 0;
|
||||
$.mockjax({
|
||||
url: 'groups-cache-sim-err.php',
|
||||
responseTime: 200,
|
||||
status: 500,
|
||||
response: function() {
|
||||
req++;
|
||||
}
|
||||
});
|
||||
|
||||
var e = $('<a href="#" data-type="select" data-pk="1" data-value="1" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php">35</a>').appendTo(fx).editable(),
|
||||
e1 = $('<a href="#" data-type="select" data-pk="1" data-value="2" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php">35</a>').appendTo(fx).editable(),
|
||||
e2 = $('<a href="#" data-type="select" data-pk="1" data-value="3" data-autotext="always" data-url="post.php" data-source="groups-cache-sim-err.php">6456</a>').appendTo(fx).editable(),
|
||||
errText = $.fn.editableform.types.select.defaults.sourceError;
|
||||
|
||||
setTimeout(function() {
|
||||
|
||||
equal(req, 1, 'one request');
|
||||
equal(e.text(), errText, 'text1 correct');
|
||||
equal(e1.text(), errText, 'text2 correct');
|
||||
equal(e2.text(), errText, 'text3 correct');
|
||||
|
||||
e.remove();
|
||||
e1.remove();
|
||||
e2.remove();
|
||||
start();
|
||||
}, 300);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
asyncTest("autotext: auto", function () {
|
||||
expect(3);
|
||||
|
||||
//auto, text->empty, source->array
|
||||
var e = $('<a href="#" data-type="select" data-value="3"></a>').appendTo(sfx).editable({
|
||||
source: groups,
|
||||
autotext: 'auto'
|
||||
}),
|
||||
//auto, text->not empty, source->array
|
||||
e1 = $('<a href="#" data-type="select" data-value="3">blabla</a>').appendTo(sfx).editable({
|
||||
source: groups,
|
||||
autotext: 'auto'
|
||||
}),
|
||||
//auto, text->empty, source->url
|
||||
e2 = $('<a href="#" data-type="select" data-value="3" data-source="groups.php"></a>').appendTo(fx).editable({
|
||||
autotext: 'auto'
|
||||
});
|
||||
|
||||
equal(e.text(), groups[3], 'text set ok');
|
||||
equal(e1.text(), 'blabla', 'text1 not changed');
|
||||
|
||||
setTimeout(function() {
|
||||
equal(e2.text(), groups[3], 'text2 set ok');
|
||||
e2.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
asyncTest("autotext: always (source = url)", function () {
|
||||
expect(1);
|
||||
var e = $('<a href="#" data-type="select" data-value="3" data-source="groups.php">blabla</a>').appendTo(fx).editable({
|
||||
autotext: 'always'
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
equal(e.text(), groups[3], 'text setup ok');
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
test("autotext: never", function () {
|
||||
var e = $('<a href="#" data-type="select" data-value="3"></a>').appendTo(sfx).editable({
|
||||
source: groups,
|
||||
autotext: 'never'
|
||||
});
|
||||
|
||||
equal(e.text(), e.data('editable').options.emptytext, 'text set to emptytext');
|
||||
});
|
||||
|
||||
asyncTest("test prepend option (sync & async)", function () {
|
||||
//sync
|
||||
var e = $('<a href="#" data-type="select" data-name="prepend-test-sync" data-value="" data-url="post.php">customer</a>').appendTo('#qunit-fixture').editable({
|
||||
pk: 1,
|
||||
source: {q: 'qq', w: 'ww'},
|
||||
prepend: 'empty'
|
||||
});
|
||||
|
||||
e.click()
|
||||
var p = tip(e);
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
equal(p.find('select').find('option').length, 3, 'options prepended (sync)');
|
||||
equal(p.find('select').val(), '', 'selected value correct');
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
|
||||
//async
|
||||
e = $('<a href="#" data-type="select" data-name="prepend-test-async" data-value="r" data-url="post.php">customer</a>').appendTo(fx).editable({
|
||||
pk: 1,
|
||||
source: 'groups.php',
|
||||
prepend: {r: 'abc'}
|
||||
});
|
||||
|
||||
e.click()
|
||||
p = tip(e);
|
||||
|
||||
setTimeout(function() {
|
||||
ok(p.is(':visible'), 'popover visible');
|
||||
equal(p.find('select').find('option').length, size+1, 'options prepended (async)');
|
||||
equal(p.find('select').val(), 'r', 'selected value correct');
|
||||
p.find('button[type=button]').click();
|
||||
ok(!p.is(':visible'), 'popover was removed');
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
|
||||
});
|
Reference in New Issue
Block a user