Skip to content

Commit

Permalink
[WIP] Fix create to edit form values
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Sep 19, 2018
1 parent 38d8030 commit 7c3c027
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
29 changes: 28 additions & 1 deletion cypress/integration/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Create Page', () => {
);
});

it('should redirect to show page after create success', () => {
it.only('should redirect to edit page after create success', () => {
const values = [
{
type: 'input',
Expand All @@ -79,6 +79,33 @@ describe('Create Page', () => {

CreatePage.setValues(values);
CreatePage.submit();
EditPage.waitUntilVisible();
cy.get(EditPage.elements.input('title')).should(el =>
expect(el).to.have.value('Test title')
);
cy.get(EditPage.elements.input('teaser')).should(el =>
expect(el).to.have.value('Test teaser')
);

EditPage.delete();
});

it('should redirect to show page after create success with "Save and show"', () => {
const values = [
{
type: 'input',
name: 'title',
value: 'Test title',
},
{
type: 'textarea',
name: 'teaser',
value: 'Test teaser',
},
];

CreatePage.setValues(values);
CreatePage.submitAndShow();
ShowPage.waitUntilVisible();
EditPage.navigate();
EditPage.delete();
Expand Down
11 changes: 10 additions & 1 deletion cypress/support/CreatePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ export default url => ({
inputs: `.ra-input`,
snackbar: 'div[role="alertdialog"]',
submitButton: ".create-page button[type='submit']",
submitAndAddButton:
submitAndShowButton:
".create-page form>div:last-child button[type='button']:nth-child(2)",
submitAndAddButton:
".create-page form>div:last-child button[type='button']:nth-child(3)",
submitCommentable:
".create-page form>div:last-child button[type='button']:last-child",
descInput: '.ql-editor',
Expand Down Expand Up @@ -55,6 +57,13 @@ export default url => ({
cy.wait(200); // let the notification disappear (could block further submits)
},

submitAndShow() {
cy.get(this.elements.submitAndShowButton).click();
cy.get(this.elements.snackbar);
cy.get(this.elements.body).click(); // dismiss notification
cy.wait(200); // let the notification disappear (could block further submits)
},

submitAndAdd() {
cy.get(this.elements.submitAndAddButton).click();
cy.get(this.elements.snackbar);
Expand Down
1 change: 1 addition & 0 deletions examples/simple/src/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const messages = {
title: 'Post "%{title}"',
},
action: {
save_and_edit: 'Save and Edit',
save_and_add: 'Save and Add',
save_and_show: 'Save and Show',
save_with_average_note: 'Save with Note',
Expand Down
8 changes: 7 additions & 1 deletion examples/simple/src/posts/PostCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,16 @@ const SaveWithNoteButton = connect(

const PostCreateToolbar = props => (
<Toolbar {...props}>
<SaveButton
label="post.action.save_and_edit"
redirect="edit"
submitOnEnter={true}
/>
<SaveButton
label="post.action.save_and_show"
redirect="show"
submitOnEnter={true}
submitOnEnter={false}
variant="flat"
/>
<SaveButton
label="post.action.save_and_add"
Expand Down
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 @@ -19,8 +19,8 @@ export function* handleLocationChange({ payload }) {

previousLocation = payload;

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

export default function* recordForm() {
Expand Down

0 comments on commit 7c3c027

Please sign in to comment.