1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
describe('columns.render option', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
describe('Check the defaults', function() {
dt.html('basic');
it('Default should be null', function() {
expect($.fn.DataTable.defaults.column.mRender).toBe(null);
});
});
describe('Functional tests - special values', function() {
dt.html('basic');
it('undefined', function() {
let data = [['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff']];
let table = $('#example').DataTable({
data: data,
columns: [null, null, null, null, null, { data: null, render: undefined, defaultContent: 'test' }]
});
expect($('tbody tr:eq(0) td:eq(5)').text()).toBe('test');
});
dt.html('basic');
it('null', function() {
let table = $('#example').DataTable({
columns: [{ data: null, render: null, defaultContent: 'test' }, null, null, null, null, null]
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('test');
});
});
describe('Functional tests - integer type', function() {
dt.html('basic');
it('Integer for data source', function() {
let table = $('#example').DataTable({
columns: [{ data: null, render: 2 }, null, null, null, null, null]
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('Edinburgh');
});
dt.html('basic');
it('Integer for data source', function() {
let table = $('#example').DataTable({
columns: [{ render: 2 }, null, null, null, null, null]
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('a');
});
});
describe('Functional tests - string type', function() {
dt.html('empty');
it('Plain string', function() {
let data = [
{
name: { first: 'Aaron', last: 'Aardvark' },
position: 'Architect',
office: 'Atlanta',
age: 99,
start_date: '2018/05/06',
salary: '$40,000'
}
];
let cols = dt.getTestColumns();
cols[0].render = 'first';
$('#example').DataTable({
data: data,
columns: cols
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('Aaron');
});
dt.html('empty');
it('Dotted JS notation (next objects)', function() {
let data = [
{
name: { name_object: { first: 'Aaron', last: 'Aardvark' } },
position: 'Architect',
office: 'Atlanta',
age: 99,
start_date: '2018/05/06',
salary: '$40,000'
}
];
let cols = dt.getTestColumns();
cols[0].render = '.name_object.first';
$('#example').DataTable({
data: data,
columns: cols
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('Aaron');
});
dt.html('empty');
it('Array in the string', function() {
let data = [
{
name: { first: 'Aaron', last: 'Aardvark' },
position: 'Architect',
office: [{ city: 'Atlanta' }, { city: 'Aspen' }],
age: 99,
start_date: '2018/05/06',
salary: '$40,000'
}
];
let cols = dt.getTestColumns();
cols[0].render = 'first';
cols[2].render = '[; ].city';
$('#example').DataTable({
data: data,
columns: cols
});
expect($('tbody tr:eq(0) td:eq(2)').text()).toBe('Atlanta; Aspen');
});
});
describe('Functional tests - object type', function() {
dt.html('empty');
let table;
it('Order and display are correct', function() {
let data = [
{
name: 'Aaron',
name_display: 'Aaron Aardvark',
name_sort: 'Zaron Zardvark',
position: 'Architect',
office: 'Atlanta',
age: 99,
start_date: '2018/05/06',
salary: '$40,000'
},
{
name: 'Bertie',
name_display: 'Bertie Bassett',
name_sort: 'Bertie Bassett',
position: 'Architect',
office: 'Atlanta',
age: 99,
start_date: '2018/05/06',
salary: '$40,000'
}
];
let cols = dt.getTestColumns();
cols[0].data = null;
cols[0].render = {
_: 'name',
display: 'name_display',
sort: 'name_sort'
};
table = $('#example').DataTable({
data: data,
columns: cols
});
expect($('tbody tr:eq(1) td:eq(0)').text()).toBe('Aaron Aardvark');
});
it('Search is correct', function() {
table.search('Aardvark').draw();
expect(table.page.info().recordsDisplay).toBe(0);
});
it('Type is correct', function() {
// TK COLIN
});
});
describe('Functional tests - function type', function() {
dt.html('basic');
let table;
it('Function has the correct args', function() {
let params = false;
let count = 0;
table = $('#example').DataTable({
columns: [
null,
null,
null,
null,
null,
{
render: function() {
count++;
params = arguments;
return arguments[0];
}
}
]
});
expect(count).toBe(171);
expect(params.length).toBe(4);
expect(typeof params[0]).toBe('string');
expect(typeof params[1]).toBe('string');
expect(params[2] instanceof Array).toBe(true);
expect(typeof params[3]).toBe('object');
expect(params[3].row).toBe(56);
expect(params[3].col).toBe(5);
expect(params[3].settings).toBe(table.settings()[0]);
});
dt.html('basic');
it('Test types - setup', function() {
table = $('#example').DataTable({
columns: [
{
render: function(data, type, row, meta) {
if (data !== 'Ashton Cox') {
return data;
}
switch (type) {
case 'filter':
return 'AAA filter Ashton Cox';
case 'display':
return 'AAA display Ashton Cox';
case 'type':
// TK COLIN
return 'AAA type Ashton Cox';
case 'sort':
return 'Ajjj Ashton Cox';
case 'undefined':
return 'AAA undefined Ashton Cox';
default:
return 'AAA default Ashton Cox';
}
}
},
null,
null,
null,
null,
null
]
});
});
it('Test types - display and sort', function() {
expect($('tbody tr:eq(1) td:eq(0)').text()).toBe('AAA display Ashton Cox');
});
it('Test types - filter', function() {
table.search('filter').draw();
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('AAA display Ashton Cox');
});
it('Test types - undefined', function() {
expect(table.cell(':eq(0)', 0, { search: 'applied' }).render('undefined')).toBe('AAA undefined Ashton Cox');
});
it('Test types - original value still available', function() {
expect(table.cell(':eq(0)', 0, { search: 'applied' }).data()).toBe('Ashton Cox');
});
});
describe('Functional tests - two tables', function() {
dt.html('two_tables');
it('Test types - setup', function() {
let table1 = $('#example_one').DataTable({
columnDefs: [
{
targets: 0,
render: function(data, type, row, meta) {
return 'AAA ' + data;
}
}
]
});
let table2 = $('#example_two').DataTable({
columnDefs: [
{
targets: 0,
render: function(data, type, row, meta) {
return 'BBB ' + data;
}
}
]
});
expect($('#example_one tbody tr:eq(1) td:eq(0)').text()).toBe('AAA Angelica Ramos');
expect($('#example_two tbody tr:eq(1) td:eq(0)').text()).toBe('BBB Milan');
});
});
});
|