Skip to content

Commit

Permalink
[Dashboard] Fix for error flashing when deleting repo (#5461)
Browse files Browse the repository at this point in the history
* Fix for error flashing when deleting repo

Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>

* Remove wrong check in test

Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>

Signed-off-by: Rafa Castelblanque <rcastelblanq@vmware.com>
  • Loading branch information
castelblanque authored Oct 17, 2022
1 parent f8d20a2 commit 1fd6a76
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const defaultProps = {

it("deletes the repo and refreshes list", async () => {
const deleteRepo = jest.fn();
// Mock the response for delete repo action
const mockDispatch = jest.fn();
mockDispatch.mockReturnValue(true);
spyOnUseDispatch = jest.spyOn(ReactRedux, "useDispatch").mockReturnValue(mockDispatch);
const refetchRepos = jest.fn();
actions.repos = {
...actions.repos,
Expand Down Expand Up @@ -67,6 +71,40 @@ it("deletes the repo and refreshes list", async () => {
expect(refetchRepos).toHaveBeenCalled();
});

it("show error message when package repository deletion fails ", async () => {
const deleteRepo = jest.fn();
// Mock the response for delete repo action
const mockDispatch = jest.fn();
mockDispatch.mockReturnValue(false);
spyOnUseDispatch = jest.spyOn(ReactRedux, "useDispatch").mockReturnValue(mockDispatch);
const refetchRepos = jest.fn();
actions.repos = {
...actions.repos,
deleteRepo,
};
const wrapper = mountWrapper(
defaultStore,
<PkgRepoControl {...defaultProps} refetchRepos={refetchRepos} />,
);
const deleteButton = wrapper.find(CdsButton).filterWhere(b => b.text() === "Delete");
act(() => {
(deleteButton.prop("onClick") as any)();
});
wrapper.update();
expect(wrapper.find(ConfirmDialog)).toIncludeText(
"Are you sure you want to delete the repository",
);
const confirmButton = wrapper
.find(ConfirmDialog)
.find(".btn")
.filterWhere(b => b.text() === "Delete");
await act(async () => {
await (confirmButton.prop("onClick") as any)();
});
expect(deleteRepo).toHaveBeenCalled();
expect(refetchRepos).not.toHaveBeenCalled();
});

it("renders the button to edit the repo", () => {
const wrapper = mountWrapper(defaultStore, <PkgRepoControl {...defaultProps} />);
expect(wrapper.find(PkgRepoAddButton).prop("text")).toBe("Edit");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export function PkgRepoControl({

const handleDeleteClick = (packageRepoRef: PackageRepositoryReference) => {
return async () => {
await dispatch(actions.repos.deleteRepo(packageRepoRef));
refetchRepos();
const deleted = await dispatch(actions.repos.deleteRepo(packageRepoRef));
if (deleted) {
refetchRepos();
}
closeModal();
};
};
Expand Down

0 comments on commit 1fd6a76

Please sign in to comment.