forked from Tabloids/wdclib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Table.test.js
76 lines (48 loc) · 2.18 KB
/
Table.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint-env node, mocha, jest */
import Table from './Table';
// use if required for debugging
let consoleLog = console.log; // eslint-disable-line no-unused-vars
let consoleWarn = console.warn; // eslint-disable-line no-unused-vars
console.log = jest.fn();
console.warn = jest.fn();
describe('UNIT - Table', () => {
it('Table should initialize with documented DEFAULTS', () => {
let table = new Table();
expect(table.tableInfo).toBeUndefined();
expect(table.incrementValue).toBe('');
expect(table.isJoinFiltered).toBe(false);
expect(table.filterColumnId).toBe('');
expect(table.filterValues).toEqual([]);
expect(table._dataCallbackFn).toBeUndefined();
});
it('Table should initialize with assigned initialization values', () => {
let tableInfo = {};
let incrementValue = '3';
let isJoinFiltered = true;
let filterColumnId = '5';
let filterValues = [2, 3, 5, 7, 11, 13, 17, 19, 23];
let dataCallbackFn = function dataCallbackFnTest () {
// this is a test, the param is passed by reference
};
let table = new Table(tableInfo, incrementValue, isJoinFiltered, filterColumnId, filterValues, dataCallbackFn);
expect(table.tableInfo).toBe(tableInfo);
expect(table.incrementValue).toBe(incrementValue);
expect(table.isJoinFiltered).toBe(isJoinFiltered);
expect(table.filterColumnId).toBe(filterColumnId);
expect(table.filterValues).toBe(filterValues);
expect(table._dataCallbackFn).toBe(dataCallbackFn);
});
it('_appendRows should return boolean "execution success"', () => {
let table = new Table({}, '', false, '', [], () => { });
expect(table._appendRows()).toBe(false);
expect(table._appendRows({})).toBe(false);
expect(table._appendRows([])).toBe(true);
});
it('_appendRows should call _dataCallbackFn on input success"', () => {
let mockCallback = jest.fn();
let table = new Table({}, '', false, '', [], mockCallback);
table._appendRows([]);
table._appendRows([]);
expect(mockCallback.mock.calls.length).toBe(2);
});
});