@sb1/ffe-tables-react 6.0.27 → 6.0.31

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.
@@ -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
- });