-
Notifications
You must be signed in to change notification settings - Fork 4
86b7kbjcf - Fix: item counter when deleting form item on second page #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/actions/sponsor-forms-actions.js
Outdated
| snackbarErrorHandler | ||
| )(params)(dispatch) | ||
| .then(() => { | ||
| const { currentPage, perPage, order, orderDir, hideArchived } = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
smarcet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@niko-exo please review comments
1a81b2a to
156ba5b
Compare
📝 WalkthroughWalkthroughThe pull request adds test coverage for sponsor form item deletion, updates the list refresh logic to refetch items after deletion, and modifies the reducer to stop tracking totalCount when items are deleted. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
|
Branch rebased on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @src/actions/__tests__/sponsor-forms-actions.test.js:
- Around line 25-64: Test has a typo in the expectation message and is missing
stronger assertions: fix the typo "acces" -> "access" in the comment/assertion,
remove the unused sponsorFormItemsListState from the mockedGetState return, and
add assertions inside the "execute" test to verify deleteRequest was called with
the correct URL and handlers and that the SPONSOR_FORM_ITEM_DELETED action (or
the action creator used by deleteSponsorFormItem) was dispatched with the
expected itemId; use the existing spies/mocks (spyOnGetAccessTokenSafely,
spyOnSnackbarSuccessHandler, OpenStackUiCoreActions.deleteRequest) and the
deleteSponsorFormItem invocation to assert the exact parameters and dispatched
action.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/actions/__tests__/sponsor-forms-actions.test.jssrc/actions/sponsor-forms-actions.jssrc/pages/sponsors/sponsor-form-item-list-page/index.jssrc/reducers/sponsors/__tests__/sponsor-form-items-list-reducer.test.jssrc/reducers/sponsors/sponsor-form-items-list-reducer.js
💤 Files with no reviewable changes (2)
- src/actions/sponsor-forms-actions.js
- src/reducers/sponsors/tests/sponsor-form-items-list-reducer.test.js
🧰 Additional context used
🧬 Code graph analysis (1)
src/pages/sponsors/sponsor-form-item-list-page/index.js (1)
src/actions/sponsor-forms-actions.js (4)
deleteSponsorFormItem(933-959)deleteSponsorFormItem(933-959)getSponsorFormItems(862-909)getSponsorFormItems(862-909)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: build
- GitHub Check: build
- GitHub Check: build
- GitHub Check: build
- GitHub Check: build
- GitHub Check: build
🔇 Additional comments (5)
src/actions/__tests__/sponsor-forms-actions.test.js (3)
1-5: LGTM!The imports are well-organized and include all necessary dependencies for testing the DeleteSponsorFormItem action flow.
6-16: LGTM!The mock correctly preserves the original module while stubbing
deleteRequestwith a triple-nested function that matches the thunk pattern used in the codebase:deleteRequest(...args)(params)(dispatch).
18-24: LGTM!The test suite structure is clean, with proper cleanup using
jest.restoreAllMocks()inafterEachto prevent test interference.src/pages/sponsors/sponsor-form-item-list-page/index.js (1)
104-115: LGTM! This correctly fixes the item counter refresh issue.The change properly addresses the root cause by refetching the list after deletion, ensuring
totalCountand the items array are synchronized with the backend state. This approach is more reliable than attempting to calculatetotalCountlocally in the reducer.The refresh preserves all current filters, sorting, and pagination parameters, maintaining the user's view state.
src/reducers/sponsors/sponsor-form-items-list-reducer.js (1)
131-136: LGTM! Simplifying the reducer is the right approach.Removing the local
totalCountrecalculation eliminates the source of the bug. The subsequent refetch (added in the page component) ensurestotalCountis updated accurately from the backend.This change follows the single-source-of-truth principle: instead of attempting to maintain synchronization locally, rely on the server response via
RECEIVE_SPONSOR_FORM_ITEMSto update bothitemsandtotalCountcorrectly.
| 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(); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo and consider more comprehensive assertions.
Minor typo on line 58: "acces" should be "access".
The test validates the observable side effects but could be more thorough. Consider adding assertions to verify:
- The correct parameters are passed to
deleteRequest(URL, action creator, error handler) - The
SPONSOR_FORM_ITEM_DELETEDaction is dispatched with the correct itemId
Additionally, sponsorFormItemsListState in the mocked state (lines 31-37) is not used by deleteSponsorFormItem and can be removed for clarity.
📝 Proposed fix for typo
- // gets acces token safely
+ // gets access token safely
expect(spyOnGetAccessTokenSafely).toHaveBeenCalled();♻️ Optional: More comprehensive assertions
const mockedGetState = jest.fn(() => ({
currentSummitState: {
currentSummit: "SSS"
- },
- sponsorFormItemsListState: {
- currentPage: 1,
- perPage: 10,
- order: "asc",
- orderDir: 1,
- hideArchived: false
}
}));And add more specific assertions:
// gets access token safely
expect(spyOnGetAccessTokenSafely).toHaveBeenCalled();
// calls delete request
expect(OpenStackUiCoreActions.deleteRequest).toHaveBeenCalled();
+ // verify deleteRequest was called with correct action creator
+ const deleteRequestCall = OpenStackUiCoreActions.deleteRequest.mock.calls[0];
+ expect(deleteRequestCall[1]).toBeDefined(); // action creator
+ expect(deleteRequestCall[2]).toContain('/show-forms/AAA/items/III'); // URL
// shows snackbar
expect(spyOnSnackbarSuccessHandler).toHaveBeenCalled();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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(); | |
| }); | |
| it("execute", async () => { | |
| const mockedDispatch = jest.fn(); | |
| const mockedGetState = jest.fn(() => ({ | |
| currentSummitState: { | |
| currentSummit: "SSS" | |
| } | |
| })); | |
| 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 access token safely | |
| expect(spyOnGetAccessTokenSafely).toHaveBeenCalled(); | |
| // calls delete request | |
| expect(OpenStackUiCoreActions.deleteRequest).toHaveBeenCalled(); | |
| // verify deleteRequest was called with correct action creator | |
| const deleteRequestCall = OpenStackUiCoreActions.deleteRequest.mock.calls[0]; | |
| expect(deleteRequestCall[1]).toBeDefined(); // action creator | |
| expect(deleteRequestCall[2]).toContain('/show-forms/AAA/items/III'); // URL | |
| // shows snackbar | |
| expect(spyOnSnackbarSuccessHandler).toHaveBeenCalled(); | |
| }); |
🤖 Prompt for AI Agents
In @src/actions/__tests__/sponsor-forms-actions.test.js around lines 25 - 64,
Test has a typo in the expectation message and is missing stronger assertions:
fix the typo "acces" -> "access" in the comment/assertion, remove the unused
sponsorFormItemsListState from the mockedGetState return, and add assertions
inside the "execute" test to verify deleteRequest was called with the correct
URL and handlers and that the SPONSOR_FORM_ITEM_DELETED action (or the action
creator used by deleteSponsorFormItem) was dispatched with the expected itemId;
use the existing spies/mocks (spyOnGetAccessTokenSafely,
spyOnSnackbarSuccessHandler, OpenStackUiCoreActions.deleteRequest) and the
deleteSponsorFormItem invocation to assert the exact parameters and dispatched
action.
|
Ready for review |
ref: https://app.clickup.com/t/86b7kbjcf
86b7kbjcf - Fix: item counter when deleting form item on second page
Changelog
Links
86b7kbjcf - Item counter does not refresh after deleting item until page refresh
Evidence
2025-12-30_13-34-24.mp4
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.