forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
fix: fix bulk inline edit mode for event activities #818
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
Merged
smarcet
merged 1 commit into
master
from
fix/fix-bulk-inline-edit-mode-event-activities
Mar 12, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
| import { normalizeBulkEvents } from "../event-actions"; | ||
|
|
||
| describe("event-actions bulk normalization", () => { | ||
| test("does not include speakers in bulk payload", () => { | ||
| const input = [ | ||
| { | ||
| id: 10, | ||
| title: "My Event", | ||
| speakers: [{ id: 3 }, { id: 4 }], | ||
| selection_plan: { id: 20 }, | ||
| type: { id: 30 }, | ||
| track: { id: 40 }, | ||
| streaming_url: "https://example.com/live" | ||
| } | ||
| ]; | ||
|
|
||
| const result = normalizeBulkEvents(input); | ||
|
|
||
| expect(result).toHaveLength(1); | ||
| expect(result[0]).toMatchObject({ | ||
| id: 10, | ||
| title: "My Event", | ||
| selection_plan_id: 20, | ||
| type_id: 30, | ||
| track_id: 40, | ||
| streaming_url: "https://example.com/live" | ||
| }); | ||
| expect(result[0]).not.toHaveProperty("speakers"); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
src/components/tables/editable-table/__tests__/EditableTable.test.js
This file contains hidden or 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,96 @@ | ||
| import React from "react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { act, render, screen, waitFor } from "@testing-library/react"; | ||
| import EditableTable from "../EditableTable"; | ||
|
|
||
| describe("EditableTable", () => { | ||
| const baseProps = { | ||
| options: { | ||
| className: "test-table", | ||
| actions: {} | ||
| }, | ||
| columns: [ | ||
| { columnKey: "id", value: "id", sortable: true }, | ||
| { columnKey: "title", value: "title", sortable: true } | ||
| ], | ||
| currentSummit: { id: 99 }, | ||
| page: 1, | ||
| handleSort: jest.fn(), | ||
| handleDeleteRow: jest.fn(), | ||
| formattingFunction: (row) => row, | ||
| data: [ | ||
| { | ||
| id: 1, | ||
| title: "Event 1", | ||
| media_uploads: [{ id: 11, event_id: 1 }] | ||
| }, | ||
| { | ||
| id: 2, | ||
| title: "Event 2", | ||
| media_uploads: [{ id: 22, event_id: 2 }] | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test("applies bulk updates without executing afterUpdate by default", async () => { | ||
| const user = userEvent.setup(); | ||
| const updateData = jest.fn(() => Promise.resolve()); | ||
|
|
||
| render(<EditableTable {...baseProps} updateData={updateData} />); | ||
|
|
||
| const checkboxes = screen.getAllByRole("checkbox"); | ||
|
|
||
| await user.click(checkboxes[1]); | ||
| await user.click(screen.getByText("event_list.edit_selected")); | ||
| await act(async () => { | ||
| await user.click(screen.getByText("bulk_actions_page.btn_apply_changes")); | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(updateData).toHaveBeenCalledTimes(1); | ||
| expect(updateData).toHaveBeenCalledWith( | ||
| 99, | ||
| expect.arrayContaining([expect.objectContaining({ id: 1 })]) | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test("executes afterUpdate actions only when explicitly configured", async () => { | ||
| const user = userEvent.setup(); | ||
| const updateData = jest.fn(() => Promise.resolve()); | ||
| const afterUpdateAction = jest.fn(() => Promise.resolve()); | ||
|
|
||
| render( | ||
| <EditableTable | ||
| {...baseProps} | ||
| updateData={updateData} | ||
| afterUpdate={[ | ||
| { | ||
| action: afterUpdateAction, | ||
| propertyName: "media_uploads" | ||
| } | ||
| ]} | ||
| /> | ||
| ); | ||
|
|
||
| const checkboxes = screen.getAllByRole("checkbox"); | ||
|
|
||
| await user.click(checkboxes[1]); | ||
| await user.click(screen.getByText("event_list.edit_selected")); | ||
| await act(async () => { | ||
| await user.click(screen.getByText("bulk_actions_page.btn_apply_changes")); | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(updateData).toHaveBeenCalledTimes(1); | ||
| expect(afterUpdateAction).toHaveBeenCalledTimes(1); | ||
| expect(afterUpdateAction).toHaveBeenCalledWith( | ||
| expect.objectContaining({ id: 11, event_id: 1 }) | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
123 changes: 123 additions & 0 deletions
123
src/pages/events/__tests__/edit-event-material-page.test.js
This file contains hidden or 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,123 @@ | ||
| import React from "react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { screen } from "@testing-library/react"; | ||
| import EditEventMaterialPage from "../edit-event-material-page"; | ||
| import { renderWithRedux } from "../../../utils/test-utils"; | ||
|
|
||
| jest.mock("react-breadcrumbs", () => ({ | ||
| Breadcrumb: () => null | ||
| })); | ||
|
|
||
| jest.mock("../../../components/buttons/add-new-button", () => () => null); | ||
|
|
||
| jest.mock("../../../components/forms/event-material-form", () => (props) => ( | ||
| <div> | ||
| <button type="button" onClick={() => props.onSubmit({ id: 77 })}> | ||
| submit-material | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => | ||
| props.onSubmitWithFile( | ||
| { id: 88, class_name: "PresentationSlide" }, | ||
| new global.File(["dummy"], "slides.pdf", { | ||
| type: "application/pdf" | ||
| }) | ||
| ) | ||
| } | ||
| > | ||
| submit-material-with-file | ||
| </button> | ||
| </div> | ||
| )); | ||
|
|
||
| jest.mock("../../../actions/event-material-actions", () => ({ | ||
| getEventMaterial: jest.fn(() => ({ type: "GET_EVENT_MATERIAL_MOCK" })), | ||
| resetEventMaterialForm: jest.fn(() => ({ | ||
| type: "RESET_EVENT_MATERIAL_MOCK" | ||
| })), | ||
| saveEventMaterial: jest.fn(() => ({ type: "SAVE_EVENT_MATERIAL_MOCK" })), | ||
| saveEventMaterialWithFile: jest.fn(() => ({ | ||
| type: "SAVE_EVENT_MATERIAL_WITH_FILE_MOCK" | ||
| })) | ||
| })); | ||
|
|
||
| const EventMaterialActions = jest.requireMock( | ||
| "../../../actions/event-material-actions" | ||
| ); | ||
|
|
||
| describe("EditEventMaterialPage", () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| const baseState = { | ||
| currentSummitState: { | ||
| currentSummit: { id: 12 } | ||
| }, | ||
| currentSummitEventState: { | ||
| entity: { | ||
| id: 321, | ||
| materials: [] | ||
| } | ||
| }, | ||
| currentEventMaterialState: { | ||
| entity: { id: 0, class_name: "PresentationSlide" }, | ||
| errors: {} | ||
| } | ||
| }; | ||
|
|
||
| test("uses saveEventMaterial for regular material submit (non-bulk)", async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| renderWithRedux( | ||
| <EditEventMaterialPage | ||
| match={{ | ||
| params: { material_id: "15" }, | ||
| url: "/app/summits/12/events/321/materials/15" | ||
| }} | ||
| />, | ||
| { | ||
| initialState: baseState | ||
| } | ||
| ); | ||
|
|
||
| expect(EventMaterialActions.getEventMaterial).toHaveBeenCalledWith("15"); | ||
|
|
||
| await user.click(screen.getByText("submit-material")); | ||
|
|
||
| expect(EventMaterialActions.saveEventMaterial).toHaveBeenCalledTimes(1); | ||
| expect(EventMaterialActions.saveEventMaterial).toHaveBeenCalledWith({ | ||
| id: 77 | ||
| }); | ||
| }); | ||
|
|
||
| test("uses saveEventMaterialWithFile with slides slug for file submit", async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| renderWithRedux( | ||
| <EditEventMaterialPage | ||
| match={{ | ||
| params: { material_id: "15" }, | ||
| url: "/app/summits/12/events/321/materials/15" | ||
| }} | ||
| />, | ||
| { | ||
| initialState: baseState | ||
| } | ||
| ); | ||
|
|
||
| await user.click(screen.getByText("submit-material-with-file")); | ||
|
|
||
| expect( | ||
| EventMaterialActions.saveEventMaterialWithFile | ||
| ).toHaveBeenCalledTimes(1); | ||
|
|
||
| const [entityArg, fileArg, slugArg] = | ||
| EventMaterialActions.saveEventMaterialWithFile.mock.calls[0]; | ||
|
|
||
| expect(entityArg).toEqual({ id: 88, class_name: "PresentationSlide" }); | ||
| expect(fileArg).toBeInstanceOf(global.File); | ||
| expect(slugArg).toBe("slides"); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Include
class_namein the regular-submit fixture.Line 15 submits only
{ id: 77 }, butsaveEventMaterialderives its slug fromentity.class_nameinsrc/actions/event-material-actions.js:71-86. That makes this test pass even if the page dropsclass_nameand would hit the wrong"media-uploads"route at runtime.Suggested change
jest.mock("../../../components/forms/event-material-form", () => (props) => ( <div> - <button type="button" onClick={() => props.onSubmit({ id: 77 })}> + <button + type="button" + onClick={() => + props.onSubmit({ id: 77, class_name: "PresentationSlide" }) + } + > submit-material </button> @@ expect(EventMaterialActions.saveEventMaterial).toHaveBeenCalledTimes(1); expect(EventMaterialActions.saveEventMaterial).toHaveBeenCalledWith({ - id: 77 + id: 77, + class_name: "PresentationSlide" }); });Also applies to: 90-92
🤖 Prompt for AI Agents