[#50] added attendee search and tests

This commit is contained in:
Camille Moussu
2025-07-30 15:22:28 +02:00
committed by Benoit TELLIER
parent 9a58c485ac
commit d7b3d4e077
6 changed files with 260 additions and 36 deletions
+111 -10
View File
@@ -1,20 +1,20 @@
import { screen, fireEvent, waitFor } from "@testing-library/react";
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import EventPopover from "../../../src/features/Events/EventModal";
import { DateSelectArg } from "@fullcalendar/core";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import preview from "jest-preview";
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
import EventPopover from "../../../src/features/Events/EventModal";
import { api } from "../../../src/utils/apiUtils";
import { formatDateToYYYYMMDDTHHMMSS } from "../../../src/utils/dateUtils";
import { renderWithProviders } from "../../utils/Renderwithproviders";
jest.mock("../../../src/utils/apiUtils");
describe("EventPopover", () => {
const mockOnClose = jest.fn();
const mockSetSelectedRange = jest.fn();
const mockCalendarRef = { current: { select: jest.fn() } } as any;
beforeEach(() => {
jest.clearAllMocks();
});
const preloadedState = {
user: {
userData: {
@@ -25,7 +25,7 @@ describe("EventPopover", () => {
},
organiserData: {
cn: "test",
cal_address: "mailto:test@test.com",
cal_address: "test@test.com",
},
},
calendars: {
@@ -45,6 +45,44 @@ describe("EventPopover", () => {
},
};
const mockUsers = [
{
id: "john@example.com",
objectType: "user",
emailAddresses: [
{
value: "john@example.com",
type: "default",
},
],
names: [
{
displayName: "John Doe",
type: "default",
},
],
},
{
id: "jane@example.com",
objectType: "user",
emailAddresses: [
{
value: "jane@example.com",
type: "default",
},
],
names: [
{
displayName: "Jane Smith",
type: "default",
},
],
},
];
(api.post as jest.Mock).mockReturnValue({
json: jest.fn().mockResolvedValue(mockUsers),
});
const defaultSelectedRange = {
startStr: "2025-07-18T09:00",
endStr: "2025-07-18T10:00",
@@ -130,6 +168,69 @@ describe("EventPopover", () => {
expect(screen.getAllByRole("combobox")[0]).toHaveTextContent("Calendar 2");
});
it("adds a attendee", async () => {
jest.useFakeTimers();
renderPopover();
fireEvent.change(screen.getByLabelText("Title"), {
target: { value: "newEvent" },
});
const select = screen.getByLabelText("Search user");
act(() => {
select.focus();
fireEvent.mouseDown(select);
userEvent.type(select, "john");
});
await act(async () => {
jest.advanceTimersByTime(400);
});
await waitFor(() => expect(api.post).toHaveBeenCalledTimes(1));
await waitFor(() => {
expect(screen.getByText("John Doe")).toBeInTheDocument();
});
await act(async () => {
userEvent.click(screen.getByText("John Doe"));
});
const spy = jest
.spyOn(eventThunks, "putEventAsync")
.mockImplementation((payload) => {
return () => Promise.resolve(payload) as any;
});
fireEvent.click(screen.getByText("Save"));
await waitFor(() => {
expect(spy).toHaveBeenCalled();
});
const receivedPayload = spy.mock.calls[0][0];
expect(receivedPayload.cal).toEqual(
preloadedState.calendars.list["667037022b752d0026472254/cal1"]
);
expect(receivedPayload.newEvent.attendee).toHaveLength(2);
expect(receivedPayload.newEvent.attendee).toStrictEqual([
{
cn: "test",
cal_address: "test@test.com",
partstat: "ACCEPTED",
rsvp: "FALSE",
role: "CHAIR",
cutype: "INDIVIDUAL",
},
{
cn: "John Doe",
cal_address: "john@example.com",
partstat: "NEED_ACTION",
rsvp: "FALSE",
role: "CHAIR",
cutype: "INDIVIDUAL",
},
]);
});
it("dispatches putEventAsync and calls onClose when Save is clicked", async () => {
renderPopover();
@@ -142,7 +243,7 @@ describe("EventPopover", () => {
description: "Discuss project",
location: "Zoom",
repetition: "",
organizer: { cn: "test", cal_address: "mailto:test@test.com" },
organizer: { cn: "test", cal_address: "test@test.com" },
timezone: "Europe/Paris",
transp: "OPAQUE",
};
+2 -2
View File
@@ -1,5 +1,5 @@
import { clientConfig } from "../../../src/features/User/oidcAuth";
import getOpenPaasUserId from "../../../src/features/User/userAPI";
import getOpenPaasUser from "../../../src/features/User/userAPI";
import { api } from "../../../src/utils/apiUtils";
jest.mock("../../../src/utils/apiUtils");
@@ -14,7 +14,7 @@ describe("getOpenPaasUserId", () => {
json: jest.fn().mockResolvedValue(mockUser),
});
const result = await getOpenPaasUserId();
const result = await getOpenPaasUser();
expect(api.get).toHaveBeenCalledWith("api/user");
expect(result).toEqual(mockUser);