Skip to content
Open
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
66 changes: 66 additions & 0 deletions src/actions/__tests__/sponsor-forms-actions.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as OpenStackUiCoreActions from "openstack-uicore-foundation/lib/utils/actions";
import { deleteSponsorFormItem } from "../sponsor-forms-actions";
import * as UtilsMethods from "../../utils/methods";
import * as BaseActions from "../base-actions";

jest.mock("openstack-uicore-foundation/lib/utils/actions", () => {
const originalModule = jest.requireActual(
"openstack-uicore-foundation/lib/utils/actions"
);

return {
__esModule: true,
...originalModule,
deleteRequest: jest.fn(() => () => () => Promise.resolve())
};
});

describe("SponsorFormActions", () => {
describe("DeleteSponsorFormItem", () => {
afterEach(() => {
// restore the spy created with spyOn
jest.restoreAllMocks();
});

it("execute", async () => {
const mockedDispatch = jest.fn();
const mockedGetState = jest.fn(() => ({
currentSummitState: {
currentSummit: "SSS"
},
sponsorFormItemsListState: {
currentPage: 1,
perPage: 10,
order: "asc",
orderDir: 1,
hideArchived: false
}
}));

const params = {
formId: "AAA",
itemId: "III"
};

const spyOnGetAccessTokenSafely = jest
.spyOn(UtilsMethods, "getAccessTokenSafely")
.mockImplementation(() => "access _token");
const spyOnSnackbarSuccessHandler = jest.spyOn(
BaseActions,
"snackbarSuccessHandler"
);

await deleteSponsorFormItem(params.formId, params.itemId)(
mockedDispatch,
mockedGetState
);

// gets acces token safely
expect(spyOnGetAccessTokenSafely).toHaveBeenCalled();
// calls delete request
expect(OpenStackUiCoreActions.deleteRequest).toHaveBeenCalled();
// shows snackbar
expect(spyOnSnackbarSuccessHandler).toHaveBeenCalled();
});
});
});
15 changes: 13 additions & 2 deletions src/actions/sponsor-forms-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -932,13 +932,12 @@ export const getSponsorFormItem =

export const deleteSponsorFormItem =
(formId, itemId) => async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummitState, sponsorFormItemsListState } = getState();
const accessToken = await getAccessTokenSafely();
const { currentSummit } = currentSummitState;
const params = { access_token: accessToken };

dispatch(startLoading());

return deleteRequest(
null,
createAction(SPONSOR_FORM_ITEM_DELETED)({ itemId }),
Expand All @@ -947,6 +946,18 @@ export const deleteSponsorFormItem =
snackbarErrorHandler
)(params)(dispatch)
.then(() => {
const { currentPage, perPage, order, orderDir, hideArchived } =
Copy link

@smarcet smarcet Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niko-exo this is not necessary. please take the same approach as we did here
9319963
** note
this approach introduce a new bug that happens with current page is not longer valid ( user deletes the last item of current page )

sponsorFormItemsListState;
dispatch(
getSponsorFormItems(
formId,
currentPage,
perPage,
order,
orderDir,
hideArchived
)
);
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ describe("SponsorFormItemsListReducer", () => {
result = SponsorFormItemsListReducer(
{
...initialState,
totalCount: 2,
items: [
{
id: "A",
Expand Down Expand Up @@ -267,7 +266,6 @@ describe("SponsorFormItemsListReducer", () => {
);
expect(result).toStrictEqual({
...initialState,
totalCount: 1,
items: [
{
id: "B",
Expand Down
3 changes: 1 addition & 2 deletions src/reducers/sponsors/sponsor-form-items-list-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ const sponsorFormItemsListReducer = (state = DEFAULT_STATE, action) => {
case SPONSOR_FORM_ITEM_DELETED: {
const { itemId } = payload;
const items = state.items.filter((it) => it.id !== itemId);
const totalCount = items.length;

return { ...state, items, totalCount };
return { ...state, items };
}
case SPONSOR_FORM_ITEM_ARCHIVED: {
const { id: itemId } = payload.response;
Expand Down