Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SimpleFormIterator label function #6305

Merged
merged 5 commits into from
Jun 22, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update tests for SimpleFormIterator
iamstiil committed May 25, 2021
commit 311de7fd3f859af479f0abeb1b2403a56b2b5ed4
41 changes: 34 additions & 7 deletions packages/ra-ui-materialui/src/form/SimpleFormIterator.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { fireEvent, waitFor, getByText } from '@testing-library/react';
import * as React from 'react';
import { ThemeProvider } from '@material-ui/core';
import { createMuiTheme } from '@material-ui/core/styles';
import { fireEvent, getByText, waitFor } from '@testing-library/react';
import expect from 'expect';
import { SaveContextProvider, SideEffectContextProvider } from 'ra-core';
import { renderWithRedux } from 'ra-test';
import { ThemeProvider } from '@material-ui/core';
import { createMuiTheme } from '@material-ui/core/styles';

import SimpleFormIterator from './SimpleFormIterator';
import TextInput from '../input/TextInput';
import * as React from 'react';
import { ArrayInput } from '../input';
import TextInput from '../input/TextInput';
import SimpleForm from './SimpleForm';
import SimpleFormIterator from './SimpleFormIterator';

const theme = createMuiTheme();

@@ -499,6 +498,34 @@ describe('<SimpleFormIterator />', () => {
expect(getByText('Custom Remove Button')).not.toBeNull();
});

it('should display custom row label', () => {
const { getByText } = renderWithRedux(
<ThemeProvider theme={theme}>
<SaveContextProvider value={saveContextValue}>
<SideEffectContextProvider value={sideEffectValue}>
<SimpleForm
record={{
id: 'whatever',
emails: [{ email: 'foo' }, { email: 'bar' }],
}}
>
<ArrayInput source="emails">
<SimpleFormIterator
labelFn={index => `3.${index}`}
>
<TextInput source="email" />
</SimpleFormIterator>
</ArrayInput>
</SimpleForm>
</SideEffectContextProvider>
</SaveContextProvider>
</ThemeProvider>
);

expect(getByText('3.0')).toBeDefined();
expect(getByText('3.1')).toBeDefined();
});

it('should call the onClick method when the custom add button is clicked', async () => {
const onClick = jest.fn();
const { getByText } = renderWithRedux(