File size: 2,989 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React from 'react';
import { spy } from 'sinon';
import { mount } from 'enzyme';
import { assert } from 'chai';
import MuiTableFooter from '@mui/material/TableFooter';
import getTextLabels from '../src/textLabels';
import TableFooter from '../src/components/TableFooter';
import JumpToPage from '../src/components/JumpToPage';

describe('<TableFooter />', function() {
  let options;
  const changeRowsPerPage = spy();
  const changePage = spy();
  before(() => {
    options = {
      rowsPerPageOptions: [5, 10, 15],
      textLabels: getTextLabels(),
    };
  });

  it('should render a table footer', () => {
    const mountWrapper = mount(
      <TableFooter
        options={options}
        rowCount={100}
        page={1}
        rowsPerPage={10}
        changeRowsPerPage={changeRowsPerPage}
        changePage={changePage}
      />,
    );

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

  it('should render a table footer with customFooter', () => {
    const customOptions = {
      rowsPerPageOptions: [5, 10, 15],
      textLabels: getTextLabels(),
      customFooter: (rowCount, page, rowsPerPage, changeRowsPerPage, changePage, textLabels) => {
        return (
          <MuiTableFooter
            changePage={changePage}
            changeRowsPerPage={changeRowsPerPage}
            page={page}
            rowCount={rowCount}
            rowsPerPage={rowsPerPage}
            labelRowsPerPage={textLabels.rowsPerPage}
          />
        );
      },
    };

    const mountWrapper = mount(
      <TableFooter
        options={customOptions}
        rowCount={100}
        page={1}
        rowsPerPage={10}
        changeRowsPerPage={changeRowsPerPage}
        changePage={changePage}
      />,
    );

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

  it('should not render a table footer', () => {
    const nonPageOption = {
      rowsPerPageOptions: [5, 10, 15],
      textLabels: getTextLabels(),
      pagination: false,
    };

    const mountWrapper = mount(
      <TableFooter
        options={nonPageOption}
        rowCount={100}
        page={1}
        rowsPerPage={10}
        changeRowsPerPage={changeRowsPerPage}
        changePage={changePage}
      />,
    );

    const actualResult = mountWrapper.find(MuiTableFooter);
    assert.strictEqual(actualResult.length, 0);
  });

  it('should render a JumpToPage component', () => {
    const options = {
      rowsPerPageOptions: [5, 10, 15],
      textLabels: getTextLabels(),
      jumpToPage: true,
    };

    const mountWrapper = mount(
      <TableFooter
        options={options}
        rowCount={100}
        page={1}
        rowsPerPage={10}
        changeRowsPerPage={changeRowsPerPage}
        changePage={changePage}
      />,
    );

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