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

Fix simple project UserEdit save usage #8435

Merged
merged 5 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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