@sb1/ffe-tables-react 8.0.36 → 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.
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  var react_1 = __importDefault(require("react"));
7
7
  var SortableTable_1 = __importDefault(require("./SortableTable"));
8
+ var react_2 = require("@testing-library/react");
8
9
  describe('<SortableTable>', function () {
9
10
  var columns = [
10
11
  { header: 'Name', key: 'name' },
@@ -28,99 +29,39 @@ describe('<SortableTable>', function () {
28
29
  { name: 'Ned Stark', age: 48, id: 3, button: react_1.default.createElement("button", null, "poke") },
29
30
  { name: 'Jon Snow', age: 20, id: 1, button: react_1.default.createElement("button", null, "poke") },
30
31
  ];
31
- var wrapper = render(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data }));
32
32
  it('should show right amount of th tags', function () {
33
- expect(wrapper.find('th')).toHaveLength(columns.length);
33
+ (0, react_2.render)(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data }));
34
+ expect(react_2.screen.getAllByRole('columnheader')).toHaveLength(columns.length);
34
35
  });
35
36
  it('should render a row for each data array entry', function () {
36
- expect(wrapper.find('tbody tr')).toHaveLength(data.length);
37
+ var container = (0, react_2.render)(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data })).container;
38
+ expect(container.querySelectorAll('tbody tr')).toHaveLength(data.length);
37
39
  });
38
40
  it('should set data-th property on each cell rendered', function () {
39
- expect(wrapper.find('[data-th]')).toHaveLength(data.length * columns.length);
41
+ var container = (0, react_2.render)(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data })).container;
42
+ expect(container.querySelectorAll('[data-th]')).toHaveLength(data.length * columns.length);
40
43
  });
41
44
  it('should add `aria-sort` property', function () {
42
- expect(wrapper.find('[aria-sort]')).toHaveLength(columns.length);
45
+ var container = (0, react_2.render)(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data })).container;
46
+ expect(container.querySelectorAll('[aria-sort]')).toHaveLength(columns.length);
43
47
  });
44
48
  it('should not show sorting arrow if header is blank string', function () {
45
- expect(wrapper.find('.ffe-sortable-table__sort-arrow').length).toBe(columns.length - 1);
49
+ var container = (0, react_2.render)(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data })).container;
50
+ expect(container.querySelectorAll('.ffe-sortable-table__sort-arrow')
51
+ .length).toBe(columns.length - 1);
46
52
  });
47
53
  it('should show buttons in table when passing in buttons in data', function () {
48
- expect(wrapper.find('button').length).toBe(data.length);
49
- });
50
- it('should call onSort after sorting table', function () {
51
- var onSort = jest.fn();
52
- var table = shallow(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data, onSort: onSort }));
53
- table.instance().tableHeaderClicked('name');
54
- expect.objectContaining({
55
- sortBy: 'name',
56
- descending: false,
57
- tableData: [
58
- {
59
- age: 16,
60
- button: react_1.default.createElement("button", null, "poke"),
61
- id: 4,
62
- name: 'Daenerys Targaryen',
63
- },
64
- {
65
- age: 20,
66
- button: react_1.default.createElement("button", null, "poke"),
67
- id: 1,
68
- name: 'Jon Snow',
69
- },
70
- {
71
- age: 48,
72
- button: react_1.default.createElement("button", null, "poke"),
73
- id: 3,
74
- name: 'Ned Stark',
75
- },
76
- {
77
- age: 36,
78
- button: react_1.default.createElement("button", null, "poke"),
79
- id: 2,
80
- name: 'Zombie Mountain',
81
- },
82
- ],
83
- });
84
- });
85
- it('should call onSort after initial sort', function () {
86
- var onSort = jest.fn();
87
- shallow(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data, onSort: onSort, sortBy: 'name' }));
88
- expect(onSort).toHaveBeenCalledWith(expect.objectContaining({
89
- sortBy: 'name',
90
- descending: false,
91
- tableData: [
92
- {
93
- age: 16,
94
- button: react_1.default.createElement("button", null, "poke"),
95
- id: 4,
96
- name: 'Daenerys Targaryen',
97
- },
98
- {
99
- age: 20,
100
- button: react_1.default.createElement("button", null, "poke"),
101
- id: 1,
102
- name: 'Jon Snow',
103
- },
104
- {
105
- age: 48,
106
- button: react_1.default.createElement("button", null, "poke"),
107
- id: 3,
108
- name: 'Ned Stark',
109
- },
110
- {
111
- age: 36,
112
- button: react_1.default.createElement("button", null, "poke"),
113
- id: 2,
114
- name: 'Zombie Mountain',
115
- },
116
- ],
117
- }));
54
+ var container = (0, react_2.render)(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data })).container;
55
+ expect(container.querySelectorAll('button').length).toBe(data.length);
118
56
  });
119
57
  describe('condensed', function () {
120
58
  it('should by default not be condensed', function () {
121
- return expect(wrapper.find('.ffe-table--condensed')).toHaveLength(0);
59
+ var container = (0, react_2.render)(react_1.default.createElement(SortableTable_1.default, { columns: columns, data: data })).container;
60
+ expect(container.querySelectorAll('.ffe-table--condensed')).toHaveLength(0);
61
+ });
62
+ it('can be condensed', function () {
63
+ var container = (0, react_2.render)(react_1.default.createElement(SortableTable_1.default, { condensed: true, columns: columns, data: data })).container;
64
+ expect(container.querySelectorAll('.ffe-table--condensed')).toHaveLength(1);
122
65
  });
123
- var condensedWrapper = render(react_1.default.createElement(SortableTable_1.default, { condensed: true, columns: columns, data: data }));
124
- it('can be condensed', function () { return expect(condensedWrapper).toHaveLength(1); });
125
66
  });
126
67
  });
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  var react_1 = __importDefault(require("react"));
18
18
  var TableRowExpandable_1 = __importDefault(require("./TableRowExpandable"));
19
+ var react_2 = require("@testing-library/react");
19
20
  var props = {
20
21
  cells: {
21
22
  name: 'Ola Normann',
@@ -32,73 +33,38 @@ var props = {
32
33
  { key: 'email', content: 'E-post' },
33
34
  ],
34
35
  };
35
- var wrapper = shallow(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props),
36
- react_1.default.createElement("p", null, "The cake is a lie")));
37
- var unexpandableWrapper = shallow(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props), false && react_1.default.createElement("div", null, "Ignorance is bliss, and we won't render this")));
38
- var defaultExpandedWrapper = shallow(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props, { defaultExpanded: true }),
39
- react_1.default.createElement("p", null, "The cake is a lie")));
40
36
  describe('<TableRowExpandable>', function () {
41
37
  it('should be collapsed by default', function () {
42
- expect(wrapper.state().expanded).toBe(false);
43
- expect(wrapper.find('.ffe-table__row-expandable--expanded')).toHaveLength(0);
44
- expect(wrapper
45
- .find('.ffe-table__row-expandable-content')
46
- .prop('aria-hidden')).toBe('true');
47
- expect(wrapper
48
- .find('.ffe-table__row-expandable-content')
49
- .hasClass('ffe-table__row--collapsed')).toBe(true);
38
+ var container = (0, react_2.render)(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props),
39
+ react_1.default.createElement("p", null, "The cake is a lie"))).container;
40
+ expect(container.querySelectorAll('.ffe-table__row-expandable--expanded')).toHaveLength(0);
41
+ var content = container.querySelector('.ffe-table__row-expandable-content');
42
+ expect(content.getAttribute('aria-hidden')).toBe('true');
43
+ expect(content.classList.contains('ffe-table__row--collapsed')).toBeTruthy();
50
44
  });
51
45
  it('should be expanded if provided true defaultExpanded', function () {
52
- expect(defaultExpandedWrapper.state().expanded).toBe(true);
53
- expect(defaultExpandedWrapper.find('.ffe-table__row--collapsed')).toHaveLength(0);
54
- expect(defaultExpandedWrapper
55
- .find('.ffe-table__row-expandable-content')
56
- .prop('aria-hidden')).toBe('false');
57
- expect(defaultExpandedWrapper
58
- .find('.ffe-table__row-expandable-content')
59
- .hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
46
+ var container = (0, react_2.render)(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props, { defaultExpanded: true }),
47
+ react_1.default.createElement("p", null, "The cake is a lie"))).container;
48
+ expect(container.querySelectorAll('.ffe-table__row--collapsed')).toHaveLength(0);
49
+ var content = container.querySelector('.ffe-table__row-expandable-content');
50
+ expect(content.getAttribute('aria-hidden')).toBe('false');
51
+ expect(content.classList.contains('ffe-table__row-expandable-content--expanded')).toBeTruthy();
60
52
  });
61
53
  it('should scroll into view on mount if true scrollToOnMount is provided', function () {
62
54
  var scrollIntoViewMock = jest.fn();
63
55
  window.HTMLElement.prototype.scrollIntoView = scrollIntoViewMock;
64
- mount(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props, { scrollToOnMount: true }),
56
+ (0, react_2.render)(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props, { scrollToOnMount: true }),
65
57
  react_1.default.createElement("p", null, "The cake is a lie")));
66
58
  expect(scrollIntoViewMock).toHaveBeenCalledTimes(1);
67
59
  });
68
60
  it('should render expanded content', function () {
69
- wrapper.setState({ expanded: true });
70
- expect(wrapper.find('td').last().find('p').text()).toBe('The cake is a lie');
71
- expect(wrapper
72
- .find('tr')
73
- .last()
74
- .hasClass('ffe-table__row-expandable-content--expanded')).toBe(true);
75
- expect(wrapper.find('tr').last().hasClass('ffe-table__row--collapsed')).toBe(false);
76
- });
77
- it('should pass correct props to TableRow component', function () {
78
- wrapper.setState({ expanded: true });
79
- var tableRow = wrapper.find('TableRow').props();
80
- expect(tableRow.expanded).toBe(true);
81
- expect(tableRow.columns).toBe(props.columns);
82
- expect(tableRow.trClasses).toContain('ffe-table__row-expandable--expanded');
83
- });
84
- it('should pass an expand icon with correct classname to TableRow', function () {
85
- wrapper.setState({ expanded: true });
86
- var tableRow = wrapper.find('TableRow').props();
87
- expect(tableRow.cells.expandIcon.props.className).toContain('ffe-table__expand-icon--expanded');
88
- expect(tableRow.expandable).toBe(true);
89
- });
90
- it('should not pass an expand icon to TableRows that are not expandable', function () {
91
- var tableRow = unexpandableWrapper.find('TableRow').props();
92
- expect(tableRow.cells.expandIcon).toBe(' ');
93
- expect(tableRow.expandable).toBe(false);
94
- });
95
- var renderedWrapper = render(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props),
96
- react_1.default.createElement("p", null, "a Festivus for the rest of us")));
97
- it('should render a tbody with two tr', function () {
98
- expect(renderedWrapper.children()).toHaveLength(2);
99
- });
100
- it('should set the correct aria attributes on tr', function () {
101
- expect(renderedWrapper.find('tr').first().prop('aria-expanded')).toBe('false');
102
- expect(renderedWrapper.find('tr').last().prop('aria-hidden')).toBe('true');
61
+ (0, react_2.render)(react_1.default.createElement(TableRowExpandable_1.default, __assign({}, props),
62
+ react_1.default.createElement("p", null, "The cake is a lie")));
63
+ var row = react_2.screen.getByRole('button');
64
+ react_2.fireEvent.click(row);
65
+ var expandedContent = react_2.screen.getByRole('presentation');
66
+ expect(expandedContent.textContent).toBe('The cake is a lie');
67
+ expect(expandedContent.classList.contains('ffe-table__row-expandable-content--expanded')).toBeTruthy();
68
+ expect(expandedContent.classList.contains('ffe-table__row--collapsed')).toBeFalsy();
103
69
  });
104
70
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-tables-react",
3
- "version": "8.0.36",
3
+ "version": "8.0.37",
4
4
  "description": "React implementation of ffe-tables",
5
5
  "license": "MIT",
6
6
  "author": "SpareBank 1",
@@ -26,8 +26,8 @@
26
26
  "test:watch": "ffe-buildtool jest --watch"
27
27
  },
28
28
  "dependencies": {
29
- "@sb1/ffe-icons-react": "^10.0.4",
30
- "@sb1/ffe-tables": "^14.0.22",
29
+ "@sb1/ffe-icons-react": "^10.0.5",
30
+ "@sb1/ffe-tables": "^14.0.23",
31
31
  "classnames": "^2.3.1",
32
32
  "deep-equal": "^1.0.1",
33
33
  "memoize-one": "^5.0.0",
@@ -36,7 +36,7 @@
36
36
  "shallow-equals": "^1.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@sb1/ffe-buildtool": "^0.6.3",
39
+ "@sb1/ffe-buildtool": "^0.6.4",
40
40
  "react": "^16.9.0",
41
41
  "react-dom": "^16.9.0"
42
42
  },
@@ -46,5 +46,5 @@
46
46
  "publishConfig": {
47
47
  "access": "public"
48
48
  },
49
- "gitHead": "433cd8945569727bd23b2850e770d4465d2600d3"
49
+ "gitHead": "1a06e8ffb30f92e91b7825ccebada746d7f60abc"
50
50
  }