Skip to content

Commit b2e1a50

Browse files
committed
Add unit tests for all themed inputs.
1 parent 4c6a503 commit b2e1a50

21 files changed

+135
-9
lines changed

packages/ra-ui-materialui/src/input/BooleanInput.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ResourceContextProvider, testDataProvider } from 'ra-core';
55
import { AdminContext } from '../AdminContext';
66
import { SimpleForm } from '../form';
77
import { BooleanInput } from './BooleanInput';
8+
import { Themed } from './BooleanInput.stories';
89

910
describe('<BooleanInput />', () => {
1011
const defaultProps = {
@@ -185,4 +186,9 @@ describe('<BooleanInput />', () => {
185186
expect(screen.queryByText('ra.validation.error')).not.toBeNull();
186187
});
187188
});
189+
190+
it('should be customized by a theme', async () => {
191+
render(<Themed />);
192+
const input = await screen.findByTestId('themed');
193+
});
188194
});

packages/ra-ui-materialui/src/input/BooleanInput.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ export const Themed = () => (
8383
theme={deepmerge(createTheme(), {
8484
components: {
8585
RaBooleanInput: {
86+
defaultProps: {
87+
'data-testid': 'themed',
88+
},
8689
styleOverrides: {
8790
root: {
8891
color: 'red',
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
4+
import { Themed } from './DatagridInput.stories';
5+
6+
describe('<DatagridInput />', () => {
7+
it('should be customized by a theme', async () => {
8+
render(<Themed />);
9+
const input = await screen.findByTestId('themed');
10+
});
11+
});

packages/ra-ui-materialui/src/input/DatagridInput.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ export const Themed = () => (
167167
theme={deepmerge(createTheme(), {
168168
components: {
169169
RaDatagridInput: {
170+
defaultProps: {
171+
'data-testid': 'themed',
172+
},
170173
styleOverrides: {
171174
root: {
172175
['& .MuiTypography-root']: {

packages/ra-ui-materialui/src/input/DatagridInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
FilterContext,
2626
} from '../list';
2727
import { Pagination as DefaultPagination } from '../list/pagination';
28+
import { sanitizeInputRestProps } from './sanitizeInputRestProps';
2829

2930
const defaultPagination = <DefaultPagination />;
3031

@@ -160,7 +161,7 @@ export const DatagridInput = (inProps: DatagridInputProps) => {
160161
) : null}
161162
{!fieldState.error && !fetchError && (
162163
<>
163-
<Datagrid {...rest} />
164+
<Datagrid {...sanitizeInputRestProps(rest)} />
164165
{pagination !== false && pagination}
165166
</>
166167
)}

packages/ra-ui-materialui/src/input/DateInput.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
ExternalChanges,
1515
ExternalChangesWithParse,
1616
Parse,
17+
Themed,
1718
} from './DateInput.stories';
1819

1920
describe('<DateInput />', () => {
@@ -319,4 +320,9 @@ describe('<DateInput />', () => {
319320
await screen.findByText('Required');
320321
});
321322
});
323+
324+
it('should be customized by a theme', async () => {
325+
render(<Themed />);
326+
const input = await screen.findByTestId('themed');
327+
});
322328
});

packages/ra-ui-materialui/src/input/DateInput.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ export const Themed = ({
155155
theme={deepmerge(createTheme(), {
156156
components: {
157157
RaDateInput: {
158+
defaultProps: {
159+
'data-testid': 'themed',
160+
},
158161
styleOverrides: {
159162
root: {
160163
['& input']: {

packages/ra-ui-materialui/src/input/DateTimeInput.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SaveButton } from '../button';
1414
import {
1515
ExternalChanges,
1616
ExternalChangesWithParse,
17+
Themed,
1718
} from './DateTimeInput.stories';
1819

1920
describe('<DateTimeInput />', () => {
@@ -328,4 +329,9 @@ describe('<DateTimeInput />', () => {
328329
});
329330
});
330331
});
332+
333+
it('should be customized by a theme', async () => {
334+
render(<Themed />);
335+
const input = await screen.findByTestId('themed');
336+
});
331337
});

packages/ra-ui-materialui/src/input/DateTimeInput.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ export const Themed = () => (
103103
theme={deepmerge(createTheme(), {
104104
components: {
105105
RaDateTimeInput: {
106+
defaultProps: {
107+
'data-testid': 'themed',
108+
},
106109
styleOverrides: {
107110
root: {
108111
['& input']: {

packages/ra-ui-materialui/src/input/NumberInput.spec.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { AdminContext } from '../AdminContext';
99
import { SaveButton } from '../button';
1010
import { SimpleForm, Toolbar } from '../form';
1111
import { required, ResourceContextProvider } from 'ra-core';
12+
import { Themed } from './NumberInput.stories';
1213

1314
describe('<NumberInput />', () => {
1415
const defaultProps = {
@@ -672,4 +673,9 @@ describe('<NumberInput />', () => {
672673
});
673674
});
674675
});
676+
677+
it('should be customized by a theme', async () => {
678+
render(<Themed />);
679+
const input = await screen.findByTestId('themed');
680+
});
675681
});

0 commit comments

Comments
 (0)