1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-10 10:26:38 +02:00

Started QUnit tests

This commit is contained in:
Max Guglielmi 2015-05-10 21:12:31 +10:00
parent c995091db4
commit a2e5589b49
25 changed files with 311 additions and 9553 deletions

View file

@ -6,6 +6,20 @@ module.exports = function (grunt) {
grunt.initConfig({
jshint: {
src: [
'Gruntfile.js',
'src-es6/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
qunit: {
files: ['test/**/*.html']
},
"webpack-dev-server": {
options: {
webpack: webpack.dev,
@ -21,36 +35,36 @@ module.exports = function (grunt) {
},
webpack: {
"dev": {
entry: __dirname + '/src-es6/tablefilter.js',
// entry: {
// tablefilter: __dirname + '/src-es6/tablefilter.js',
// colsVisibility: __dirname +
// '/src-es6/extensions/colsVisibility/colsVisibility.js'
// },
output: {
publicPath: "/src/",
path: __dirname + "/src",
filename: "tablefilter.js",
chunkFilename: "[name].js",
libraryTarget: 'umd'
},
resolve: {
extensions: ['', '.js']
},
module: {
loaders: [{
test: path.join(__dirname, 'src-es6'),
exclude: /node_modules/,
query: {
compact: false
},
loader: 'babel-loader'
}]
},
devtool: "sourcemap",
debug: true
},
// "dev": {
// entry: __dirname + '/src-es6/tablefilter.js',
// // entry: {
// // tablefilter: __dirname + '/src-es6/tablefilter.js',
// // colsVisibility: __dirname +
// // '/src-es6/extensions/colsVisibility/colsVisibility.js'
// // },
// output: {
// publicPath: "/src/",
// path: __dirname + "/src",
// filename: "tablefilter.js",
// chunkFilename: "[name].js",
// libraryTarget: 'umd'
// },
// resolve: {
// extensions: ['', '.js']
// },
// module: {
// loaders: [{
// test: path.join(__dirname, 'src-es6'),
// exclude: /node_modules/,
// query: {
// compact: false
// },
// loader: 'babel-loader'
// }]
// },
// devtool: "sourcemap",
// debug: true
// },
"build": {
entry: __dirname + '/src-es6/tablefilter.js',
// entry: {
@ -68,9 +82,10 @@ module.exports = function (grunt) {
resolve: {
extensions: ['', '.js'],
alias: {
sortabletable: "../../../libs/sortabletable.js",
adapterSortabletable:
'./extensions/sortabletable/adapterSortabletable'
sortabletable: "../../../libs/sortabletable.js"
// ,
// adapterSortabletable:
// './extensions/sortabletable/adapterSortabletable'
}
},
// externals: {
@ -93,13 +108,10 @@ module.exports = function (grunt) {
// "NODE_ENV": JSON.stringify("production")
// }
// }),
// new webpack.optimize.CommonsChunkPlugin(
// 'main', 1, false),
// new webpack.IgnorePlugin(/adapterSortabletable$/),
// new webpack.optimize.CommonsChunkPlugin(
// "commons.js",
// ["1", "2"]),
new webpack.optimize.DedupePlugin()
new webpack.optimize.DedupePlugin(),
new webpack.optimize.MinChunkSizePlugin(
{minChunkSize: 10000})
// ,
// new webpack.optimize.UglifyJsPlugin()
]
@ -108,6 +120,8 @@ module.exports = function (grunt) {
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-webpack');
// The development server (the recommended option for development)
@ -120,6 +134,9 @@ module.exports = function (grunt) {
grunt.registerTask("dev", ["webpack:dev"/*, "watch:app"*/]);
// Production build
grunt.registerTask("build", ["webpack:build"]);
grunt.registerTask("build", ['jshint', "webpack:build"]);
// Tests
grunt.registerTask('test', ['qunit']);
};

1184
dist/1.js vendored

File diff suppressed because one or more lines are too long

7991
dist/tablefilter.js vendored

File diff suppressed because one or more lines are too long

View file

@ -111,8 +111,7 @@
},
extensions: [{
/*** Columns Visibility Manager extension load ***/
name: 'ColsVisibility',
src: 'extensions/colsVisibility/colsVisibility.js',
name: 'colsVisibility',
description: 'Columns visibility manager',/*
initialize: function(o){o.SetColsVisibility();}*/
// manager: true,

View file

@ -5,6 +5,8 @@
"babel-core": "^5.1.13",
"babel-loader": "^5.0.0",
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.11.2",
"grunt-contrib-qunit": "^0.7.0",
"grunt-webpack": "^1.0.8",
"script-loader": "^0.6.1",
"webpack": "^1.8.10",

View file

@ -129,8 +129,6 @@ export class ColsVisibility{
f.name+'Style', this.path + this.stylesheet, null, 'link');
this.tf = tf;
this.init();
}
toggle(evt){

View file

@ -1143,8 +1143,8 @@ export class TableFilter{
/* Loads extensions */
if(this.hasExtensions){
// this.loadExtensions();
this.registerExtensions();
// this.initExtensions();
// this.registerExtensions();
this.initExtensions();
}
if(this.onFiltersLoaded){
@ -1240,11 +1240,8 @@ export class TableFilter{
}
}
registerExtensions(){
initExtensions(){
var exts = this.extensions;
if(exts.length === 0){
return;
}
for(var i=0; i<exts.length; i++){
var ext = exts[i];
@ -1255,14 +1252,19 @@ export class TableFilter{
}
loadExtension(ext){
if(!ext || !ext.name || !ext.src){
if(!ext || !ext.name){
return;
}
var modulePath = ext.src.replace('.js', '');
require(['./'+modulePath], (m)=> {
var name = ext.name;
var path = ext.path || './extensions/{}/{}'
.replace(new RegExp('{}', 'g'), name);
// var modulePath = ext.src.replace('.js', '');
require([path], (m)=> {
// require(['./'+modulePath], (m)=> {
var key = Object.keys(m)[0];
this.ExtRegistry[key] = new m[key](this, ext);
this.ExtRegistry[key] = new m[key](this, ext).init();
});
}
@ -1533,10 +1535,15 @@ export class TableFilter{
=====================================================*/
setSort(){
require(['adapterSortabletable'], (m)=> {
var adapterSortabletable = new m.AdapterSortableTable(this);
this.ExtRegistry.sort = adapterSortabletable;
adapterSortabletable.init();
// require(['adapterSortabletable'], (m)=> {
// var adapterSortabletable = new m.AdapterSortableTable(this);
// this.ExtRegistry.sort = adapterSortabletable;
// adapterSortabletable.init();
// });
this.loadExtension({
name: 'adapterSortabletable',
path: './extensions/sortabletable/adapterSortabletable.js'
});
}
setOldSort(){

View file

@ -6,11 +6,6 @@
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
@ -74,7 +69,8 @@
</tbody>
</table>
<script data-main="test-alternate-rows" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test-alternate-rows.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,19 +1,10 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
var tf = new TableFilter('demo', {
alternate_rows: true
});
tf.init();
var dom = require('dom'),
AlternateRows = require('modules/alternateRows').AlternateRows;
var tf = new TableFilter('demo', {
alternate_rows: true
});
tf.init();
module('Sanity checks');
test('AlternateRows component', function() {
deepEqual(tf.Cpt.alternateRows instanceof AlternateRows, true, 'AlternateRows constructor');
notEqual(tf.Cpt.alternateRows, null, 'AlternateRows instanciated');
});
});
module('Sanity checks');
test('AlternateRows component', function() {
deepEqual(typeof tf.Cpt.alternateRows, 'object', 'AlternateRows instanciated');
});

View file

@ -6,11 +6,6 @@
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
@ -74,7 +69,8 @@
</tbody>
</table>
<script data-main="test-checklist" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test-checklist.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,34 +1,27 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
var CheckList = require('modules/checkList').CheckList,
types = require('types').Types,
dom = require('dom').Dom;
var tf = new TableFilter('demo', {
col_3: 'checklist',
fill_slc_on_demand: false
});
tf.init();
var checkList = tf.Cpt.checkList;
module('Sanity checks');
test('CheckList component', function() {
deepEqual(checkList instanceof CheckList, true, 'CheckList type');
notEqual(checkList, null, 'CheckList instanciated');
deepEqual(types.isArray(checkList.checkListDiv), true, 'Type of checkListDiv property');
});
module('UI elements');
test('CheckList UI elements', function() {
var flt = dom.id(tf.fltIds[3]);
notEqual(flt, null, 'CheckList UL element');
deepEqual(flt.firstChild.nodeName, 'LI', 'First CheckList option element name');
});
test('TableFilter removed', function() {
tf.remove();
deepEqual(dom.id(tf.fltIds[3]), null, 'CheckList UL element');
});
var id = function (id){ return document.getElementById(id); };
var tf = new TableFilter('demo', {
col_3: 'checklist',
fill_slc_on_demand: false
});
tf.init();
var checkList = tf.Cpt.checkList;
module('Sanity checks');
test('CheckList component', function() {
deepEqual(typeof checkList, 'object', 'CheckList instanciated');
deepEqual(checkList.checkListDiv instanceof Array, true, 'Type of checkListDiv property');
});
module('UI elements');
test('CheckList UI elements', function() {
var flt = id(tf.fltIds[3]);
notEqual(flt, null, 'CheckList UL element');
deepEqual(flt.firstChild.nodeName, 'LI', 'First CheckList option element name');
});
test('TableFilter removed', function() {
tf.remove();
deepEqual(id(tf.fltIds[3]), null, 'CheckList UL element');
});

View file

@ -6,11 +6,6 @@
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
@ -74,7 +69,8 @@
</tbody>
</table>
<script data-main="test-clear-button" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test-clear-button.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,47 +1,38 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
var ClearButton = require('modules/clearButton').ClearButton,
types = require('types').Types,
dom = require('dom').Dom;
var tf = new TableFilter('demo', {
btn_reset: true
});
tf.init();
var clearButton = tf.Cpt.clearButton;
module('Sanity checks');
test('Clear button component', function() {
deepEqual(clearButton instanceof ClearButton, true, 'ClearButton type');
notEqual(clearButton, null, 'ClearButton instanciated');
notEqual(clearButton.btnResetEl, null, 'btnResetEl property');
});
module('UI elements');
test('ClearButton UI elements', function() {
var container = clearButton.btnResetEl;
deepEqual(container.nodeName, 'INPUT', 'Clear button container');
deepEqual(container.parentNode.id, clearButton.prfxResetSpan+tf.id, 'Container id');
});
module('Destroy and re-init');
test('Remove UI', function() {
clearButton.destroy();
var btnResetEl = tf.Cpt.clearButton.btnResetEl;
deepEqual(btnResetEl, null, 'Clear button is removed');
});
test('Re-set UI', function() {
tf.enableIcons = false;
tf.Cpt.clearButton.btnResetHtml = null;
tf.Cpt.clearButton.btnResetText = 'Clear';
tf.Cpt.clearButton.init();
var btnResetEl = tf.Cpt.clearButton.btnResetEl;
deepEqual(btnResetEl.nodeName, 'A', 'Clear button tag changed');
deepEqual(dom.getText(btnResetEl), 'Clear', 'Clear button text');
});
var tf = new TableFilter('demo', {
btn_reset: true
});
tf.init();
var clearButton = tf.Cpt.clearButton;
module('Sanity checks');
test('Clear button component', function() {
deepEqual(typeof clearButton, 'object', 'ClearButton instanciated');
notEqual(clearButton.btnResetEl, null, 'btnResetEl property');
});
module('UI elements');
test('ClearButton UI elements', function() {
var container = clearButton.btnResetEl;
deepEqual(container.nodeName, 'INPUT', 'Clear button container');
deepEqual(container.parentNode.id, clearButton.prfxResetSpan+tf.id, 'Container id');
});
module('Destroy and re-init');
test('Remove UI', function() {
clearButton.destroy();
var btnResetEl = tf.Cpt.clearButton.btnResetEl;
deepEqual(btnResetEl, null, 'Clear button is removed');
});
test('Re-set UI', function() {
tf.enableIcons = false;
tf.Cpt.clearButton.btnResetHtml = null;
tf.Cpt.clearButton.btnResetText = 'Clear';
tf.Cpt.clearButton.init();
var btnResetEl = tf.Cpt.clearButton.btnResetEl;
deepEqual(btnResetEl.nodeName, 'A', 'Clear button tag changed');
deepEqual(btnResetEl.innerText, 'Clear', 'Clear button text');
});

View file

@ -6,11 +6,6 @@
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
@ -83,7 +78,8 @@
</tbody>
</table>
<script data-main="test-col-ops" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test-col-ops.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,33 +1,25 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
var id = function (id){ return document.getElementById(id); };
var table = document.getElementById('demo');
var totRowIndex = table.getElementsByTagName('tr').length;
var dom = require('dom').Dom,
ColOps = require('modules/colOps').ColOps;
var tf = new TableFilter('demo', {
rows_always_visible: [totRowIndex],
col_operation: {
id: ['sum1', 'sum2'],
col: [2, 3],
operation: ['sum', 'mean'],
write_method: ['innerhtml', 'innerhtml'],
exclude_row: [totRowIndex],
decimal_precision: [0, 2],
tot_row_index: [totRowIndex, totRowIndex]
}
});
tf.init();
var table = document.getElementById('demo');
var totRowIndex = table.getElementsByTagName('tr').length;
var tf = new TableFilter('demo', {
rows_always_visible: [totRowIndex],
col_operation: {
id: ['sum1', 'sum2'],
col: [2, 3],
operation: ['sum', 'mean'],
write_method: ['innerhtml', 'innerhtml'],
exclude_row: [totRowIndex],
decimal_precision: [0, 2],
tot_row_index: [totRowIndex, totRowIndex]
}
});
tf.init();
module('Sanity checks');
test('Column Operations component', function() {
deepEqual(tf.Cpt.colOps instanceof ColOps, true, 'ColOps constructor');
notEqual(tf.Cpt.colOps, null, 'ColOps instanciated');
equal(dom.id('sum1').innerHTML, 9911, 'Sum result');
equal(dom.id('sum2').innerHTML, 1.69, 'Mean result');
});
});
module('Sanity checks');
test('Column Operations component', function() {
deepEqual(typeof tf.Cpt.colOps, 'object', 'ColOps instanciated');
equal(id('sum1').innerHTML, 9911, 'Sum result');
equal(id('sum2').innerHTML, 1.69, 'Mean result');
});

View file

@ -6,11 +6,6 @@
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
@ -74,7 +69,8 @@
</tbody>
</table>
<script data-main="test-dropdown" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test-dropdown.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,38 +1,29 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
var Dropdown = require('modules/dropdown').Dropdown,
types = require('types').Types,
dom = require('dom').Dom;
var tf = new TableFilter('demo', {
col_2: 'multiple',
col_3: 'select',
fill_slc_on_demand: false
});
tf.init();
var dropdown = tf.Cpt.dropdown;
module('Sanity checks');
test('Drop-down component', function() {
deepEqual(dropdown instanceof Dropdown, true, 'DropDown type');
notEqual(dropdown, null, 'DropDown instanciated');
deepEqual(types.isArray(dropdown.opts), true, 'Type of opts property');
});
module('UI elements');
test('Drop-down UI elements', function() {
var flt1 = dom.id(tf.fltIds[3]);
var flt2 = dom.id(tf.fltIds[2]);
notEqual(flt1, null, 'DropDown SELECT element exists');
notEqual(flt2, null, 'DropDown SELECT element exists');
deepEqual(flt2.hasAttribute('multiple'), true, 'Multiple select exists');
});
test('TableFilter removed', function() {
tf.remove();
deepEqual(dom.id(tf.fltIds[3]), null, 'Filter is removed');
});
var id = function (id){ return document.getElementById(id); };
var tf = new TableFilter('demo', {
col_2: 'multiple',
col_3: 'select',
fill_slc_on_demand: false
});
tf.init();
var dropdown = tf.Cpt.dropdown;
module('Sanity checks');
test('Drop-down component', function() {
deepEqual(typeof dropdown, 'object', 'DropDown instanciated');
deepEqual(dropdown.opts instanceof Array, true, 'Type of opts property');
});
module('UI elements');
test('Drop-down UI elements', function() {
var flt1 = id(tf.fltIds[3]);
var flt2 = id(tf.fltIds[2]);
notEqual(flt1, null, 'DropDown SELECT element exists');
notEqual(flt2, null, 'DropDown SELECT element exists');
deepEqual(flt2.hasAttribute('multiple'), true, 'Multiple select exists');
});
test('TableFilter removed', function() {
tf.remove();
deepEqual(id(tf.fltIds[3]), null, 'Filter is removed');
});

View file

@ -6,11 +6,6 @@
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
@ -7732,7 +7727,8 @@
</tbody>
</table>
<script data-main="test-grid-layout" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test-grid-layout.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,32 +1,24 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
var GridLayout = require('modules/gridLayout').GridLayout;
var tf = new TableFilter('demo', {
grid_layout: true,
sort: false
});
tf.init();
var gridLayout = tf.Cpt.gridLayout;
module('Sanity checks');
test('GridLayout component', function() {
deepEqual(gridLayout instanceof GridLayout, true, 'GridLayout type');
notEqual(gridLayout, null, 'GridLayout instanciated');
notEqual(gridLayout.tblMainCont, null, 'GridLayout main container element');
notEqual(gridLayout.tblCont, null, 'GridLayout main HTML table container element');
notEqual(gridLayout.headTblCont, null, 'GridLayout headers container element');
notEqual(gridLayout.headTbl, null, 'GridLayout headers HTML table');
});
test('Destroy GridLayout component', function() {
gridLayout.destroy();
deepEqual(gridLayout.tblMainCont, null, 'Main container element removed');
deepEqual(gridLayout.tblCont, null, 'Main HTML table container element removed');
deepEqual(gridLayout.headTblCont, null, 'Headers container element removed');
deepEqual(gridLayout.headTbl, null, 'Headers HTML table element removed');
});
var tf = new TableFilter('demo', {
grid_layout: true,
sort: false
});
tf.init();
var gridLayout = tf.Cpt.gridLayout;
module('Sanity checks');
test('GridLayout component', function() {
deepEqual(typeof gridLayout, 'object', 'GridLayout instanciated');
notEqual(gridLayout.tblMainCont, null, 'GridLayout main container element');
notEqual(gridLayout.tblCont, null, 'GridLayout main HTML table container element');
notEqual(gridLayout.headTblCont, null, 'GridLayout headers container element');
notEqual(gridLayout.headTbl, null, 'GridLayout headers HTML table');
});
test('Destroy GridLayout component', function() {
gridLayout.destroy();
deepEqual(gridLayout.tblMainCont, null, 'Main container element removed');
deepEqual(gridLayout.tblCont, null, 'Main HTML table container element removed');
deepEqual(gridLayout.headTblCont, null, 'Headers container element removed');
deepEqual(gridLayout.headTbl, null, 'Headers HTML table element removed');
});

View file

@ -6,11 +6,6 @@
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
@ -74,7 +69,8 @@
</tbody>
</table>
<script data-main="test-help" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test-help.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,56 +1,45 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
var Help = require('modules/help').Help,
types = require('types').Types,
dom = require('dom').Dom;
var tf = new TableFilter('demo', {
help_instructions: true
});
tf.init();
var help = tf.Cpt.help;
module('Sanity checks');
test('Clear button component', function() {
deepEqual(help instanceof Help, true, 'Help type');
notEqual(help, null, 'Help instanciated');
notEqual(help.helpInstrBtnEl, null, 'helpInstrBtnEl property');
});
module('UI elements');
test('Help UI elements', function() {
var container = help.helpInstrContEl,
helpBtn = help.helpInstrBtnEl;
deepEqual(container.nodeName, 'DIV', 'Help container');
deepEqual(helpBtn.nodeName, 'SPAN', 'Help button');
});
module('Destroy and re-init');
test('Remove UI', function() {
help.destroy();
var container = help.helpInstrContEl,
helpBtn = help.helpInstrBtnEl;
deepEqual(container, null, 'Help container removed');
deepEqual(helpBtn, null, 'Help button removed');
});
test('Re-set UI', function() {
tf.Cpt.help.destroy();
tf.Cpt.help.helpInstrBtnText = '→Help←';
tf.Cpt.help.helpInstrText = 'Hello world!';
tf.Cpt.help.init();
var container = help.helpInstrContEl,
helpBtn = help.helpInstrBtnEl;
notEqual(
dom.getText(container).indexOf('Hello world!'),
-1,
'Help pop-up text'
);
notEqual(
dom.getText(helpBtn).indexOf('→Help←'), -1, 'Help button text');
});
var tf = new TableFilter('demo', {
help_instructions: true
});
tf.init();
var help = tf.Cpt.help;
module('Sanity checks');
test('Clear button component', function() {
deepEqual(typeof help, 'object', 'Help instanciated');
notEqual(help.helpInstrBtnEl, null, 'helpInstrBtnEl property');
});
module('UI elements');
test('Help UI elements', function() {
var container = help.helpInstrContEl,
helpBtn = help.helpInstrBtnEl;
deepEqual(container.nodeName, 'DIV', 'Help container');
deepEqual(helpBtn.nodeName, 'SPAN', 'Help button');
});
module('Destroy and re-init');
test('Remove UI', function() {
help.destroy();
var container = help.helpInstrContEl,
helpBtn = help.helpInstrBtnEl;
deepEqual(container, null, 'Help container removed');
deepEqual(helpBtn, null, 'Help button removed');
});
test('Re-set UI', function() {
tf.Cpt.help.destroy();
tf.Cpt.help.helpInstrBtnText = '→Help←';
tf.Cpt.help.helpInstrText = 'Hello world!';
tf.Cpt.help.init();
var container = help.helpInstrContEl,
helpBtn = help.helpInstrBtnEl;
notEqual(
container.innerHTML.indexOf('Hello world!'),
-1,
'Help pop-up text'
);
notEqual(helpBtn.innerHTML.indexOf('→Help←'), -1, 'Help button text');
});

View file

@ -6,11 +6,6 @@
<link rel="stylesheet" href="libs/qunit/qunit.css">
<link rel="stylesheet" href="../dist/filtergrid.css">
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
</script>
</head>
<body>
<table id="demo" cellpadding="0" cellspacing="0">
@ -74,7 +69,8 @@
</tbody>
</table>
<script data-main="test-highlight-keywords" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test-highlight-keywords.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,31 +1,23 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
var tf = new TableFilter('demo', {
highlight_keywords: true
});
tf.init();
var dom = require('dom').Dom,
Highlight = require('modules/highlightKeywords').HighlightKeyword;
var highlightKeyword = tf.Cpt.highlightKeyword;
module('Sanity checks');
test('HighlightKeyword component', function() {
deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
deepEqual(highlightKeyword.highlightedNodes instanceof Array, true, 'Property check');
});
var tf = new TableFilter('demo', {
highlight_keywords: true
});
tf.init();
test('Highlighted keywords', function() {
tf.setFilterValue(1, 'Perth');
tf.setFilterValue(3, '3.1');
tf._filter();
deepEqual(highlightKeyword.highlightedNodes.length, 2, 'Number of highlighted words');
var highlightKeyword = tf.Cpt.highlightKeyword;
module('Sanity checks');
test('HighlightKeyword component', function() {
deepEqual(highlightKeyword instanceof Highlight, true, 'Instance of expected class type');
notEqual(highlightKeyword, null, 'Instanciated');
deepEqual(highlightKeyword.highlightedNodes instanceof Array, true, 'Property check');
});
test('Highlighted keywords', function() {
tf.setFilterValue(1, 'Perth');
tf.setFilterValue(3, '3.1');
tf._filter();
deepEqual(highlightKeyword.highlightedNodes.length, 2, 'Number of highlighted words');
tf._clearFilters();
tf._filter();
deepEqual(highlightKeyword.highlightedNodes.length, 0, 'Number of highlighted words');
});
});
tf._clearFilters();
tf._filter();
deepEqual(highlightKeyword.highlightedNodes.length, 0, 'Number of highlighted words');
});

View file

@ -9,8 +9,8 @@
<script src="libs/qunit/qunit.js"></script>
<script>
// Defer Qunit so RequireJS can work its magic and resolve all modules.
QUnit.config.autostart = false;
QUnit.config.autoload = false;
// QUnit.config.autostart = false;
// QUnit.config.autoload = false;
</script>
</head>
<body>
@ -75,7 +75,8 @@
</tbody>
</table>
<script data-main="test" src="../libs/requirejs/require.js"></script>
<script src="../dist/tablefilter.js"></script>
<script src="test.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>

View file

@ -1,6 +1,4 @@
requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
QUnit.start();
(function(win, TableFilter) {
var tf = new TableFilter('demo');
tf.init();
@ -18,4 +16,4 @@ requirejs(['test-config', '../src/tablefilter'], function(config, TableFilter){
equal(tf.getFilterElement(0).nodeName, 'INPUT', 'Filter DOM element');
});
});
})(window, TableFilter);