From 3a348b0bb8cf1edd59cd883afadad496ede12b4d Mon Sep 17 00:00:00 2001 From: Vahid Bazzaz Date: Fri, 30 Jun 2023 14:17:45 +0330 Subject: [PATCH 1/2] fix boxview tests - add cache --- react/src/views/Box/BoxView.test.tsx | 55 ++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/react/src/views/Box/BoxView.test.tsx b/react/src/views/Box/BoxView.test.tsx index 51d98d2af..235e3b975 100644 --- a/react/src/views/Box/BoxView.test.tsx +++ b/react/src/views/Box/BoxView.test.tsx @@ -3,6 +3,7 @@ import { GraphQLError } from "graphql"; import "@testing-library/jest-dom"; import { screen, render, waitFor } from "tests/test-utils"; import userEvent from "@testing-library/user-event"; +import { cache } from "queries/cache"; import BTBox, { UPDATE_NUMBER_OF_ITEMS_IN_BOX_MUTATION, UPDATE_STATE_IN_BOX_MUTATION, @@ -44,6 +45,21 @@ const initialQuery = { }, }; +const initialQueryForChangeNumberOfBoxes = { + request: { + query: BOX_BY_LABEL_IDENTIFIER_AND_ALL_SHIPMENTS_QUERY, + variables: { + labelIdentifier: "1235", + }, + }, + result: { + data: { + box: generateMockBox({ labelIdentifier: "1235", numberOfItems: 31 }), + shipments: null, + }, + }, +}; + const initialQueryForBoxInLegacyLostLocation = { request: { query: BOX_BY_LABEL_IDENTIFIER_AND_ALL_SHIPMENTS_QUERY, @@ -123,13 +139,13 @@ const updateNumberOfItemsMutation = { request: { query: UPDATE_NUMBER_OF_ITEMS_IN_BOX_MUTATION, variables: { - boxLabelIdentifier: "123", + boxLabelIdentifier: "1235", numberOfItems: 32, }, }, result: { data: { - updateBox: generateMockBox({ numberOfItems: 32 }), + updateBox: generateMockBox({ numberOfItems: 32, labelIdentifier: "1235" }), shipments: null, }, }, @@ -395,8 +411,9 @@ it("3.1.2 - Change Number of Items", async () => { const user = userEvent.setup(); render(, { routePath: "/bases/:baseId/boxes/:labelIdentifier", - initialUrl: "/bases/2/boxes/123", - mocks: [initialQuery, updateNumberOfItemsMutation], + initialUrl: "/bases/2/boxes/1235", + mocks: [initialQueryForChangeNumberOfBoxes, updateNumberOfItemsMutation], + cache, addTypename: true, globalPreferences: { dispatch: jest.fn(), @@ -407,7 +424,7 @@ it("3.1.2 - Change Number of Items", async () => { }, }); - const title = await screen.findByRole("heading", { name: "Box 123" }); + const title = await screen.findByRole("heading", { name: "Box 1235" }); expect(title).toBeInTheDocument(); expect(screen.getByRole("heading", { name: /31x snow trousers/i })); @@ -427,15 +444,34 @@ it("3.1.2 - Change Number of Items", async () => { await user.type(screen.getByRole("spinbutton"), "{backspace}"); await user.type(screen.getByRole("spinbutton"), "-"); await waitFor(() => expect(screen.getByRole("spinbutton")).toHaveValue("-")); - await user.click(screen.getByText(/Submit/i)); + + await user.click( + screen.getByRole("button", { + name: /submit/i, + }), + ); + await waitFor(() => expect(screen.getByRole("spinbutton")).toHaveValue("0")); // // // Test case 3.1.2.2 - Number of Item Validation await user.type(screen.getByRole("spinbutton"), "{backspace}"); await user.type(screen.getByRole("spinbutton"), "1"); await waitFor(() => expect(screen.getByRole("spinbutton")).toHaveValue("1")); - await user.click(screen.getByText(/Submit/i)); - expect(screen.getByText(/32x snow trousers/i)); + + await user.click( + screen.getByRole("button", { + name: /submit/i, + }), + ); + + await waitFor(() => + expect(mockedCreateToast).toHaveBeenCalledWith( + expect.objectContaining({ + message: expect.stringMatching(/successfully added 1 items to box/i), + }), + ), + ); + expect(screen.getByTestId("boxview-number-items")).toHaveTextContent(/32x snow trousers/i); }, 10000); // Test case 3.1.3.1 @@ -445,6 +481,7 @@ it("3.1.3.1 - Change State to Scrap", async () => { routePath: "/bases/:baseId/boxes/:labelIdentifier", initialUrl: "/bases/2/boxes/123", mocks: [initialQuery, updateBoxStateToScrapMutation, updateBoxStateToLostMutation], + cache, addTypename: true, globalPreferences: { dispatch: jest.fn(), @@ -477,6 +514,7 @@ it("3.1.3.2 - Change State to Lost", async () => { initialUrl: "/bases/2/boxes/123", mocks: [initialQuery, updateBoxStateToLostMutation], addTypename: true, + cache, globalPreferences: { dispatch: jest.fn(), globalPreferences: { @@ -512,6 +550,7 @@ it("3.1.4 - Move location", async () => { routePath: "/bases/:baseId/boxes/:labelIdentifier", initialUrl: "/bases/1/boxes/125", mocks: [initialQueryMoveLocationOfBox, moveLocationOfBoxMutation], + cache, addTypename: true, globalPreferences: { dispatch: jest.fn(), From 97a8eeb657f91105c61a91fab7b0e514232be21d Mon Sep 17 00:00:00 2001 From: Vahid Bazzaz Date: Fri, 30 Jun 2023 14:59:13 +0330 Subject: [PATCH 2/2] add support for partial response to boxview --- react/src/views/Box/BoxView.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/react/src/views/Box/BoxView.tsx b/react/src/views/Box/BoxView.tsx index 855e6bdaa..927017cae 100644 --- a/react/src/views/Box/BoxView.tsx +++ b/react/src/views/Box/BoxView.tsx @@ -151,6 +151,7 @@ function BTBox() { const allData = useQuery( BOX_BY_LABEL_IDENTIFIER_AND_ALL_SHIPMENTS_QUERY, { + errorPolicy: "all", variables: { labelIdentifier, }, @@ -210,7 +211,7 @@ function BTBox() { updateNumberOfItemsMutationStatus.loading; const error = - allData.error || + (allData.error && allData?.data === undefined) || assignBoxToDistributionEventMutationStatus.error || unassignBoxFromDistributionEventMutationStatus.error;