Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Sep 19, 2018
1 parent a407060 commit a1a93bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/ra-core/src/sideEffect/recordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export function* handleLocationChange({ payload }) {

previousLocation = payload;

yield put(destroy(REDUX_FORM_NAME));
yield put(resetForm());
yield put(destroy(REDUX_FORM_NAME));
}

export default function* recordForm() {
Expand Down
15 changes: 7 additions & 8 deletions packages/ra-core/src/sideEffect/recordForm.spec.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import { put } from 'redux-saga/effects';
import { LOCATION_CHANGE } from 'react-router-redux';
import { destroy } from 'redux-form';
import { resetForm } from '../actions/formActions';
import { resetForm, BEFORE_LOCATION_CHANGE } from '../actions/formActions';
import { handleLocationChange } from './recordForm';
import { REDUX_FORM_NAME } from '../form/constants';

describe('recordForm saga', () => {
it('resets the form when the LOCATION_CHANGE action has no state', () => {
it('resets the form when the BEFORE_LOCATION_CHANGE action has no state', () => {
const saga = handleLocationChange({
type: LOCATION_CHANGE,
type: BEFORE_LOCATION_CHANGE,
payload: { pathname: '/comments/create' },
});

expect(saga.next().value).toEqual(put(resetForm()));
expect(saga.next().value).toEqual(put(destroy(REDUX_FORM_NAME)));
});

it('does not reset the form when the LOCATION_CHANGE action state has skipFormReset set to true', () => {
it('does not reset the form when the BEFORE_LOCATION_CHANGE action state has skipFormReset set to true', () => {
const saga = handleLocationChange({
type: LOCATION_CHANGE,
type: BEFORE_LOCATION_CHANGE,
payload: {
pathname: '/comments/create/2',
state: { skipFormReset: true },
Expand All @@ -30,7 +29,7 @@ describe('recordForm saga', () => {

it('does not reset the form when navigating to same location', () => {
const saga = handleLocationChange({
type: LOCATION_CHANGE,
type: BEFORE_LOCATION_CHANGE,
payload: {
pathname: '/comments/create/2',
},
Expand All @@ -40,7 +39,7 @@ describe('recordForm saga', () => {
saga.next();

const saga2 = handleLocationChange({
type: LOCATION_CHANGE,
type: BEFORE_LOCATION_CHANGE,
payload: {
pathname: '/comments/create/2',
},
Expand Down

0 comments on commit a1a93bc

Please sign in to comment.