Skip to content

Commit

Permalink
fis unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto authored and djhi committed Aug 9, 2019
1 parent fc087e2 commit a3972de
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
16 changes: 11 additions & 5 deletions packages/ra-ui-materialui/src/list/FilterButton.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import expect from 'expect';
import { render, cleanup, fireEvent } from '@testing-library/react';
import { render, cleanup, fireEvent } from 'react-testing-library';
import { ThemeProvider } from '@material-ui/styles';
import { createMuiTheme } from '@material-ui/core';

import { FilterButton } from './FilterButton';
import TextInput from '../input/TextInput';

const theme = createMuiTheme();

describe('<FilterButton />', () => {
const defaultProps = {
resource: 'post',
Expand Down Expand Up @@ -36,10 +40,12 @@ describe('<FilterButton />', () => {
<TextInput source="Returned" label="Returned" />
);
const { getByLabelText, queryByText } = render(
<FilterButton
{...defaultProps}
filters={defaultProps.filters.concat(hiddenFilter)}
/>
<ThemeProvider theme={theme}>
<FilterButton
{...defaultProps}
filters={defaultProps.filters.concat(hiddenFilter)}
/>
</ThemeProvider>
);

fireEvent.click(getByLabelText('ra.action.add_filter'));
Expand Down
54 changes: 46 additions & 8 deletions packages/ra-ui-materialui/src/list/Pagination.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';
import expect from 'expect';
import { render, cleanup } from '@testing-library/react';
import { render, cleanup } from 'react-testing-library';
import { ThemeProvider } from '@material-ui/styles';
import { createMuiTheme } from '@material-ui/core';

import Pagination from './Pagination';
import DeviceTestWrapper from '../layout/DeviceTestWrapper';

const theme = createMuiTheme();

describe('<Pagination />', () => {
const defaultProps = {
width: 'lg',
Expand All @@ -18,21 +22,27 @@ describe('<Pagination />', () => {
describe('no results mention', () => {
it('should display a pagination limit when there is no result', () => {
const { queryByText } = render(
<Pagination {...defaultProps} total={0} />
<ThemeProvider theme={theme}>
<Pagination {...defaultProps} total={0} />
</ThemeProvider>
);
expect(queryByText('ra.navigation.no_results')).not.toBeNull();
});

it('should not display a pagination limit when there are results', () => {
const { queryByText } = render(
<Pagination {...defaultProps} total={1} />
<ThemeProvider theme={theme}>
<Pagination {...defaultProps} total={1} />
</ThemeProvider>
);
expect(queryByText('ra.navigation.no_results')).toBeNull();
});

it('should not display a pagination limit on an out of bounds page', () => {
const { queryByText } = render(
<Pagination {...defaultProps} total={10} page={2} />
<ThemeProvider theme={theme}>
<Pagination {...defaultProps} total={10} page={2} />
</ThemeProvider>
);
// mui TablePagination displays a warning in that case, and that's normal
expect(queryByText('ra.navigation.no_results')).toBeNull();
Expand All @@ -42,25 +52,53 @@ describe('<Pagination />', () => {
describe('Pagination buttons', () => {
it('should display a next button when there are more results', () => {
const { queryByText } = render(
<Pagination {...defaultProps} perPage={1} total={2} page={1} />
<ThemeProvider theme={theme}>
<Pagination
{...defaultProps}
perPage={1}
total={2}
page={1}
/>
</ThemeProvider>
);
expect(queryByText('ra.navigation.next')).not.toBeNull();
});
it('should not display a next button when there are no more results', () => {
const { queryByText } = render(
<Pagination {...defaultProps} perPage={1} total={2} page={2} />
<ThemeProvider theme={theme}>
<Pagination
{...defaultProps}
perPage={1}
total={2}
page={2}
/>
</ThemeProvider>
);
expect(queryByText('ra.navigation.next')).toBeNull();
});
it('should display a prev button when there are previous results', () => {
const { queryByText } = render(
<Pagination {...defaultProps} perPage={1} total={2} page={2} />
<ThemeProvider theme={theme}>
<Pagination
{...defaultProps}
perPage={1}
total={2}
page={2}
/>
</ThemeProvider>
);
expect(queryByText('ra.navigation.prev')).not.toBeNull();
});
it('should not display a prev button when there are no previous results', () => {
const { queryByText } = render(
<Pagination {...defaultProps} perPage={1} total={2} page={1} />
<ThemeProvider theme={theme}>
<Pagination
{...defaultProps}
perPage={1}
total={2}
page={1}
/>
</ThemeProvider>
);
expect(queryByText('ra.navigation.prev')).toBeNull();
});
Expand Down

0 comments on commit a3972de

Please sign in to comment.