Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed May 12, 2021
1 parent 84d6aca commit fa47212
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/ra-ui-materialui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"final-form-arrays": "^3.0.2",
"ignore-styles": "~5.0.1",
"ra-core": "^3.15.1",
"ra-test": "^3.15.1",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react-final-form": "^6.5.2",
Expand Down
24 changes: 22 additions & 2 deletions packages/ra-ui-materialui/src/input/DateInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as React from 'react';
import expect from 'expect';
import { render, fireEvent } from '@testing-library/react';
import { Form } from 'react-final-form';
import { required, FormWithRedirect } from 'ra-core';
import { renderWithRedux } from 'ra-test';
import format from 'date-fns/format';

import DateInput from './DateInput';
import { Form } from 'react-final-form';
import { required } from 'ra-core';
import { FormApi } from 'final-form';

describe('<DateInput />', () => {
const defaultProps = {
Expand All @@ -24,6 +27,23 @@ describe('<DateInput />', () => {
);
});

it('should not make the form dirty on initialization', () => {
const publishedAt = new Date().toISOString();
let formApi: FormApi;
const { getByDisplayValue } = renderWithRedux(
<FormWithRedirect
onSubmit={jest.fn}
record={{ id: 1, publishedAt }}
render={({ form }) => {
formApi = form;
return <DateInput {...defaultProps} />;
}}
/>
);
expect(getByDisplayValue(format(publishedAt, 'YYYY-MM-DD')));
expect(formApi.getState().dirty).toEqual(false);
});

it('should call `input.onChange` method when changed', () => {
let formApi;
const { getByLabelText } = render(
Expand Down

0 comments on commit fa47212

Please sign in to comment.