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 |
|
48 | test('unhighlight with term', function() {
|
49 |
|
50 | tf.clearFilters();
|
51 | tf.setFilterValue(0, 'Sydney');
|
52 | tf.filter();
|
53 |
|
54 |
|
55 | highlightKeyword.unhighlight('Sydney', highlightKeyword.highlightCssClass);
|
56 |
|
57 |
|
58 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
|
59 | 'term unhighlighted');
|
60 | });
|
61 | test('unhighlight with null term', function() {
|
62 |
|
63 | tf.clearFilters();
|
64 | tf.setFilterValue(0, 'Sydney');
|
65 | tf.setFilterValue(1, 'Canbe');
|
66 | tf.filter();
|
67 |
|
68 |
|
69 | highlightKeyword.unhighlight(null, highlightKeyword.highlightCssClass);
|
70 |
|
71 |
|
72 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
|
73 | 'all terms unhighlighted');
|
74 | });
|
75 |
|
76 | module('Reset feature');
|
77 | test('can destroy and init TableFilter', function() {
|
78 | tf.destroy();
|
79 | tf.init();
|
80 | deepEqual(typeof highlightKeyword, 'object', 'Instanciated');
|
81 | deepEqual(highlightKeyword.highlightCssClass, 'keyword', 'Css class check');
|
82 | });
|
83 |
|
84 | module('Tear-down');
|
85 | test('can destroy TableFilter DOM elements and clean highlighted words',
|
86 | function() {
|
87 | tf.setFilterValue(1, 'Perth');
|
88 | tf.filter();
|
89 | tf.destroy();
|
90 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
91 | deepEqual(tf.dom().querySelectorAll('.keyword').length, 0,
|
92 | 'Number of applied CSS classes');
|
93 | }
|
94 | );
|