@sb1/ffe-tables-react 6.0.27 → 6.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -10
- package/es/DefaultTable/DefaultTable.spec.js +0 -573
- package/es/SortableTable/SortableTable.spec.js +0 -87
- package/es/SortableTable/sort-data.spec.js +0 -81
- package/es/TableParts/TableRowExpandable.spec.js +0 -96
- package/lib/DefaultTable/DefaultTable.spec.js +0 -581
- package/lib/SortableTable/SortableTable.spec.js +0 -96
- package/lib/SortableTable/sort-data.spec.js +0 -86
- package/lib/TableParts/TableRowExpandable.spec.js +0 -103
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { render, shallow } from 'enzyme';
|
|
3
|
-
import { assert, match, spy } from 'sinon';
|
|
4
|
-
import SortableTable from './SortableTable';
|
|
5
|
-
describe('<SortableTable>', function () {
|
|
6
|
-
var columns = [{
|
|
7
|
-
header: 'Name',
|
|
8
|
-
key: 'name'
|
|
9
|
-
}, {
|
|
10
|
-
header: 'Age',
|
|
11
|
-
key: 'age'
|
|
12
|
-
}, {
|
|
13
|
-
header: 'Employee-id',
|
|
14
|
-
key: 'id'
|
|
15
|
-
}, {
|
|
16
|
-
header: '',
|
|
17
|
-
key: 'button'
|
|
18
|
-
}];
|
|
19
|
-
var data = [{
|
|
20
|
-
name: 'Zombie Mountain',
|
|
21
|
-
age: 36,
|
|
22
|
-
id: 2,
|
|
23
|
-
button: /*#__PURE__*/React.createElement("button", null, "poke")
|
|
24
|
-
}, {
|
|
25
|
-
name: 'Daenerys Targaryen',
|
|
26
|
-
age: 16,
|
|
27
|
-
id: 4,
|
|
28
|
-
button: /*#__PURE__*/React.createElement("button", null, "poke")
|
|
29
|
-
}, {
|
|
30
|
-
name: 'Ned Stark',
|
|
31
|
-
age: 48,
|
|
32
|
-
id: 3,
|
|
33
|
-
button: /*#__PURE__*/React.createElement("button", null, "poke")
|
|
34
|
-
}, {
|
|
35
|
-
name: 'Jon Snow',
|
|
36
|
-
age: 20,
|
|
37
|
-
id: 1,
|
|
38
|
-
button: /*#__PURE__*/React.createElement("button", null, "poke")
|
|
39
|
-
}];
|
|
40
|
-
var wrapper = render( /*#__PURE__*/React.createElement(SortableTable, {
|
|
41
|
-
columns: columns,
|
|
42
|
-
data: data
|
|
43
|
-
}));
|
|
44
|
-
it('should show right amount of th tags', function () {
|
|
45
|
-
expect(wrapper.find('th')).toHaveLength(columns.length);
|
|
46
|
-
});
|
|
47
|
-
it('should render a row for each data array entry', function () {
|
|
48
|
-
expect(wrapper.find('tbody tr')).toHaveLength(data.length);
|
|
49
|
-
});
|
|
50
|
-
it('should set data-th property on each cell rendered', function () {
|
|
51
|
-
expect(wrapper.find('[data-th]')).toHaveLength(data.length * columns.length);
|
|
52
|
-
});
|
|
53
|
-
it('should add `aria-sort` property', function () {
|
|
54
|
-
expect(wrapper.find('[aria-sort]')).toHaveLength(columns.length);
|
|
55
|
-
});
|
|
56
|
-
it('should not show sorting arrow if header is blank string', function () {
|
|
57
|
-
expect(wrapper.find('.ffe-sortable-table__sort-arrow').length).toBe(columns.length - 1);
|
|
58
|
-
});
|
|
59
|
-
it('should show buttons in table when passing in buttons in data', function () {
|
|
60
|
-
expect(wrapper.find('button').length).toBe(data.length);
|
|
61
|
-
});
|
|
62
|
-
it('should call onSort after sorting table', function () {
|
|
63
|
-
var onSort = spy();
|
|
64
|
-
var table = shallow( /*#__PURE__*/React.createElement(SortableTable, {
|
|
65
|
-
columns: columns,
|
|
66
|
-
data: data,
|
|
67
|
-
onSort: onSort
|
|
68
|
-
}));
|
|
69
|
-
table.instance().tableHeaderClicked('name');
|
|
70
|
-
assert.calledWith(onSort, match(function (val) {
|
|
71
|
-
return 'sortBy' in val && 'descending' in val && 'tableData' in val;
|
|
72
|
-
}));
|
|
73
|
-
});
|
|
74
|
-
describe('condensed', function () {
|
|
75
|
-
it('should by default not be condensed', function () {
|
|
76
|
-
return expect(wrapper.find('.ffe-table--condensed')).toHaveLength(0);
|
|
77
|
-
});
|
|
78
|
-
var condensedWrapper = render( /*#__PURE__*/React.createElement(SortableTable, {
|
|
79
|
-
condensed: true,
|
|
80
|
-
columns: columns,
|
|
81
|
-
data: data
|
|
82
|
-
}));
|
|
83
|
-
it('can be condensed', function () {
|
|
84
|
-
return expect(condensedWrapper).toHaveLength(1);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import sortData from './sort-data';
|
|
2
|
-
var columns = [{
|
|
3
|
-
key: 'name',
|
|
4
|
-
header: 'Name'
|
|
5
|
-
}, {
|
|
6
|
-
key: 'age',
|
|
7
|
-
header: 'Age'
|
|
8
|
-
}, {
|
|
9
|
-
key: 'id',
|
|
10
|
-
header: 'Employee-id'
|
|
11
|
-
}, {
|
|
12
|
-
key: 'rand',
|
|
13
|
-
header: 'A random number with thousand separator needs a custom compare',
|
|
14
|
-
compare: function compare(a, b) {
|
|
15
|
-
return a.replace(/\s/g, '') - b.replace(/\s/g, '');
|
|
16
|
-
}
|
|
17
|
-
}];
|
|
18
|
-
var data = [{
|
|
19
|
-
name: 'Zombie Mountain',
|
|
20
|
-
age: 36,
|
|
21
|
-
id: 2,
|
|
22
|
-
rand: '69 873'
|
|
23
|
-
}, {
|
|
24
|
-
name: 'Daenerys Targaryen',
|
|
25
|
-
age: 16,
|
|
26
|
-
id: 4,
|
|
27
|
-
rand: '9 156'
|
|
28
|
-
}, {
|
|
29
|
-
name: 'Ned Stark',
|
|
30
|
-
age: 48,
|
|
31
|
-
id: 3,
|
|
32
|
-
rand: '3 863 914'
|
|
33
|
-
}, {
|
|
34
|
-
name: 'Jon Snow',
|
|
35
|
-
age: 20,
|
|
36
|
-
id: 1,
|
|
37
|
-
rand: '145 678'
|
|
38
|
-
}];
|
|
39
|
-
describe('sortData', function () {
|
|
40
|
-
it('should sort data in descending order', function () {
|
|
41
|
-
var ascendingTableData = sortData(columns, data, 'age', true);
|
|
42
|
-
|
|
43
|
-
for (var i = 1; i > ascendingTableData.length; i++) {
|
|
44
|
-
expect(ascendingTableData[i].id).toBeLessThan(ascendingTableData[i - 1].id);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
it('should sort data in ascending order', function () {
|
|
48
|
-
var ascendingTableData = sortData(columns, data, 'age', false);
|
|
49
|
-
|
|
50
|
-
for (var i = 1; i > ascendingTableData.length; i++) {
|
|
51
|
-
expect(ascendingTableData[i].id).toBeGreaterThan(ascendingTableData[i - 1].id);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
it('should sort data based on `sortBy` parameter', function () {
|
|
55
|
-
var tableData = sortData(columns, data, 'age', true);
|
|
56
|
-
expect(tableData[0].age).toBe(48);
|
|
57
|
-
expect(tableData[1].age).toBe(36);
|
|
58
|
-
expect(tableData[2].age).toBe(20);
|
|
59
|
-
expect(tableData[3].age).toBe(16);
|
|
60
|
-
});
|
|
61
|
-
it('should sort data even though an attribute is not set', function () {
|
|
62
|
-
data[3] = {
|
|
63
|
-
name: 'Jon Snow',
|
|
64
|
-
id: 1,
|
|
65
|
-
rand: '145 678'
|
|
66
|
-
}; // no age key
|
|
67
|
-
|
|
68
|
-
var tableData = sortData(columns, data, 'age', false);
|
|
69
|
-
expect(tableData[0].age).toBe(16);
|
|
70
|
-
expect(tableData[1].age).toBe(36);
|
|
71
|
-
expect(tableData[2].age).toBe(48);
|
|
72
|
-
expect(tableData[3].age).toBe(undefined);
|
|
73
|
-
});
|
|
74
|
-
it('should sort data with a custom compare function when provided', function () {
|
|
75
|
-
var tableData = sortData(columns, data, 'rand', false);
|
|
76
|
-
expect(tableData[0].rand).toBe('9 156');
|
|
77
|
-
expect(tableData[1].rand).toBe('69 873');
|
|
78
|
-
expect(tableData[2].rand).toBe('145 678');
|
|
79
|
-
expect(tableData[3].rand).toBe('3 863 914');
|
|
80
|
-
});
|
|
81
|
-
});
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { shallow, render, mount } from 'enzyme';
|
|
5
|
-
import TableRowExpandable from './TableRowExpandable';
|
|
6
|
-
var props = {
|
|
7
|
-
cells: {
|
|
8
|
-
name: 'Ola Normann',
|
|
9
|
-
address: 'Gateveien 2',
|
|
10
|
-
age: 23,
|
|
11
|
-
phone: '912 34 567',
|
|
12
|
-
email: 'ola@normann.no'
|
|
13
|
-
},
|
|
14
|
-
columns: [{
|
|
15
|
-
key: 'name',
|
|
16
|
-
content: 'Navn'
|
|
17
|
-
}, {
|
|
18
|
-
key: 'address',
|
|
19
|
-
content: 'Adresse'
|
|
20
|
-
}, {
|
|
21
|
-
key: 'age',
|
|
22
|
-
content: 'Alder',
|
|
23
|
-
alignRight: true
|
|
24
|
-
}, {
|
|
25
|
-
key: 'phone',
|
|
26
|
-
content: 'Telefon'
|
|
27
|
-
}, {
|
|
28
|
-
key: 'email',
|
|
29
|
-
content: 'E-post'
|
|
30
|
-
}]
|
|
31
|
-
};
|
|
32
|
-
var wrapper = shallow( /*#__PURE__*/React.createElement(TableRowExpandable, props, /*#__PURE__*/React.createElement("p", null, "The cake is a lie")));
|
|
33
|
-
var unexpandableWrapper = shallow( /*#__PURE__*/React.createElement(TableRowExpandable, props, false && /*#__PURE__*/React.createElement("div", null, "Ignorance is bliss, and we won't render this")));
|
|
34
|
-
var defaultExpandedWrapper = shallow( /*#__PURE__*/React.createElement(TableRowExpandable, _extends({}, props, {
|
|
35
|
-
defaultExpanded: true
|
|
36
|
-
}), /*#__PURE__*/React.createElement("p", null, "The cake is a lie")));
|
|
37
|
-
describe('<TableRowExpandable>', function () {
|
|
38
|
-
it('should be collapsed by default', function () {
|
|
39
|
-
expect(wrapper.state().expanded).toBe(false);
|
|
40
|
-
expect(wrapper.find('.ffe-table__row-expandable--expanded')).toHaveLength(0);
|
|
41
|
-
expect(wrapper.find('.ffe-table__row-expandable-content').prop('aria-hidden')).toBe('true');
|
|
42
|
-
expect(wrapper.find('.ffe-table__row-expandable-content').hasClass('ffe-table__row--collapsed')).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
it('should be expanded if provided true defaultExpanded', function () {
|
|
45
|
-
expect(defaultExpandedWrapper.state().expanded).toBe(true);
|
|
46
|
-
expect(defaultExpandedWrapper.find('.ffe-table__row--collapsed')).toHaveLength(0);
|
|
47
|
-
expect(defaultExpandedWrapper.find('.ffe-table__row-expandable-content').prop('aria-hidden')).toBe('false');
|
|
48
|
-
expect(defaultExpandedWrapper.find('.ffe-table__row-expandable-content').hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
|
|
49
|
-
});
|
|
50
|
-
it('should scroll into view on mount if true scrollToOnMount is provided', function () {
|
|
51
|
-
var scrollIntoViewMock = jest.fn();
|
|
52
|
-
window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
|
|
53
|
-
mount( /*#__PURE__*/React.createElement(TableRowExpandable, _extends({}, props, {
|
|
54
|
-
scrollToOnMount: true
|
|
55
|
-
}), /*#__PURE__*/React.createElement("p", null, "The cake is a lie")));
|
|
56
|
-
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
|
|
57
|
-
});
|
|
58
|
-
it('should render expanded content', function () {
|
|
59
|
-
wrapper.setState({
|
|
60
|
-
expanded: true
|
|
61
|
-
});
|
|
62
|
-
expect(wrapper.find('td').last().find('p').text()).toBe('The cake is a lie');
|
|
63
|
-
expect(wrapper.find('tr').last().hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
|
|
64
|
-
expect(wrapper.find('tr').last().hasClass('ffe-table__row--collapsed')).toBe(false);
|
|
65
|
-
});
|
|
66
|
-
it('should pass correct props to TableRow component', function () {
|
|
67
|
-
wrapper.setState({
|
|
68
|
-
expanded: true
|
|
69
|
-
});
|
|
70
|
-
var tableRow = wrapper.find('TableRow').props();
|
|
71
|
-
expect(tableRow.expanded).toBe(true);
|
|
72
|
-
expect(tableRow.columns).toBe(props.columns);
|
|
73
|
-
expect(tableRow.trClasses).toContain('ffe-table__row-expandable--expanded');
|
|
74
|
-
});
|
|
75
|
-
it('should pass an expand icon with correct classname to TableRow', function () {
|
|
76
|
-
wrapper.setState({
|
|
77
|
-
expanded: true
|
|
78
|
-
});
|
|
79
|
-
var tableRow = wrapper.find('TableRow').props();
|
|
80
|
-
expect(tableRow.cells.expandIcon.props.className).toContain('ffe-table__expand-icon--expanded');
|
|
81
|
-
expect(tableRow.expandable).toBe(true);
|
|
82
|
-
});
|
|
83
|
-
it('should not pass an expand icon to TableRows that are not expandable', function () {
|
|
84
|
-
var tableRow = unexpandableWrapper.find('TableRow').props();
|
|
85
|
-
expect(tableRow.cells.expandIcon).toBe(' ');
|
|
86
|
-
expect(tableRow.expandable).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
var renderedWrapper = render( /*#__PURE__*/React.createElement(TableRowExpandable, props, /*#__PURE__*/React.createElement("p", null, "a Festivus for the rest of us")));
|
|
89
|
-
it('should render a tbody with two tr', function () {
|
|
90
|
-
expect(renderedWrapper.children()).toHaveLength(2);
|
|
91
|
-
});
|
|
92
|
-
it('should set the correct aria attributes on tr', function () {
|
|
93
|
-
expect(renderedWrapper.find('tr').first().prop('aria-expanded')).toBe('false');
|
|
94
|
-
expect(renderedWrapper.find('tr').last().prop('aria-hidden')).toBe('true');
|
|
95
|
-
});
|
|
96
|
-
});
|