@dhis2-ui/pagination 8.1.10 → 8.2.1

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.
@@ -9,6 +9,8 @@ var _style = _interopRequireDefault(require("styled-jsx/style"));
9
9
 
10
10
  var _uiConstants = require("@dhis2/ui-constants");
11
11
 
12
+ var _classnames = _interopRequireDefault(require("classnames"));
13
+
12
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
15
 
14
16
  var _react = _interopRequireDefault(require("react"));
@@ -23,15 +25,17 @@ const translate = (prop, interpolationObject) => {
23
25
  return prop;
24
26
  };
25
27
 
26
- const PageSummary = ({
27
- dataTest,
28
- firstItem,
29
- lastItem,
30
- page,
31
- pageCount,
32
- pageSummaryText,
33
- total
34
- }) => {
28
+ const PageSummary = _ref => {
29
+ let {
30
+ dataTest,
31
+ firstItem,
32
+ inactive,
33
+ lastItem,
34
+ page,
35
+ pageCount,
36
+ pageSummaryText,
37
+ total
38
+ } = _ref;
35
39
  const summary = translate(pageSummaryText, {
36
40
  firstItem,
37
41
  lastItem,
@@ -40,14 +44,16 @@ const PageSummary = ({
40
44
  total
41
45
  });
42
46
  return /*#__PURE__*/_react.default.createElement("div", {
43
- "data-test": `${dataTest}-summary`,
44
- className: _style.default.dynamic([["3931741314", [_uiConstants.spacers.dp12, _uiConstants.colors.grey700]]])
47
+ "data-test": "".concat(dataTest, "-summary"),
48
+ className: _style.default.dynamic([["1022808428", [_uiConstants.spacers.dp12, _uiConstants.colors.grey700, _uiConstants.colors.grey500]]])
45
49
  }, /*#__PURE__*/_react.default.createElement("span", {
46
- className: _style.default.dynamic([["3931741314", [_uiConstants.spacers.dp12, _uiConstants.colors.grey700]]])
50
+ className: _style.default.dynamic([["1022808428", [_uiConstants.spacers.dp12, _uiConstants.colors.grey700, _uiConstants.colors.grey500]]]) + " " + ((0, _classnames.default)({
51
+ inactive
52
+ }) || "")
47
53
  }, summary), /*#__PURE__*/_react.default.createElement(_style.default, {
48
- id: "3931741314",
49
- dynamic: [_uiConstants.spacers.dp12, _uiConstants.colors.grey700]
50
- }, [`div.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;min-height:32px;margin-right:${_uiConstants.spacers.dp12};}`, `span.__jsx-style-dynamic-selector{color:${_uiConstants.colors.grey700};font-size:14px;}`]));
54
+ id: "1022808428",
55
+ dynamic: [_uiConstants.spacers.dp12, _uiConstants.colors.grey700, _uiConstants.colors.grey500]
56
+ }, ["div.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;min-height:32px;margin-right:".concat(_uiConstants.spacers.dp12, ";}"), "span.__jsx-style-dynamic-selector{color:".concat(_uiConstants.colors.grey700, ";font-size:14px;}"), "span.inactive.__jsx-style-dynamic-selector{color:".concat(_uiConstants.colors.grey500, ";}")]));
51
57
  };
52
58
 
53
59
  exports.PageSummary = PageSummary;
@@ -56,6 +62,7 @@ PageSummary.propTypes = {
56
62
  page: _propTypes.default.number.isRequired,
57
63
  pageSummaryText: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.func]).isRequired,
58
64
  firstItem: _propTypes.default.number,
65
+ inactive: _propTypes.default.bool,
59
66
  lastItem: _propTypes.default.number,
60
67
  pageCount: _propTypes.default.number,
61
68
  total: _propTypes.default.number
@@ -33,27 +33,29 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
33
33
 
34
34
  const MAX_PAGE_COUNT = 2000;
35
35
 
36
- const Pagination = ({
37
- className,
38
- dataTest,
39
- hidePageSelect,
40
- hidePageSizeSelect,
41
- hidePageSummary,
42
- isLastPage,
43
- nextPageText,
44
- onPageChange,
45
- onPageSizeChange,
46
- page,
47
- pageCount,
48
- pageLength,
49
- pageSelectText,
50
- pageSize,
51
- pageSizes,
52
- pageSizeSelectText,
53
- pageSummaryText,
54
- previousPageText,
55
- total
56
- }) => {
36
+ const Pagination = _ref => {
37
+ let {
38
+ className,
39
+ dataTest,
40
+ disabled,
41
+ hidePageSelect,
42
+ hidePageSizeSelect,
43
+ hidePageSummary,
44
+ isLastPage,
45
+ nextPageText,
46
+ onPageChange,
47
+ onPageSizeChange,
48
+ page,
49
+ pageCount,
50
+ pageLength,
51
+ pageSelectText,
52
+ pageSize,
53
+ pageSizes,
54
+ pageSizeSelectText,
55
+ pageSummaryText,
56
+ previousPageText,
57
+ total
58
+ } = _ref;
57
59
  const {
58
60
  firstItem,
59
61
  lastItem
@@ -72,12 +74,14 @@ const Pagination = ({
72
74
  className: "jsx-3647884394" + " " + "spacer"
73
75
  }) : /*#__PURE__*/_react.default.createElement(_pageSizeSelect.PageSizeSelect, {
74
76
  dataTest: dataTest,
77
+ disabled: disabled,
75
78
  pageSize: pageSize,
76
79
  pageSizes: pageSizes,
77
80
  onChange: onPageSizeChange,
78
81
  pageSizeSelectText: pageSizeSelectText
79
82
  }), !hidePageSummary && /*#__PURE__*/_react.default.createElement(_pageSummary.PageSummary, {
80
83
  dataTest: dataTest,
84
+ inactive: disabled,
81
85
  firstItem: firstItem,
82
86
  lastItem: lastItem,
83
87
  page: page,
@@ -88,17 +92,19 @@ const Pagination = ({
88
92
  className: "jsx-3647884394" + " " + "page-navigation"
89
93
  }, showPageSelect && /*#__PURE__*/_react.default.createElement(_pageSelect.PageSelect, {
90
94
  dataTest: dataTest,
95
+ disabled: disabled,
91
96
  pageSelectText: pageSelectText,
92
97
  page: page,
93
98
  pageCount: pageCount,
94
99
  onChange: onPageChange
95
100
  }), /*#__PURE__*/_react.default.createElement(_pageControls.PageControls, {
96
101
  dataTest: dataTest,
97
- isLastPage: isLastPage || page === pageCount,
98
102
  nextPageText: nextPageText,
99
103
  page: page,
100
104
  previousPageText: previousPageText,
101
- onClick: onPageChange
105
+ onClick: onPageChange,
106
+ isNextDisabled: disabled || isLastPage || page === pageCount,
107
+ isPreviousDisabled: disabled || page === 1
102
108
  })), /*#__PURE__*/_react.default.createElement(_style.default, {
103
109
  id: "3647884394"
104
110
  }, [".container.jsx-3647884394{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;}", ".spacer.jsx-3647884394{-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;}", ".page-navigation.jsx-3647884394{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;min-height:32px;}"]));
@@ -119,6 +125,7 @@ Pagination.propTypes = {
119
125
  pageSize: _propTypes2.default.number.isRequired,
120
126
  className: _propTypes2.default.string,
121
127
  dataTest: _propTypes2.default.string,
128
+ disabled: _propTypes2.default.bool,
122
129
  hidePageSelect: _propTypes2.default.bool,
123
130
  hidePageSizeSelect: _propTypes2.default.bool,
124
131
  hidePageSummary: _propTypes2.default.bool,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WithoutAnySelect = exports.WithCustomPageSummary = exports.WithoutPageSummary = exports.WithoutGoToPageSelect = exports.WithoutPageSizeSelect = exports.NoTotalAtLastPageWithoutPageLength = exports.NoTotalAtLastPage = exports.NoTotal = exports.PagerAtLastPage = exports.PagerAtFirstPage = exports.Default = exports.default = void 0;
6
+ exports.default = exports.WithoutPageSummary = exports.WithoutPageSizeSelect = exports.WithoutGoToPageSelect = exports.WithoutAnySelect = exports.WithCustomPageSummary = exports.PagerAtLastPage = exports.PagerAtFirstPage = exports.NoTotalAtLastPageWithoutPageLength = exports.NoTotalAtLastPage = exports.NoTotal = exports.Disabled = exports.Default = void 0;
7
7
 
8
8
  var _d2I18n = _interopRequireDefault(require("@dhis2/d2-i18n"));
9
9
 
@@ -20,28 +20,18 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
 
22
22
  const subtitle = 'Allows navigation through data displayed over several pages';
23
- const description = `
24
- Pagination allows data to be split in pages. Paging large amounts of data avoids overwhelming users and should always be used wherever a lot of data is displayed. Pagination controls allow a user to browse through a set of data or navigate to a specific page depending on the type of pagination used.
25
-
26
- **Do not rely on pagination for navigating datasets. A user should be able to search within, sort and filter datasets too, rather than needing to click through many pages looking for the right data item.**
27
-
28
- \`\`\`js
29
- import { Pagination } from '@dhis2/ui'
30
- \`\`\`
31
-
32
- _**Note**: Dropdown menus may not display properly on this page. View these demos in the 'Canvas' tab._
33
- `;
23
+ const description = "\nPagination allows data to be split in pages. Paging large amounts of data avoids overwhelming users and should always be used wherever a lot of data is displayed. Pagination controls allow a user to browse through a set of data or navigate to a specific page depending on the type of pagination used.\n\n**Do not rely on pagination for navigating datasets. A user should be able to search within, sort and filter datasets too, rather than needing to click through many pages looking for the right data item.**\n\n```js\nimport { Pagination } from '@dhis2/ui'\n```\n\n_**Note**: Dropdown menus may not display properly on this page. View these demos in the 'Canvas' tab._\n";
34
24
 
35
25
  const logOnPageChange = page => {
36
- console.log(`Now navigate to page ${page}...`);
26
+ console.log("Now navigate to page ".concat(page, "..."));
37
27
  };
38
28
 
39
29
  const logOnPageSizeChange = pageSize => {
40
- console.log(`Now change page size to ${pageSize}...`);
30
+ console.log("Now change page size to ".concat(pageSize, "..."));
41
31
  };
42
32
 
43
33
  var _default = {
44
- title: 'Navigation/Pagination',
34
+ title: 'Pagination',
45
35
  component: _pagination.Pagination,
46
36
  parameters: {
47
37
  componentSubtitle: subtitle,
@@ -65,6 +55,11 @@ const Default = Template.bind({});
65
55
  exports.Default = Default;
66
56
  Default.args = { ...pagers.atTenthPage
67
57
  };
58
+ const Disabled = Template.bind({});
59
+ exports.Disabled = Disabled;
60
+ Disabled.args = { ...pagers.atTenthPage,
61
+ disabled: true
62
+ };
68
63
  const PagerAtFirstPage = Template.bind({});
69
64
  exports.PagerAtFirstPage = PagerAtFirstPage;
70
65
  PagerAtFirstPage.args = { ...pagers.atFirstPage
@@ -4,6 +4,12 @@ export const atFirstPage = {
4
4
  total: 1035,
5
5
  pageSize: 50
6
6
  };
7
+ export const atSecondPage = {
8
+ page: 2,
9
+ pageCount: 21,
10
+ total: 1035,
11
+ pageSize: 50
12
+ };
7
13
  export const atTenthPage = {
8
14
  page: 10,
9
15
  pageCount: 21,
@@ -16,8 +22,14 @@ export const atLastPage = {
16
22
  total: 1035,
17
23
  pageSize: 50
18
24
  };
25
+ export const atPageBeforeLast = {
26
+ page: 20,
27
+ pageCount: 21,
28
+ total: 1035,
29
+ pageSize: 50
30
+ };
19
31
  export const noTotal = {
20
- page: 2,
32
+ page: 3,
21
33
  pageSize: 50,
22
34
  isLastPage: false
23
35
  };
@@ -15,8 +15,8 @@ describe('getItemRange', () => {
15
15
  pageSize,
16
16
  total
17
17
  });
18
- expect(firstItem).toEqual(451);
19
- expect(lastItem).toEqual(500);
18
+ expect(firstItem).toBe(451);
19
+ expect(lastItem).toBe(500);
20
20
  });
21
21
  it('returns 0 for firstItem and lastItem if the total is 0', () => {
22
22
  const {
@@ -27,8 +27,8 @@ describe('getItemRange', () => {
27
27
  pageSize: 50,
28
28
  total: 0
29
29
  });
30
- expect(firstItem).toEqual(0);
31
- expect(lastItem).toEqual(0);
30
+ expect(firstItem).toBe(0);
31
+ expect(lastItem).toBe(0);
32
32
  });
33
33
  it('uses the total count as lastItem when the last page is reached', () => {
34
34
  const {
@@ -43,7 +43,7 @@ describe('getItemRange', () => {
43
43
  pageSize,
44
44
  total
45
45
  });
46
- expect(lastItem).toEqual(total);
46
+ expect(lastItem).toBe(total);
47
47
  });
48
48
  it('handles pagers without totals', () => {
49
49
  const {
@@ -53,8 +53,8 @@ describe('getItemRange', () => {
53
53
  page: 3,
54
54
  pageSize: 50
55
55
  });
56
- expect(firstItem).toEqual(101);
57
- expect(lastItem).toEqual(150);
56
+ expect(firstItem).toBe(101);
57
+ expect(lastItem).toBe(150);
58
58
  });
59
59
  it('bases the lastItem on the pageLength for pagers without total when the last page is reached', () => {
60
60
  const {
@@ -65,7 +65,7 @@ describe('getItemRange', () => {
65
65
  pageLength: 21,
66
66
  isLastPage: true
67
67
  });
68
- expect(lastItem).toEqual(121);
68
+ expect(lastItem).toBe(121);
69
69
  });
70
70
  it('sets lastItem to NaN when on the last page and there is no total or pageLength', () => {
71
71
  const {
@@ -75,6 +75,6 @@ describe('getItemRange', () => {
75
75
  pageSize: 50,
76
76
  isLastPage: true
77
77
  });
78
- expect(lastItem).toEqual(NaN);
78
+ expect(lastItem).toBe(NaN);
79
79
  });
80
80
  });
@@ -18,24 +18,24 @@ describe('<PageControls />', () => {
18
18
  it('renders without errors', () => {
19
19
  shallow( /*#__PURE__*/React.createElement(PageControls, props));
20
20
  });
21
- it('disables no buttons on a page between first and last', () => {
21
+ it('enables all buttons on by default', () => {
22
22
  const wrapper = shallow( /*#__PURE__*/React.createElement(PageControls, props));
23
- expect(wrapper.find('.button-previous').getElement().props.disabled).toEqual(false);
24
- expect(wrapper.find('.button-next').getElement().props.disabled).toEqual(false);
23
+ expect(wrapper.find('.button-previous').getElement().props.disabled).toBeFalsy();
24
+ expect(wrapper.find('.button-next').getElement().props.disabled).toBeFalsy();
25
25
  });
26
- it('disables the previous page button on the first page', () => {
26
+ it('disables the previous page button when isPreviousDisabled is true', () => {
27
27
  const wrapper = shallow( /*#__PURE__*/React.createElement(PageControls, _extends({}, props, {
28
- page: 1
28
+ isPreviousDisabled: true
29
29
  })));
30
- expect(wrapper.find('.button-previous').getElement().props.disabled).toEqual(true);
31
- expect(wrapper.find('.button-next').getElement().props.disabled).toEqual(false);
30
+ expect(wrapper.find('.button-previous').getElement().props.disabled).toBe(true);
31
+ expect(wrapper.find('.button-next').getElement().props.disabled).toBeFalsy();
32
32
  });
33
- it('disables the next page button on the last page', () => {
33
+ it('disables the next page button when isNextDisabled is true', () => {
34
34
  const wrapper = shallow( /*#__PURE__*/React.createElement(PageControls, _extends({}, props, {
35
- isLastPage: true
35
+ isNextDisabled: true
36
36
  })));
37
- expect(wrapper.find('.button-previous').getElement().props.disabled).toEqual(false);
38
- expect(wrapper.find('.button-next').getElement().props.disabled).toEqual(true);
37
+ expect(wrapper.find('.button-previous').getElement().props.disabled).toBeFalsy();
38
+ expect(wrapper.find('.button-next').getElement().props.disabled).toBe(true);
39
39
  });
40
40
  it('calls the onClick handler with the value for the next page when next is clicked', () => {
41
41
  const wrapper = shallow( /*#__PURE__*/React.createElement(PageControls, props));
@@ -27,7 +27,7 @@ describe('<PageSummary />', () => {
27
27
  total: 224
28
28
  })));
29
29
  const expectedString = 'Page 2 of 5, items 51-100 of 224';
30
- expect(wrapper.find('span').text()).toEqual(expectedString);
30
+ expect(wrapper.find('span').text()).toBe(expectedString);
31
31
  });
32
32
  it('renders the correct message when only lastItem is provided', () => {
33
33
  const wrapper = shallow( /*#__PURE__*/React.createElement(PageSummary, _extends({}, props, {
@@ -37,7 +37,7 @@ describe('<PageSummary />', () => {
37
37
  pageCount: 5
38
38
  })));
39
39
  const expectedString = 'Page 2, items 51-100';
40
- expect(wrapper.find('span').text()).toEqual(expectedString);
40
+ expect(wrapper.find('span').text()).toBe(expectedString);
41
41
  });
42
42
  it('renders the correct message when total is missing and lastItem is not a number', () => {
43
43
  const wrapper = shallow( /*#__PURE__*/React.createElement(PageSummary, _extends({}, props, {
@@ -47,6 +47,6 @@ describe('<PageSummary />', () => {
47
47
  pageCount: 5
48
48
  })));
49
49
  const expectedString = 'Page 2';
50
- expect(wrapper.find('span').text()).toEqual(expectedString);
50
+ expect(wrapper.find('span').text()).toBe(expectedString);
51
51
  });
52
52
  });
@@ -1,10 +1,9 @@
1
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
2
 
3
- import { shallow } from 'enzyme';
3
+ import '@testing-library/dom';
4
+ import { render } from '@testing-library/react';
4
5
  import React from 'react';
5
6
  import * as mockPagers from '../__fixtures__/index.js';
6
- import { PageSelect } from '../page-select.js';
7
- import { PageSizeSelect } from '../page-size-select.js';
8
7
  import { Pagination } from '../pagination.js';
9
8
  describe('<Pagination />', () => {
10
9
  describe('Pagination with total and totalPages', () => {
@@ -13,69 +12,163 @@ describe('<Pagination />', () => {
13
12
  onPageSizeChange: () => {}
14
13
  };
15
14
  it('renders without errors', () => {
16
- shallow( /*#__PURE__*/React.createElement(Pagination, props));
15
+ render( /*#__PURE__*/React.createElement(Pagination, props));
17
16
  });
18
17
  it('renders a PageSelect and PageSizeSelect by default', () => {
19
- const wrapper = shallow( /*#__PURE__*/React.createElement(Pagination, props));
20
- expect(wrapper.find(PageSelect).length).toEqual(1);
21
- expect(wrapper.find(PageSizeSelect).length).toEqual(1);
18
+ const {
19
+ getByTestId
20
+ } = render( /*#__PURE__*/React.createElement(Pagination, props));
21
+ expect(getByTestId('dhis2-uiwidgets-pagination-page-select')).toBeInTheDocument();
22
+ expect(getByTestId('dhis2-uiwidgets-pagination-pagesize')).toBeInTheDocument();
22
23
  });
23
24
  it('renders without a PageSelect when hidePageSelect is true', () => {
24
- const wrapper = shallow( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
25
+ const {
26
+ getByTestId,
27
+ queryByTestId
28
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
25
29
  hidePageSelect: true
26
30
  })));
27
- expect(wrapper.find(PageSelect).length).toEqual(0);
28
- expect(wrapper.find(PageSizeSelect).length).toEqual(1);
31
+ expect(queryByTestId('dhis2-uiwidgets-pagination-page-select')).not.toBeInTheDocument();
32
+ expect(getByTestId('dhis2-uiwidgets-pagination-pagesize')).toBeInTheDocument();
29
33
  });
30
34
  it('renders without a PageSelect when pageCount is not provided', () => {
31
- const wrapper = shallow( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
35
+ const {
36
+ getByTestId,
37
+ queryByTestId
38
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
32
39
  pageCount: undefined
33
40
  })));
34
- expect(wrapper.find(PageSelect).length).toEqual(0);
35
- expect(wrapper.find(PageSizeSelect).length).toEqual(1);
41
+ expect(queryByTestId('dhis2-uiwidgets-pagination-page-select')).not.toBeInTheDocument();
42
+ expect(getByTestId('dhis2-uiwidgets-pagination-pagesize')).toBeInTheDocument();
36
43
  });
37
44
  it('renders without a PageSelect when pageCount is 1', () => {
38
- const wrapper = shallow( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
45
+ const {
46
+ getByTestId,
47
+ queryByTestId
48
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
39
49
  pageCount: 1
40
50
  })));
41
- expect(wrapper.find(PageSelect).length).toEqual(0);
42
- expect(wrapper.find(PageSizeSelect).length).toEqual(1);
51
+ expect(queryByTestId('dhis2-uiwidgets-pagination-page-select')).not.toBeInTheDocument();
52
+ expect(getByTestId('dhis2-uiwidgets-pagination-pagesize')).toBeInTheDocument();
43
53
  });
44
54
  it('renders without a PageSelect when pageCount is over 2000', () => {
45
- const wrapper = shallow( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
55
+ const {
56
+ getByTestId,
57
+ queryByTestId
58
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
46
59
  pageCount: 2001
47
60
  })));
48
- expect(wrapper.find(PageSelect).length).toEqual(0);
49
- expect(wrapper.find(PageSizeSelect).length).toEqual(1);
61
+ expect(queryByTestId('dhis2-uiwidgets-pagination-page-select')).not.toBeInTheDocument();
62
+ expect(getByTestId('dhis2-uiwidgets-pagination-pagesize')).toBeInTheDocument();
50
63
  });
51
64
  it('renders without a PageSizeSelect when hidePageSizeSelect is true', () => {
52
- const wrapper = shallow( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
65
+ const {
66
+ getByTestId,
67
+ queryByTestId
68
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
53
69
  hidePageSizeSelect: true
54
70
  })));
55
- expect(wrapper.find(PageSelect).length).toEqual(1);
56
- expect(wrapper.find(PageSizeSelect).length).toEqual(0);
71
+ expect(queryByTestId('dhis2-uiwidgets-pagination-pagesize')).not.toBeInTheDocument();
72
+ expect(getByTestId('dhis2-uiwidgets-pagination-page-select')).toBeInTheDocument();
57
73
  });
58
74
  it('renders without PageSelect and PageSizeSelect when both are true', () => {
59
- const wrapper = shallow( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
75
+ const {
76
+ queryByTestId
77
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
60
78
  hidePageSelect: true,
61
79
  hidePageSizeSelect: true
62
80
  })));
63
- expect(wrapper.find(PageSelect).length).toEqual(0);
64
- expect(wrapper.find(PageSizeSelect).length).toEqual(0);
81
+ expect(queryByTestId('dhis2-uiwidgets-pagination-pagesize')).not.toBeInTheDocument();
82
+ expect(queryByTestId('dhis2-uiwidgets-pagination-page-select')).not.toBeInTheDocument();
83
+ });
84
+ it('enables all elements when disabled is falsy', () => {
85
+ const {
86
+ getByTestId,
87
+ getByRole
88
+ } = render( /*#__PURE__*/React.createElement(Pagination, props));
89
+ expect(getByTestId('dhis2-uiwidgets-pagination-pagesize').querySelector('.select .root')).not.toHaveClass('disabled');
90
+ expect(getByTestId('dhis2-uiwidgets-pagination-summary').querySelector('span')).not.toHaveClass('inactive');
91
+ expect(getByTestId('dhis2-uiwidgets-pagination-page-select').querySelector('.select .root')).not.toHaveClass('disabled');
92
+ expect(getByRole('button', {
93
+ name: 'Previous'
94
+ })).not.toBeDisabled();
95
+ expect(getByRole('button', {
96
+ name: 'Next'
97
+ })).not.toBeDisabled();
98
+ });
99
+ it('disables all elements when disabled is true', () => {
100
+ const {
101
+ getByTestId,
102
+ getByRole
103
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, {
104
+ disabled: true
105
+ })));
106
+ expect(getByTestId('dhis2-uiwidgets-pagination-pagesize').querySelector('.select .root')).toHaveClass('disabled');
107
+ expect(getByTestId('dhis2-uiwidgets-pagination-summary').querySelector('span')).toHaveClass('inactive');
108
+ expect(getByTestId('dhis2-uiwidgets-pagination-page-select').querySelector('.select .root')).toHaveClass('disabled');
109
+ expect(getByRole('button', {
110
+ name: 'Previous'
111
+ })).toBeDisabled();
112
+ expect(getByRole('button', {
113
+ name: 'Next'
114
+ })).toBeDisabled();
115
+ });
116
+ it('disables previous button when on the first page', () => {
117
+ const {
118
+ getByRole
119
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, mockPagers.atFirstPage, {
120
+ onPageChange: () => {},
121
+ onPageSizeChange: () => {}
122
+ })));
123
+ expect(getByRole('button', {
124
+ name: 'Previous'
125
+ })).toBeDisabled();
126
+ expect(getByRole('button', {
127
+ name: 'Next'
128
+ })).not.toBeDisabled();
129
+ });
130
+ it('disables next button when on the last page', () => {
131
+ const {
132
+ getByRole
133
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, mockPagers.atLastPage, {
134
+ onPageChange: () => {},
135
+ onPageSizeChange: () => {}
136
+ })));
137
+ expect(getByRole('button', {
138
+ name: 'Previous'
139
+ })).not.toBeDisabled();
140
+ expect(getByRole('button', {
141
+ name: 'Next'
142
+ })).toBeDisabled();
65
143
  });
66
144
  });
67
145
  describe('Pagination without total and totalPages', () => {
68
146
  const props = { ...mockPagers.noTotal,
147
+ pageLength: mockPagers.noTotal.pageSize,
69
148
  onPageChange: () => {},
70
149
  onPageSizeChange: () => {}
71
150
  };
72
151
  it('renders without errors', () => {
73
- shallow( /*#__PURE__*/React.createElement(Pagination, props));
152
+ render( /*#__PURE__*/React.createElement(Pagination, props));
74
153
  });
75
154
  it('renders with a PageSizeSelect but without a PageSelect', () => {
76
- const wrapper = shallow( /*#__PURE__*/React.createElement(Pagination, props));
77
- expect(wrapper.find(PageSizeSelect).length).toEqual(1);
78
- expect(wrapper.find(PageSelect).length).toEqual(0);
155
+ const {
156
+ queryByTestId,
157
+ getByTestId
158
+ } = render( /*#__PURE__*/React.createElement(Pagination, props));
159
+ expect(getByTestId('dhis2-uiwidgets-pagination-pagesize')).toBeInTheDocument();
160
+ expect(queryByTestId('dhis2-uiwidgets-pagination-page-select')).not.toBeInTheDocument();
161
+ });
162
+ it('prevents forward navigation when on the last page', () => {
163
+ const {
164
+ getByRole
165
+ } = render( /*#__PURE__*/React.createElement(Pagination, _extends({}, props, mockPagers.noTotalAtLastPage)));
166
+ expect(getByRole('button', {
167
+ name: 'Previous'
168
+ })).not.toBeDisabled();
169
+ expect(getByRole('button', {
170
+ name: 'Next'
171
+ })).toBeDisabled();
79
172
  });
80
173
  });
81
174
  });
@@ -2,13 +2,15 @@ import i18n from './locales/index.js';
2
2
 
3
3
  const isValidNumber = input => typeof input === 'number' && !isNaN(input);
4
4
 
5
- export const getDefaultPageSummaryText = ({
6
- firstItem,
7
- lastItem,
8
- page,
9
- pageCount,
10
- total
11
- }) => {
5
+ export const getDefaultPageSummaryText = _ref => {
6
+ let {
7
+ firstItem,
8
+ lastItem,
9
+ page,
10
+ pageCount,
11
+ total
12
+ } = _ref;
13
+
12
14
  if (isValidNumber(total) && isValidNumber(lastItem)) {
13
15
  return i18n.t('Page {{page}} of {{pageCount}}, items {{firstItem}}-{{lastItem}} of {{total}}', {
14
16
  page,
@@ -1,10 +1,11 @@
1
- export const getItemRange = ({
2
- isLastPage,
3
- page,
4
- pageLength,
5
- pageSize,
6
- total
7
- }) => {
1
+ export const getItemRange = _ref => {
2
+ let {
3
+ isLastPage,
4
+ page,
5
+ pageLength,
6
+ pageSize,
7
+ total
8
+ } = _ref;
8
9
  // page is 1-based
9
10
  let firstItem = (page - 1) * pageSize + 1;
10
11
  let lastItem = firstItem + pageSize - 1;