1
0
mirror of https://github.com/DataTables/DataTables.git synced 2024-12-05 17:24:10 +01:00
DataTables/media/unit_testing/tests_onhold/2_js/6872-default-content-missing-props.js

285 lines
5.4 KiB
JavaScript
Raw Normal View History

// DATA_TEMPLATE: empty_table
oTest.fnStart( "6872 - mDataProp and sDefaultContent for deep objects" );
$(document).ready( function () {
var test = false;
$.fn.dataTable.ext.sErrMode = "throw";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Shallow properties
*/
$('#example').dataTable( {
"aaData": [
{
"a": "a",
"b": "b",
"c": "c",
"d": "d",
"e": "e"
}
],
"aoColumns": [
{ "mDataProp": "a" },
{ "mDataProp": "b" },
{ "mDataProp": "c" },
{ "mDataProp": "d" },
{ "mDataProp": "e" }
]
} );
oTest.fnTest(
"Basic initialisation of objects works",
null,
function () { return $('#example tbody td:eq(0)').html() === "a"; }
);
oTest.fnTest(
"Error when property missing (no default content)",
function () {
oSession.fnRestore();
test = false;
try {
$('#example').dataTable( {
"aaData": [
{
"a": "a",
"b": "b",
"d": "d",
"e": "e"
}
],
"aoColumns": [
{ "mDataProp": "a" },
{ "mDataProp": "b" },
{ "mDataProp": "c" },
{ "mDataProp": "d" },
{ "mDataProp": "e" }
]
} );
} catch (e) {
test = true;
}
},
function () { return test; }
);
oTest.fnTest(
"Default content used for missing prop and no error",
function () {
oSession.fnRestore();
$('#example').dataTable( {
"aaData": [
{
"a": "a",
"b": "b",
"d": "d",
"e": "e"
}
],
"aoColumns": [
{ "mDataProp": "a" },
{ "mDataProp": "b" },
{ "mDataProp": "c", "sDefaultContent": "test" },
{ "mDataProp": "d" },
{ "mDataProp": "e" }
]
} );
},
function () { return $('#example tbody td:eq(2)').html() === "test"; }
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Deep properties with a single object
*/
oTest.fnTest(
"Basic test with deep properties",
function () {
oSession.fnRestore();
$('#example').dataTable( {
"aaData": [
{
"z": {
"a": "a",
"b": "b",
"c": "c",
"d": "d",
"e": "e"
}
}
],
"aoColumns": [
{ "mDataProp": "z.a" },
{ "mDataProp": "z.b" },
{ "mDataProp": "z.c" },
{ "mDataProp": "z.d" },
{ "mDataProp": "z.e" }
]
} );
},
function () { return $('#example tbody td:eq(0)').html() === "a"; }
);
oTest.fnTest(
"Error when property missing on deep get (no default content)",
function () {
oSession.fnRestore();
test = false;
try {
$('#example').dataTable( {
"aaData": [
{
"z": {
"a": "a",
"b": "b",
"c": "c",
"e": "e"
}
}
],
"aoColumns": [
{ "mDataProp": "z.a" },
{ "mDataProp": "z.b" },
{ "mDataProp": "z.c" },
{ "mDataProp": "z.d" },
{ "mDataProp": "z.e" }
]
} );
} catch (e) {
test = true;
}
},
function () { return test; }
);
oTest.fnTest(
"Default content used for missing prop on deep get and no error",
function () {
oSession.fnRestore();
$('#example').dataTable( {
"aaData": [
{
"z": {
"a": "a",
"b": "b",
"c": "c",
"e": "e"
}
}
],
"aoColumns": [
{ "mDataProp": "z.a" },
{ "mDataProp": "z.b" },
{ "mDataProp": "z.c" },
{ "mDataProp": "z.d", "sDefaultContent": "test" },
{ "mDataProp": "z.e" }
]
} );
},
function () { return $('#example tbody td:eq(3)').html() === "test"; }
);
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Deep properties with individual objects
*/
oTest.fnTest(
"Basic test with deep individual properties",
function () {
oSession.fnRestore();
$('#example').dataTable( {
"aaData": [
{
"m": { "a": "a" },
"n": { "b": "b" },
"o": { "c": "c" },
"p": { "d": "d" },
"q": { "e": "e" }
}
],
"aoColumns": [
{ "mDataProp": "m.a" },
{ "mDataProp": "n.b" },
{ "mDataProp": "o.c" },
{ "mDataProp": "p.d" },
{ "mDataProp": "q.e" }
]
} );
},
function () { return $('#example tbody td:eq(0)').html() === "a"; }
);
oTest.fnTest(
"Error when property missing on deep individual get (no default content)",
function () {
oSession.fnRestore();
test = false;
try {
$('#example').dataTable( {
"aaData": [
{
"m": { "a": "a" },
"n": { "b": "b" },
"p": { "d": "d" },
"q": { "e": "e" }
}
],
"aoColumns": [
{ "mDataProp": "m.a" },
{ "mDataProp": "n.b" },
{ "mDataProp": "o.c" },
{ "mDataProp": "p.d" },
{ "mDataProp": "q.e" }
]
} );
} catch (e) {
test = true;
}
},
function () { return test; }
);
oTest.fnTest(
"Default content used for missing prop on deep individual get and no error",
function () {
oSession.fnRestore();
$('#example').dataTable( {
"aaData": [
{
"m": { "a": "a" },
"n": { "b": "b" },
"p": { "d": "d" },
"q": { "e": "e" }
}
],
"aoColumns": [
{ "mDataProp": "m.a" },
{ "mDataProp": "n.b" },
{ "mDataProp": "o.c", "sDefaultContent": "test" },
{ "mDataProp": "p.d" },
{ "mDataProp": "q.e" }
]
} );
},
function () { return $('#example tbody td:eq(2)').html() === "test"; }
);
oTest.fnComplete();
} );