Skip to content

Commit

Permalink
[setup] Misc EuiTablePaginationCleanup
Browse files Browse the repository at this point in the history
- convert tests to RTL

- remove unnecessary `() => {}` callback default (since prop is not required), use optional chaining instead
  • Loading branch information
cee-chen committed Jul 14, 2023
1 parent 98196ee commit cc1a917
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiTablePagination is rendered 1`] = `
exports[`EuiTablePagination hides the per page options 1`] = `
<div
class="euiFlexGroup eui-xScroll emotion-euiFlexGroup-wrap-s-spaceBetween-center-row"
>
<div
class="euiFlexItem emotion-euiFlexItem-growZero"
>
<div
class="euiPopover emotion-euiPopover"
>
<div
class="euiPopover__anchor css-16vtueo-render"
>
<button
class="euiButtonEmpty emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text"
data-test-subj="tablePaginationPopoverButton"
type="button"
>
<span
class="euiButtonEmpty__content emotion-euiButtonDisplayContent"
>
<span
class="eui-textTruncate euiButtonEmpty__text"
>
Rows per page: 50
</span>
<span
color="inherit"
data-euiicon-type="arrowDown"
/>
</span>
</button>
</div>
</div>
</div>
/>
<div
class="euiFlexItem emotion-euiFlexItem-growZero"
>
Expand Down Expand Up @@ -191,13 +163,43 @@ exports[`EuiTablePagination is rendered 1`] = `
</div>
`;

exports[`EuiTablePagination is rendered when hiding the per page options 1`] = `
exports[`EuiTablePagination renders 1`] = `
<div
class="euiFlexGroup eui-xScroll emotion-euiFlexGroup-wrap-s-spaceBetween-center-row"
>
<div
class="euiFlexItem emotion-euiFlexItem-growZero"
/>
>
<div
class="euiPopover emotion-euiPopover"
>
<div
class="euiPopover__anchor css-16vtueo-render"
>
<button
class="euiButtonEmpty emotion-euiButtonDisplay-euiButtonEmpty-xs-empty-text"
data-test-subj="tablePaginationPopoverButton"
type="button"
>
<span
class="euiButtonEmpty__content emotion-euiButtonDisplayContent"
>
<span
class="eui-textTruncate euiButtonEmpty__text"
>
Rows per page
:
50
</span>
<span
color="inherit"
data-euiicon-type="arrowDown"
/>
</span>
</button>
</div>
</div>
</div>
<div
class="euiFlexItem emotion-euiFlexItem-growZero"
>
Expand Down
21 changes: 11 additions & 10 deletions src/components/table/table_pagination/table_pagination.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import React from 'react';
import { render } from 'enzyme';
import { render } from '../../../test/rtl';
import { requiredProps } from '../../../test/required_props';

import { EuiTablePagination } from './table_pagination';
Expand All @@ -18,28 +18,29 @@ describe('EuiTablePagination', () => {
pageCount: 5,
onChangePage: jest.fn(),
};
test('is rendered', () => {
const component = render(

it('renders', () => {
const { container } = render(
<EuiTablePagination {...requiredProps} {...paginationProps} />
);

expect(component).toMatchSnapshot();
expect(container.firstChild).toMatchSnapshot();
});

test('is rendered when hiding the per page options', () => {
const component = render(
it('hides the per page options', () => {
const { container } = render(
<EuiTablePagination
{...requiredProps}
{...paginationProps}
showPerPageOptions={false}
/>
);

expect(component).toMatchSnapshot();
expect(container.firstChild).toMatchSnapshot();
});

test('renders a "show all" itemsPerPage option', () => {
const component = render(
it('renders a "show all" itemsPerPage option', () => {
const { container } = render(
<EuiTablePagination
{...requiredProps}
{...paginationProps}
Expand All @@ -48,6 +49,6 @@ describe('EuiTablePagination', () => {
/>
);

expect(component).toMatchSnapshot();
expect(container.firstChild).toMatchSnapshot();
});
});
4 changes: 2 additions & 2 deletions src/components/table/table_pagination/table_pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const EuiTablePagination: FunctionComponent<EuiTablePaginationProps> = ({
itemsPerPage = 50,
itemsPerPageOptions = [10, 20, 50, 100],
showPerPageOptions = true,
onChangeItemsPerPage = () => {},
onChangeItemsPerPage,
onChangePage,
pageCount,
...rest
Expand Down Expand Up @@ -105,7 +105,7 @@ export const EuiTablePagination: FunctionComponent<EuiTablePaginationProps> = ({
icon={itemsPerPageOption === itemsPerPage ? 'check' : 'empty'}
onClick={() => {
closePopover();
onChangeItemsPerPage(itemsPerPageOption);
onChangeItemsPerPage?.(itemsPerPageOption);
}}
data-test-subj={`tablePagination-${itemsPerPageOption}-rows`}
>
Expand Down

0 comments on commit cc1a917

Please sign in to comment.