-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix deletion order drafts * Fix deletion order drafts * Fix deletion order drafts --------- Co-authored-by: Paweł Chyła <chyla1988@gmail.com>
- Loading branch information
1 parent
39711fe
commit d712e65
Showing
4 changed files
with
83 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
Fix deleting draft orders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useOrderDraftBulkCancelMutation } from "@dashboard/graphql"; | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
|
||
import { useBulkDeletion } from "./useBulkDeletion"; | ||
|
||
jest.mock("react-intl"); | ||
jest.mock("@dashboard/graphql", () => ({ | ||
useOrderDraftBulkCancelMutation: jest.fn(() => [jest.fn(), {}]), | ||
})); | ||
|
||
describe("Order draft list useBulkDeletion", () => { | ||
it("deletes order drafts for by given ids", async () => { | ||
// Arrange | ||
const onComplete = jest.fn(); | ||
const selectedRowIds = ["id1", "id2"]; | ||
const orderDraftBulkDelete = jest.fn(); | ||
const useOrderDraftBulkCancelMutationMock = | ||
useOrderDraftBulkCancelMutation as jest.Mock; | ||
useOrderDraftBulkCancelMutationMock.mockReturnValue([ | ||
orderDraftBulkDelete, | ||
{}, | ||
]); | ||
|
||
// Act | ||
const { result } = renderHook(() => useBulkDeletion(onComplete)); | ||
await result.current.onOrderDraftBulkDelete(selectedRowIds); | ||
|
||
// Assert | ||
expect(orderDraftBulkDelete).toBeCalledWith({ | ||
variables: { | ||
ids: ["id1", "id2"], | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useOrderDraftBulkCancelMutation } from "@dashboard/graphql"; | ||
import useNotifier from "@dashboard/hooks/useNotifier"; | ||
import { useIntl } from "react-intl"; | ||
|
||
export const useBulkDeletion = (onComplete: () => void) => { | ||
const notify = useNotifier(); | ||
const intl = useIntl(); | ||
const [orderDraftBulkDelete, orderDraftBulkDeleteOpts] = | ||
useOrderDraftBulkCancelMutation({ | ||
onCompleted: data => { | ||
if (data?.draftOrderBulkDelete?.errors.length === 0) { | ||
notify({ | ||
status: "success", | ||
text: intl.formatMessage({ | ||
id: "ra2O4j", | ||
defaultMessage: "Deleted draft orders", | ||
}), | ||
}); | ||
|
||
onComplete(); | ||
} | ||
}, | ||
}); | ||
|
||
const onOrderDraftBulkDelete = async (selectedRowIds: string[]) => { | ||
await orderDraftBulkDelete({ | ||
variables: { | ||
ids: selectedRowIds, | ||
}, | ||
}); | ||
}; | ||
|
||
return { onOrderDraftBulkDelete, orderDraftBulkDeleteOpts }; | ||
}; |