@sb1/ffe-tables-react 8.0.35 → 8.0.37
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/es/DefaultTable/DefaultTable.spec.js +167 -194
- package/es/SortableTable/SortableTable.spec.js +20 -26
- package/es/TableParts/TableRowExpandable.spec.js +22 -56
- package/lib/DefaultTable/DefaultTable.spec.js +174 -201
- package/lib/SortableTable/SortableTable.spec.js +20 -26
- package/lib/TableParts/TableRowExpandable.spec.js +22 -56
- package/package.json +6 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { assert, match, spy } from 'sinon';
|
|
3
2
|
import SortableTable from './SortableTable';
|
|
3
|
+
import { render, screen } from '@testing-library/react';
|
|
4
4
|
describe('<SortableTable>', function () {
|
|
5
5
|
var columns = [
|
|
6
6
|
{ header: 'Name', key: 'name' },
|
|
@@ -24,45 +24,39 @@ describe('<SortableTable>', function () {
|
|
|
24
24
|
{ name: 'Ned Stark', age: 48, id: 3, button: React.createElement("button", null, "poke") },
|
|
25
25
|
{ name: 'Jon Snow', age: 20, id: 1, button: React.createElement("button", null, "poke") },
|
|
26
26
|
];
|
|
27
|
-
var wrapper = render(React.createElement(SortableTable, { columns: columns, data: data }));
|
|
28
27
|
it('should show right amount of th tags', function () {
|
|
29
|
-
|
|
28
|
+
render(React.createElement(SortableTable, { columns: columns, data: data }));
|
|
29
|
+
expect(screen.getAllByRole('columnheader')).toHaveLength(columns.length);
|
|
30
30
|
});
|
|
31
31
|
it('should render a row for each data array entry', function () {
|
|
32
|
-
|
|
32
|
+
var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
|
|
33
|
+
expect(container.querySelectorAll('tbody tr')).toHaveLength(data.length);
|
|
33
34
|
});
|
|
34
35
|
it('should set data-th property on each cell rendered', function () {
|
|
35
|
-
|
|
36
|
+
var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
|
|
37
|
+
expect(container.querySelectorAll('[data-th]')).toHaveLength(data.length * columns.length);
|
|
36
38
|
});
|
|
37
39
|
it('should add `aria-sort` property', function () {
|
|
38
|
-
|
|
40
|
+
var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
|
|
41
|
+
expect(container.querySelectorAll('[aria-sort]')).toHaveLength(columns.length);
|
|
39
42
|
});
|
|
40
43
|
it('should not show sorting arrow if header is blank string', function () {
|
|
41
|
-
|
|
44
|
+
var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
|
|
45
|
+
expect(container.querySelectorAll('.ffe-sortable-table__sort-arrow')
|
|
46
|
+
.length).toBe(columns.length - 1);
|
|
42
47
|
});
|
|
43
48
|
it('should show buttons in table when passing in buttons in data', function () {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
it('should call onSort after sorting table', function () {
|
|
47
|
-
var onSort = spy();
|
|
48
|
-
var table = shallow(React.createElement(SortableTable, { columns: columns, data: data, onSort: onSort }));
|
|
49
|
-
table.instance().tableHeaderClicked('name');
|
|
50
|
-
assert.calledWith(onSort, match(function (val) {
|
|
51
|
-
return ('sortBy' in val && 'descending' in val && 'tableData' in val);
|
|
52
|
-
}));
|
|
53
|
-
});
|
|
54
|
-
it('should call onSort after initial sort', function () {
|
|
55
|
-
var onSort = spy();
|
|
56
|
-
shallow(React.createElement(SortableTable, { columns: columns, data: data, onSort: onSort, sortBy: 'name' }));
|
|
57
|
-
assert.calledWith(onSort, match(function (val) {
|
|
58
|
-
return ('sortBy' in val && 'descending' in val && 'tableData' in val);
|
|
59
|
-
}));
|
|
49
|
+
var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
|
|
50
|
+
expect(container.querySelectorAll('button').length).toBe(data.length);
|
|
60
51
|
});
|
|
61
52
|
describe('condensed', function () {
|
|
62
53
|
it('should by default not be condensed', function () {
|
|
63
|
-
|
|
54
|
+
var container = render(React.createElement(SortableTable, { columns: columns, data: data })).container;
|
|
55
|
+
expect(container.querySelectorAll('.ffe-table--condensed')).toHaveLength(0);
|
|
56
|
+
});
|
|
57
|
+
it('can be condensed', function () {
|
|
58
|
+
var container = render(React.createElement(SortableTable, { condensed: true, columns: columns, data: data })).container;
|
|
59
|
+
expect(container.querySelectorAll('.ffe-table--condensed')).toHaveLength(1);
|
|
64
60
|
});
|
|
65
|
-
var condensedWrapper = render(React.createElement(SortableTable, { condensed: true, columns: columns, data: data }));
|
|
66
|
-
it('can be condensed', function () { return expect(condensedWrapper).toHaveLength(1); });
|
|
67
61
|
});
|
|
68
62
|
});
|
|
@@ -11,6 +11,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
};
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import TableRowExpandable from './TableRowExpandable';
|
|
14
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
14
15
|
var props = {
|
|
15
16
|
cells: {
|
|
16
17
|
name: 'Ola Normann',
|
|
@@ -27,73 +28,38 @@ var props = {
|
|
|
27
28
|
{ key: 'email', content: 'E-post' },
|
|
28
29
|
],
|
|
29
30
|
};
|
|
30
|
-
var wrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props),
|
|
31
|
-
React.createElement("p", null, "The cake is a lie")));
|
|
32
|
-
var unexpandableWrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props), false && React.createElement("div", null, "Ignorance is bliss, and we won't render this")));
|
|
33
|
-
var defaultExpandedWrapper = shallow(React.createElement(TableRowExpandable, __assign({}, props, { defaultExpanded: true }),
|
|
34
|
-
React.createElement("p", null, "The cake is a lie")));
|
|
35
31
|
describe('<TableRowExpandable>', function () {
|
|
36
32
|
it('should be collapsed by default', function () {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
expect(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
expect(
|
|
43
|
-
.find('.ffe-table__row-expandable-content')
|
|
44
|
-
.hasClass('ffe-table__row--collapsed')).toBe(true);
|
|
33
|
+
var container = render(React.createElement(TableRowExpandable, __assign({}, props),
|
|
34
|
+
React.createElement("p", null, "The cake is a lie"))).container;
|
|
35
|
+
expect(container.querySelectorAll('.ffe-table__row-expandable--expanded')).toHaveLength(0);
|
|
36
|
+
var content = container.querySelector('.ffe-table__row-expandable-content');
|
|
37
|
+
expect(content.getAttribute('aria-hidden')).toBe('true');
|
|
38
|
+
expect(content.classList.contains('ffe-table__row--collapsed')).toBeTruthy();
|
|
45
39
|
});
|
|
46
40
|
it('should be expanded if provided true defaultExpanded', function () {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
expect(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
expect(
|
|
53
|
-
.find('.ffe-table__row-expandable-content')
|
|
54
|
-
.hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
|
|
41
|
+
var container = render(React.createElement(TableRowExpandable, __assign({}, props, { defaultExpanded: true }),
|
|
42
|
+
React.createElement("p", null, "The cake is a lie"))).container;
|
|
43
|
+
expect(container.querySelectorAll('.ffe-table__row--collapsed')).toHaveLength(0);
|
|
44
|
+
var content = container.querySelector('.ffe-table__row-expandable-content');
|
|
45
|
+
expect(content.getAttribute('aria-hidden')).toBe('false');
|
|
46
|
+
expect(content.classList.contains('ffe-table__row-expandable-content--expanded')).toBeTruthy();
|
|
55
47
|
});
|
|
56
48
|
it('should scroll into view on mount if true scrollToOnMount is provided', function () {
|
|
57
49
|
var scrollIntoViewMock = jest.fn();
|
|
58
50
|
window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
|
|
59
|
-
|
|
51
|
+
render(React.createElement(TableRowExpandable, __assign({}, props, { scrollToOnMount: true }),
|
|
60
52
|
React.createElement("p", null, "The cake is a lie")));
|
|
61
53
|
expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
|
|
62
54
|
});
|
|
63
55
|
it('should render expanded content', function () {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
expect(
|
|
71
|
-
|
|
72
|
-
it('should pass correct props to TableRow component', function () {
|
|
73
|
-
wrapper.setState({ expanded: true });
|
|
74
|
-
var tableRow = wrapper.find('TableRow').props();
|
|
75
|
-
expect(tableRow.expanded).toBe(true);
|
|
76
|
-
expect(tableRow.columns).toBe(props.columns);
|
|
77
|
-
expect(tableRow.trClasses).toContain('ffe-table__row-expandable--expanded');
|
|
78
|
-
});
|
|
79
|
-
it('should pass an expand icon with correct classname to TableRow', function () {
|
|
80
|
-
wrapper.setState({ expanded: true });
|
|
81
|
-
var tableRow = wrapper.find('TableRow').props();
|
|
82
|
-
expect(tableRow.cells.expandIcon.props.className).toContain('ffe-table__expand-icon--expanded');
|
|
83
|
-
expect(tableRow.expandable).toBe(true);
|
|
84
|
-
});
|
|
85
|
-
it('should not pass an expand icon to TableRows that are not expandable', function () {
|
|
86
|
-
var tableRow = unexpandableWrapper.find('TableRow').props();
|
|
87
|
-
expect(tableRow.cells.expandIcon).toBe(' ');
|
|
88
|
-
expect(tableRow.expandable).toBe(false);
|
|
89
|
-
});
|
|
90
|
-
var renderedWrapper = render(React.createElement(TableRowExpandable, __assign({}, props),
|
|
91
|
-
React.createElement("p", null, "a Festivus for the rest of us")));
|
|
92
|
-
it('should render a tbody with two tr', function () {
|
|
93
|
-
expect(renderedWrapper.children()).toHaveLength(2);
|
|
94
|
-
});
|
|
95
|
-
it('should set the correct aria attributes on tr', function () {
|
|
96
|
-
expect(renderedWrapper.find('tr').first().prop('aria-expanded')).toBe('false');
|
|
97
|
-
expect(renderedWrapper.find('tr').last().prop('aria-hidden')).toBe('true');
|
|
56
|
+
render(React.createElement(TableRowExpandable, __assign({}, props),
|
|
57
|
+
React.createElement("p", null, "The cake is a lie")));
|
|
58
|
+
var row = screen.getByRole('button');
|
|
59
|
+
fireEvent.click(row);
|
|
60
|
+
var expandedContent = screen.getByRole('presentation');
|
|
61
|
+
expect(expandedContent.textContent).toBe('The cake is a lie');
|
|
62
|
+
expect(expandedContent.classList.contains('ffe-table__row-expandable-content--expanded')).toBeTruthy();
|
|
63
|
+
expect(expandedContent.classList.contains('ffe-table__row--collapsed')).toBeFalsy();
|
|
98
64
|
});
|
|
99
65
|
});
|