Skip to content

Commit

Permalink
Merge pull request #8435 from marmelab/fix-simpleform-users
Browse files Browse the repository at this point in the history
Fix simple project UserEdit save usage
  • Loading branch information
slax57 committed Nov 29, 2022
2 parents 20fdf07 + b1151ba commit 3163326
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
22 changes: 19 additions & 3 deletions cypress/e2e/edit.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('Edit Page', () => {
expect(el).to.have.value('')
);

// This validate the old record values are not kept after we navigated
// This validates the old record values are not kept after we navigated
const currentDate = new Date();
const currentDateString = currentDate.toISOString().slice(0, 10);

Expand Down Expand Up @@ -269,6 +269,23 @@ describe('Edit Page', () => {
});
});

it('should save edited user values', () => {
EditPostPage.navigate();
EditPostPage.logout();
LoginPage.navigate();
LoginPage.login('admin', 'password');
EditUserPage.navigate();
cy.get(EditUserPage.elements.input('name')).should(el =>
expect(el).to.have.value('Annamarie Mayer')
);
EditUserPage.setInputValue('textbox', 'name', 'Annamarie Mayer!');
EditUserPage.submit();
EditUserPage.navigate();
cy.get(EditUserPage.elements.input('name')).should(el =>
expect(el).to.have.value('Annamarie Mayer!')
);
});

it('should persit emptied inputs', () => {
EditPostPage.navigate();
EditPostPage.gotoTab(3);
Expand All @@ -285,8 +302,7 @@ describe('Edit Page', () => {
);
});

// FIXME unskip me when useGetList uses the react-query API
it.skip('should refresh the list when the update fails', () => {
it('should refresh the list when the update fails', () => {
ListPagePosts.navigate();
ListPagePosts.nextPage(); // Ensure the record is visible in the table

Expand Down
6 changes: 4 additions & 2 deletions examples/simple/src/users/UserEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Toolbar,
TopToolbar,
usePermissions,
useSaveContext,
} from 'react-admin';

import Aside from './Aside';
Expand Down Expand Up @@ -42,8 +43,10 @@ const EditActions = () => (
</TopToolbar>
);

const UserEditForm = ({ save, ...props }: { save?: any }) => {
const UserEditForm = () => {
const { permissions } = usePermissions();
const { save } = useSaveContext();

const newSave = values =>
new Promise((resolve, reject) => {
if (values.name === 'test') {
Expand All @@ -61,7 +64,6 @@ const UserEditForm = ({ save, ...props }: { save?: any }) => {
<TabbedForm
defaultValues={{ role: 'user' }}
toolbar={<UserEditToolbar />}
{...props}
onSubmit={newSave}
>
<FormTab label="user.form.summary" path="">
Expand Down

0 comments on commit 3163326

Please sign in to comment.