1/* eslint-env qunit */ 2 3window.tablelayout = window.tablelayout || {}; 4 5(function (tablelayout) { 6 'use strict'; 7 8 QUnit.module( 'Tests for tablelayout.freezeTableRows' ); 9 QUnit.test('fix 1 row and have 2 visible', function(assert) { 10 var $fixture = jQuery( '#qunit-fixture').find('#smallTable' ); 11 var $table = $fixture.find( 'table' ); 12 var expected_html = '<div class="plugin_tablelayout_placeholder" data-tablelayout="0"></div> <div class="table sectionedit8"><div style="width: 203px;"><table class="inline tablelayout_head"> ' + 13 '<thead> ' + 14 '<tr class="row0"> ' + 15 ' <th class="col0 leftalign"> Column 1 </th><th class="col1 leftalign"> Column 2 </th> ' + 16 '</tr> ' + 17 '</thead> </table></div>' + 18 '<div style="overflow-y: scroll; height: 42px; width: 203px;"><table class="inline tablelayout_body"> ' + 19 '<thead> ' + 20 '<tr class="row1"> ' + 21 ' <th class="col0 leftalign"> 2 </th><th class="col1 leftalign"> T </th> ' + 22 '</tr> ' + 23 '</thead> ' + 24 '<tbody><tr class="row2"> ' + 25 ' <td class="col0 leftalign"> 3 </td><td class="col1 leftalign"> v </td> ' + 26 '</tr> ' + 27 '<tr class="row3"> ' + 28 ' <th class="col0 leftalign"> 4 </th><th class="col1 leftalign"> A </th> ' + 29 '</tr> ' + 30 '<tr class="row4"> ' + 31 ' <td class="col0 leftalign"> 5 </td><td class="col1 leftalign"> b </td> ' + 32 '</tr> ' + 33 '</tbody></table></div></div> <div class="secedit editbutton_table editbutton_2" style="display: block; margin-top: -12px;"></div>'; 34 var rowsFrozen = 1; 35 var rowsVisible = 2; 36 tablelayout.freezeTableRows($table, rowsFrozen, rowsVisible); 37 var actual_html = $fixture.html().replace(/\s\s+/g, ' ').trim(); 38 39 var actual_width = parseInt(actual_html.substr(actual_html.indexOf('width: ')+'width: '.length, '203'.length)); 40 actual_html = actual_html.replace(new RegExp(actual_width+'px','g'), 'px'); 41 var expected_width = parseInt(expected_html.substr(expected_html.indexOf('width: ')+'width: '.length, '203'.length)); 42 expected_html = expected_html.replace(new RegExp(expected_width+'px','g'), 'px'); 43 44 var actual_height = parseInt(actual_html.substr(actual_html.indexOf('height: ')+'height: '.length, '42'.length)); 45 actual_html = actual_html.replace(actual_height+'px', 'px'); 46 var expected_height = parseInt(expected_html.substr(expected_html.indexOf('height: ')+'height: '.length, '42'.length)); 47 expected_html = expected_html.replace(expected_height+'px', 'px'); 48 49 var ALLOWED_VARIANCE = 5; 50 assert.ok(expected_width - ALLOWED_VARIANCE < actual_width && actual_width < expected_width + ALLOWED_VARIANCE, 'expected_width: '+ expected_width + '; actual_width: ' + actual_width); 51 assert.ok(expected_height - ALLOWED_VARIANCE < actual_height && actual_height < expected_height + ALLOWED_VARIANCE, 'expected_height: '+ expected_height + '; actual_height: ' + actual_height); 52 assert.deepEqual(actual_html, expected_html.replace(/\s\s+/g, ' ').trim(), 'html is ok'); 53 }); 54 55}(window.tablelayout)); 56