1 |
|
2 | var tf = new TableFilter('demo', {
|
3 | base_path: '../dist/tablefilter/',
|
4 | highlight_keywords: true
|
5 | });
|
6 | tf.init();
|
7 |
|
8 | var highlightKeyword = tf.feature('highlightKeyword');
|
9 | module('Sanity checks');
|
10 | test('HighlightKeyword component', function() {
|
11 | deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
|
12 | deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
|
13 | });
|
14 |
|
15 | module('Behaviour');
|
16 | test('Highlighted keywords', function() {
|
17 | tf.setFilterValue(1, 'Perth');
|
18 | tf.setFilterValue(3, '3.1');
|
19 | tf.filter();
|
20 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 2,
|
21 | 'Number of applied CSS classes');
|
22 |
|
23 | tf.clearFilters();
|
24 |
|
25 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
|
26 | 'Number of applied CSS classes');
|
27 | });
|
28 |
|
29 |
|
30 | test('Match same term with increasing number of chars', function() {
|
31 | tf.setFilterValue(1, 'Pe');
|
32 | tf.filter();
|
33 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
|
34 | 'Search term matched');
|
35 |
|
36 | tf.setFilterValue(1, 'Per');
|
37 | tf.filter();
|
38 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
|
39 | 'Search term matched');
|
40 |
|
41 | tf.setFilterValue(1, 'Pert');
|
42 | tf.filter();
|
43 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 1,
|
44 | 'Search term matched');
|
45 | });
|
46 |
|
47 | module('Reset feature');
|
48 | test('can destroy and init TableFilter', function() {
|
49 | tf.destroy();
|
50 | tf.init();
|
51 | deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
|
52 | deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
|
53 | });
|
54 |
|
55 | module('Tear-down');
|
56 | test('can destroy TableFilter DOM elements and clean highlighted words',
|
57 | function() {
|
58 | tf.setFilterValue(1, 'Perth');
|
59 | tf.filter();
|
60 | tf.destroy();
|
61 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
62 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
|
63 | 'Number of applied CSS classes');
|
64 | }
|
65 | );
|