UNPKG

1.81 kBJavaScriptView Raw
1
2var tf = new TableFilter('demo', {
3 base_path: '../dist/tablefilter/',
4 help_instructions: {
5 container_adjust_left_position: 20
6 },
7 responsive: true
8});
9tf.init();
10
11var help = tf.feature('help');
12module('Sanity checks');
13test('Button element', function() {
14 deepEqual(typeof help, 'object', 'Help instanciated');
15 notEqual(help.btn, null, 'btn property');
16});
17
18module('Pop-up container position');
19test('Help UI elements', function() {
20 var container = help.cont,
21 helpBtn = help.btn;
22 deepEqual(container.nodeName, 'DIV', 'Help container');
23 deepEqual(helpBtn.nodeName, 'SPAN', 'Help button');
24});
25
26// 772 issue: pop-up container position when table feature horizontal scroll
27test('When table has horizontal scroll', function() {
28 // setup
29 tf.dom().scrollLeft = 10000;
30
31 // act
32 help.toggle();
33
34 // assert
35 deepEqual(
36 parseFloat(help.cont.style.left),
37 (help.btn.offsetLeft
38 - tf.dom().scrollLeft
39 + help.contAdjustLeftPosition),
40 'Pop-up container position'
41 );
42});
43
44test('When table does not have horizontal scroll', function() {
45 tf.destroy();
46 tf = new TableFilter('demo', {
47 base_path: '../dist/tablefilter/',
48 help_instructions: true,
49 responsive: false
50 });
51 tf.init();
52 var help = tf.feature('help');
53
54 // act
55 help.toggle();
56
57 // assert
58 deepEqual(help.cont.style.left, '', 'Pop-up container position');
59});
60
61module('Tear-down');
62test('can destroy Help UI component', function() {
63 // act
64 tf.destroy();
65 var help = tf.feature('help');
66
67 // assert
68 deepEqual(help.btn, null, 'Help button removed');
69 deepEqual(help.cont, null, 'Help pop-up container removed');
70});