From b092b4c53d49bb98a71224da6d0eb936a1f7b6b5 Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:58:34 +0200 Subject: [PATCH 1/4] Fix useDelete tests --- packages/ra-core/src/dataProvider/useDelete.spec.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/ra-core/src/dataProvider/useDelete.spec.tsx b/packages/ra-core/src/dataProvider/useDelete.spec.tsx index 0a6561589a2..de25687c605 100644 --- a/packages/ra-core/src/dataProvider/useDelete.spec.tsx +++ b/packages/ra-core/src/dataProvider/useDelete.spec.tsx @@ -267,22 +267,22 @@ describe('useDelete', () => { }); describe('mutationMode', () => { - it('when pessimistic, displays result and success side effects when dataProvider promise resolves', async () => { + it.only('when pessimistic, displays result and success side effects when dataProvider promise resolves', async () => { jest.spyOn(console, 'log').mockImplementation(() => {}); render(); screen.getByText('Delete first post').click(); await waitFor(() => { expect(screen.queryByText('success')).toBeNull(); - expect(screen.queryByText('Hello')).not.toBeNull(); - expect(screen.queryByText('World')).not.toBeNull(); expect(screen.queryByText('mutating')).not.toBeNull(); }); + expect(screen.queryByText('Hello')).not.toBeNull(); + expect(screen.queryByText('World')).not.toBeNull(); await waitFor(() => { expect(screen.queryByText('success')).not.toBeNull(); - expect(screen.queryByText('Hello')).toBeNull(); - expect(screen.queryByText('World')).not.toBeNull(); expect(screen.queryByText('mutating')).toBeNull(); }); + expect(screen.queryByText('Hello')).toBeNull(); + expect(screen.queryByText('World')).not.toBeNull(); }); it('when pessimistic, displays error and error side effects when dataProvider promise rejects', async () => { jest.spyOn(console, 'log').mockImplementation(() => {}); From b3eae966a579eb395c6fa268f75fc3ce3983c334 Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:59:07 +0200 Subject: [PATCH 2/4] Fix create-react-admin tests --- packages/create-react-admin/src/generateAppTestFile.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/create-react-admin/src/generateAppTestFile.ts b/packages/create-react-admin/src/generateAppTestFile.ts index e14ec07deb3..7802e55873e 100644 --- a/packages/create-react-admin/src/generateAppTestFile.ts +++ b/packages/create-react-admin/src/generateAppTestFile.ts @@ -20,6 +20,9 @@ test("should pass", async () => { ? ` // Sign in + // Ensure the form is fully loaded before interacting with it + await new Promise((resolve) => setTimeout(resolve, 1000)); + fireEvent.change(await screen.findByLabelText("Username *"), { target: { value: "janedoe" }, }); @@ -33,6 +36,9 @@ test("should pass", async () => { // Open the first post fireEvent.click(await screen.findByText("Post 1")); fireEvent.click(await screen.findByText("Edit")); + await screen.findByDisplayValue("Post 1"); + // Ensure the form is fully loaded before interacting with it + await new Promise((resolve) => setTimeout(resolve, 1000)); // Update its title fireEvent.change(await screen.findByDisplayValue("Post 1"), { target: { value: "Post 1 edited" }, @@ -45,6 +51,9 @@ test("should pass", async () => { // Open the first comment fireEvent.click(await screen.findByText("Comment 1")); fireEvent.click(await screen.findByText("Edit")); + await screen.findByDisplayValue("Post 1 edited"); + // Ensure the form is fully loaded before interacting with it + await new Promise((resolve) => setTimeout(resolve, 1000)); // Edit the comment selected post fireEvent.click(await screen.findByDisplayValue("Post 1 edited")); fireEvent.click(await screen.findByText("Post 11")); From 505e64f7a8947ffbce1accf7929437ceda9bae10 Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Tue, 25 Jun 2024 21:52:58 +0200 Subject: [PATCH 3/4] Remove only in tests Co-authored-by: Jean-Baptiste Kaiser --- packages/ra-core/src/dataProvider/useDelete.spec.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ra-core/src/dataProvider/useDelete.spec.tsx b/packages/ra-core/src/dataProvider/useDelete.spec.tsx index de25687c605..f6d5eed43bf 100644 --- a/packages/ra-core/src/dataProvider/useDelete.spec.tsx +++ b/packages/ra-core/src/dataProvider/useDelete.spec.tsx @@ -267,7 +267,7 @@ describe('useDelete', () => { }); describe('mutationMode', () => { - it.only('when pessimistic, displays result and success side effects when dataProvider promise resolves', async () => { + it('when pessimistic, displays result and success side effects when dataProvider promise resolves', async () => { jest.spyOn(console, 'log').mockImplementation(() => {}); render(); screen.getByText('Delete first post').click(); From 7955d97cbeac652537930af404ae6df09e97612e Mon Sep 17 00:00:00 2001 From: Gildas Garcia <1122076+djhi@users.noreply.github.com> Date: Wed, 26 Jun 2024 12:02:26 +0200 Subject: [PATCH 4/4] Reduce dataProvider delay in useDelete pessimistic tests --- .../src/dataProvider/useDelete.pessimistic.stories.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/ra-core/src/dataProvider/useDelete.pessimistic.stories.tsx b/packages/ra-core/src/dataProvider/useDelete.pessimistic.stories.tsx index cf1e6179b36..45a15443d28 100644 --- a/packages/ra-core/src/dataProvider/useDelete.pessimistic.stories.tsx +++ b/packages/ra-core/src/dataProvider/useDelete.pessimistic.stories.tsx @@ -28,7 +28,7 @@ export const SuccessCase = () => { const index = posts.findIndex(p => p.id === params.id); posts.splice(index, 1); resolve({ data: params.previousData }); - }, 1000); + }, 500); }); }, } as any; @@ -94,7 +94,7 @@ export const ErrorCase = () => { return new Promise((resolve, reject) => { setTimeout(() => { reject(new Error('something went wrong')); - }, 1000); + }, 500); }); }, } as any;