Skip to content
Merged
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
30 changes: 30 additions & 0 deletions src/actions/__tests__/event-actions-bulk.test.js
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");
});
});
9 changes: 6 additions & 3 deletions src/actions/event-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,14 @@ export const normalizeEvent = (entity, eventTypeConfig, summit) => {
});

if (normalizedEntity.hasOwnProperty("sponsors"))
normalizedEntity.sponsors = normalizedEntity.sponsors.map((s) => s.id);
normalizedEntity.sponsors = normalizedEntity.sponsors
.map((s) => (typeof s === "number" ? s : s?.id))
.filter((s) => !!s);

if (normalizedEntity.hasOwnProperty("speakers"))
normalizedEntity.speakers = normalizedEntity.speakers.map((s) => s.id);
normalizedEntity.speakers = normalizedEntity.speakers
.map((s) => (typeof s === "number" ? s : s?.id))
.filter((s) => !!s);

if (
normalizedEntity.hasOwnProperty("moderator") &&
Expand Down Expand Up @@ -511,7 +515,6 @@ export const normalizeBulkEvents = (entity) => {
selection_plan_id: getIdValue(e.selection_plan) || e.selection_plan_id,
location_id: e.location?.id || e.location_id,
start_date: e.start_date,
speakers: e.speakers,
end_date: e.end_date,
type_id: getIdValue(e.type) || e.type_id,
track_id: getIdValue(e.track) || e.track_id,
Expand Down
2 changes: 1 addition & 1 deletion src/components/tables/editable-table/EditableTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function EditableTableRow(props) {
return (
<td key={`row-edit-${col.columnKey}-${row.id}`}>
{col.render
? col.render(row[col.columnKey])
? col.render(row[col.columnKey], row)
: formattedData[col.columnKey]}
</td>
);
Expand Down
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 src/pages/events/__tests__/edit-event-material-page.test.js
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
Comment on lines +13 to +16

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Include class_name in the regular-submit fixture.

Line 15 submits only { id: 77 }, but saveEventMaterial derives its slug from entity.class_name in src/actions/event-material-actions.js:71-86. That makes this test pass even if the page drops class_name and 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
Verify each finding against the current code and only fix it if needed.

In `@src/pages/events/__tests__/edit-event-material-page.test.js` around lines 13
- 16, The test's mocked EventMaterialForm currently submits only { id: 77 }, but
saveEventMaterial derives the slug from entity.class_name (see saveEventMaterial
in src/actions/event-material-actions.js), so update the mock submit
payloads/regular-submit fixture to include a class_name (e.g., { id: 77,
class_name: "EventMaterial" }) so the test exercises the same routing logic as
runtime; make the same change for the other mocked submit used later in the file
to ensure both mocks include class_name.

</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");
});
});
Loading