File size: 1,700 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react';
import { spy } from 'sinon';
import { mount, shallow } from 'enzyme';
import { assert } from 'chai';
import MuiTablePagination from '@mui/material/TablePagination';
import getTextLabels from '../src/textLabels';
import TablePagination from '../src/components/TablePagination';

describe('<TablePagination />', function() {
  let options;

  before(() => {
    options = {
      rowsPerPageOptions: [5, 10, 15],
      textLabels: getTextLabels(),
    };
  });

  it('should render a table footer with pagination', () => {
    const mountWrapper = mount(<TablePagination options={options} count={100} page={1} rowsPerPage={10} />);

    const actualResult = mountWrapper.find(MuiTablePagination);
    assert.strictEqual(actualResult.length, 1);
  });

  it('should trigger changePage prop callback when page is changed', () => {
    const changePage = spy();
    const wrapper = mount(
      <TablePagination options={options} count={100} page={1} rowsPerPage={10} changePage={changePage} />,
    );

    wrapper
      .find('#pagination-next')
      .at(0)
      .simulate('click');
    wrapper.unmount();

    assert.strictEqual(changePage.callCount, 1);
  });

  it('should correctly change page to be in bounds if out of bounds page was set', () => {
    // Set a page that is too high for the count and rowsPerPage
    const mountWrapper = mount(<TablePagination options={options} count={5} page={1} rowsPerPage={10} />);
    const actualResult = mountWrapper.find(MuiTablePagination).props().page;

    // material-ui v3 does some internal calculations to protect against out of bounds pages, but material v4 does not
    assert.strictEqual(actualResult, 0);
  });
});