Refactor imports (#470)

This commit is contained in:
Camille Moussu
2026-01-20 17:33:30 +01:00
committed by GitHub
parent aeb8670895
commit 23d50f250d
149 changed files with 1439 additions and 1374 deletions
+18 -18
View File
@@ -1,15 +1,14 @@
import CalendarApp from "@/components/Calendar/Calendar";
import CalendarLayout from "@/components/Calendar/CalendarLayout";
import * as calendarDetailThunks from "@/features/Calendars/services";
import * as servicesModule from "@/features/Calendars/services";
import { searchUsers } from "@/features/User/userAPI";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import CalendarApp from "../../src/components/Calendar/Calendar";
import * as eventThunks from "../../src/features/Calendars/CalendarSlice";
import { renderWithProviders } from "../utils/Renderwithproviders";
import { searchUsers } from "../../src/features/User/userAPI";
import * as calendarDetailThunks from "../../src/features/Calendars/services/getCalendarDetailAsync";
import { useRef } from "react";
import userEvent from "@testing-library/user-event";
import CalendarLayout from "../../src/components/Calendar/CalendarLayout";
jest.mock("../../src/features/User/userAPI");
import { useRef } from "react";
import { renderWithProviders } from "../utils/Renderwithproviders";
jest.mock("@/features/User/userAPI");
const mockedSearchUsers = searchUsers as jest.MockedFunction<
typeof searchUsers
>;
@@ -348,7 +347,7 @@ describe("calendar Availability search", () => {
it("imports temporary calendars when selecting new users", async () => {
const spy = jest
.spyOn(eventThunks, "getTempCalendarsListAsync")
.spyOn(servicesModule, "getTempCalendarsListAsync")
.mockImplementation((payload) => {
return () => Promise.resolve(payload) as any;
});
@@ -389,7 +388,7 @@ describe("calendar Availability search", () => {
},
]);
const spy = jest
.spyOn(eventThunks, "getTempCalendarsListAsync")
.spyOn(servicesModule, "getTempCalendarsListAsync")
.mockImplementation((payload) => {
return () => Promise.resolve(payload) as any;
});
@@ -411,7 +410,7 @@ describe("calendar Availability search", () => {
it("open window with attendees filled after temp search on create event button click", async () => {
const spy = jest
.spyOn(eventThunks, "getTempCalendarsListAsync")
.spyOn(servicesModule, "getTempCalendarsListAsync")
.mockImplementation((payload) => {
return () => Promise.resolve(payload) as any;
});
@@ -455,7 +454,7 @@ describe("calendar Availability search", () => {
it("open window with attendees filled after temp search on enter in temp input", async () => {
const spy = jest
.spyOn(eventThunks, "getTempCalendarsListAsync")
.spyOn(servicesModule, "getTempCalendarsListAsync")
.mockImplementation((payload) => {
return () => Promise.resolve(payload) as any;
});
@@ -696,10 +695,10 @@ describe("calendar Availability search", () => {
);
const selectedCalls = spy.mock.calls.filter(
(call) => call[0].calId === "user1/cal1"
(call: { calId: string }[]) => call[0].calId === "user1/cal1"
);
const hiddenCalls = spy.mock.calls.filter(
(call) =>
(call: { calId: string }[]) =>
call[0].calId === "user1/cal2" || call[0].calId === "user1/cal3"
);
@@ -729,12 +728,13 @@ describe("calendar Availability search", () => {
);
const callsForCal1 = spy.mock.calls.filter(
(call) => call[0].calId === "user1/cal1"
(call: { calId: string }[]) => call[0].calId === "user1/cal1"
);
const uniqueRanges = new Set(
callsForCal1.map(
(call) => `${call[0].match.start}_${call[0].match.end}`
(call: { match: { end: string; start: string } }[]) =>
`${call[0].match.start}_${call[0].match.end}`
)
);
+7 -7
View File
@@ -1,13 +1,13 @@
import { fireEvent, screen, waitFor, act } from "@testing-library/react";
import CalendarSearch from "@/components/Calendar/CalendarSearch";
import * as CalendarApi from "@/features/Calendars/CalendarApi";
import * as CalendarSlice from "@/features/Calendars/services";
import { searchUsers } from "@/features/User/userAPI";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import CalendarSearch from "../../src/components/Calendar/CalendarSearch";
import * as CalendarApi from "../../src/features/Calendars/CalendarApi";
import * as CalendarSlice from "../../src/features/Calendars/CalendarSlice";
import { searchUsers } from "../../src/features/User/userAPI";
import { renderWithProviders } from "../utils/Renderwithproviders";
jest.mock("../../src/features/User/userAPI");
jest.mock("../../src/features/Calendars/CalendarApi");
jest.mock("@/features/User/userAPI");
jest.mock("@/features/Calendars/CalendarApi");
const mockedSearchUsers = searchUsers as jest.MockedFunction<
typeof searchUsers
@@ -1,9 +1,9 @@
import { screen, fireEvent, waitFor, cleanup } from "@testing-library/react";
import CalendarSelection from "@/components/Calendar/CalendarSelection";
import * as calendarThunks from "@/features/Calendars/services";
import "@testing-library/jest-dom";
import CalendarSelection from "../../src/components/Calendar/CalendarSelection";
import { renderWithProviders } from "../utils/Renderwithproviders";
import * as calendarThunks from "../../src/features/Calendars/CalendarSlice";
import { cleanup, fireEvent, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "../utils/Renderwithproviders";
describe("CalendarSelection", () => {
beforeEach(() => {
+7 -7
View File
@@ -1,15 +1,15 @@
import {
screen,
fireEvent,
waitFor,
DateTimeFields,
DateTimeFieldsProps,
} from "@/components/Event/components/DateTimeFields";
import {
act,
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import {
DateTimeFieldsProps,
DateTimeFields,
} from "../../src/components/Event/components/DateTimeFields";
jest.mock("twake-i18n", () => ({
useI18n: () => ({
+6 -5
View File
@@ -1,8 +1,9 @@
import { RootState } from "@/app/store";
import EventDuplication from "@/components/Event/EventDuplicate";
import EventPreviewModal from "@/features/Events/EventDisplayPreview";
import EventPopover from "@/features/Events/EventModal";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import EventDuplication from "../../src/components/Event/EventDuplicate";
import EventPopover from "../../src/features/Events/EventModal";
import { renderWithProviders } from "../utils/Renderwithproviders";
import EventPreviewModal from "../../src/features/Events/EventDisplayPreview";
const day = new Date();
const preloadedState = {
@@ -58,7 +59,7 @@ const preloadedState = {
},
pending: false,
},
};
} as unknown as RootState;
describe("EventDuplication", () => {
it("calls onOpenDuplicate when button clicked", () => {
@@ -155,7 +156,7 @@ describe("EventDisplayModal", () => {
expect(
screen.getByDisplayValue(
preloadedState.calendars.list["667037022b752d0026472254/cal1"].events
.event1.title
.event1.title as string
)
).toBeInTheDocument();
});
@@ -4,7 +4,7 @@ import {
DATETIME_WITH_SECONDS_LENGTH,
DATETIME_FORMAT_WITH_SECONDS,
DATETIME_FORMAT_WITHOUT_SECONDS,
} from "../../../../src/components/Event/utils/dateTimeHelpers";
} from "@/components/Event/utils/dateTimeHelpers";
describe("dateTimeHelpers", () => {
describe("Constants", () => {
@@ -1,6 +1,6 @@
import CalendarLayout from "@/components/Calendar/CalendarLayout";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import { renderWithProviders } from "../utils/Renderwithproviders";
import CalendarLayout from "../../src/components/Calendar/CalendarLayout";
describe("Event Error Handling", () => {
beforeEach(() => {
+10 -10
View File
@@ -1,6 +1,14 @@
import * as appHooks from "@/app/hooks";
import { AppDispatch } from "@/app/store";
import CalendarApp from "@/components/Calendar/Calendar";
import {
createEventHandlers,
EventHandlersProps,
} from "@/components/Calendar/handlers/eventHandlers";
import * as eventThunks from "@/features/Calendars/services";
import EventUpdateModal from "@/features/Events/EventUpdateModal";
import { CalendarApi } from "@fullcalendar/core";
import { jest } from "@jest/globals";
import { ThunkDispatch } from "@reduxjs/toolkit";
import "@testing-library/jest-dom";
import {
act,
@@ -9,15 +17,7 @@ import {
waitFor,
within,
} from "@testing-library/react";
import * as appHooks from "../../src/app/hooks";
import * as eventThunks from "../../src/features/Calendars/CalendarSlice";
import CalendarApp from "../../src/components/Calendar/Calendar";
import EventUpdateModal from "../../src/features/Events/EventUpdateModal";
import { renderWithProviders } from "../utils/Renderwithproviders";
import {
createEventHandlers,
EventHandlersProps,
} from "../../src/components/Calendar/handlers/eventHandlers";
describe("CalendarApp integration", () => {
const today = new Date();
@@ -28,7 +28,7 @@ describe("CalendarApp integration", () => {
beforeEach(() => {
jest.clearAllMocks();
const dispatch = jest.fn() as ThunkDispatch<any, any, any>;
const dispatch = jest.fn() as AppDispatch;
jest.spyOn(appHooks, "useAppDispatch").mockReturnValue(dispatch);
});
+3 -3
View File
@@ -1,8 +1,8 @@
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import { Menubar } from "@/components/Menubar/Menubar";
import * as oidcAuth from "@/features/User/oidcAuth";
import "@testing-library/jest-dom";
import { Menubar } from "../../src/components/Menubar/Menubar";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import { renderWithProviders } from "../utils/Renderwithproviders";
import * as oidcAuth from "../../src/features/User/oidcAuth";
describe("Calendar App Component Display Tests", () => {
const preloadedState = {
@@ -1,15 +1,15 @@
import { renderWithProviders } from "../utils/Renderwithproviders";
import { screen } from "@testing-library/react";
import * as appHooks from "@/app/hooks";
import { AppDispatch } from "@/app/store";
import CalendarApp from "@/components/Calendar/Calendar";
import { jest } from "@jest/globals";
import CalendarApp from "../../src/components/Calendar/Calendar";
import * as appHooks from "../../src/app/hooks";
import { ThunkDispatch } from "@reduxjs/toolkit";
import { screen } from "@testing-library/react";
import { renderWithProviders } from "../utils/Renderwithproviders";
describe("MiniCalendar", () => {
const day = new Date();
beforeEach(() => {
jest.clearAllMocks();
const dispatch = jest.fn() as ThunkDispatch<any, any, any>;
const dispatch = jest.fn() as AppDispatch;
jest.spyOn(appHooks, "useAppDispatch").mockReturnValue(dispatch);
jest.useFakeTimers().clearAllTimers();
});
+4 -7
View File
@@ -1,13 +1,10 @@
import { screen, fireEvent, waitFor, act } from "@testing-library/react";
import { PeopleSearch, User } from "@/components/Attendees/PeopleSearch";
import { searchUsers } from "@/features/User/userAPI";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import {
User,
PeopleSearch,
} from "../../src/components/Attendees/PeopleSearch";
import { renderWithProviders } from "../utils/Renderwithproviders";
import { searchUsers } from "../../src/features/User/userAPI";
jest.mock("../../src/features/User/userAPI");
jest.mock("@/features/User/userAPI");
const mockedSearchUsers = searchUsers as jest.MockedFunction<
typeof searchUsers
>;
+6 -9
View File
@@ -1,13 +1,10 @@
import { screen, fireEvent, waitFor, act } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "../utils/Renderwithproviders";
import RepeatEvent from "../../src/components/Event/EventRepeat";
import EventPopover from "../../src/features/Events/EventModal";
import { RepetitionObject } from "../../src/features/Events/EventsTypes";
import RepeatEvent from "@/components/Event/EventRepeat";
import * as eventThunks from "@/features/Calendars/services";
import EventPopover from "@/features/Events/EventModal";
import { RepetitionObject } from "@/features/Events/EventsTypes";
import { DateSelectArg } from "@fullcalendar/core";
import { formatDateToYYYYMMDDTHHMMSS } from "../../src/utils/dateUtils";
import * as eventThunks from "../../src/features/Calendars/CalendarSlice";
import * as apiUtils from "../../src/utils/apiUtils";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import { renderWithProviders } from "../utils/Renderwithproviders";
const baseRepetition: RepetitionObject = {
freq: "",
@@ -1,8 +1,7 @@
import { ResponsiveDialog } from "@/components/Dialog";
import { Button, TextField, TwakeMuiThemeProvider } from "@linagora/twake-mui";
import { fireEvent, render, screen } from "@testing-library/react";
import React from "react";
import { ResponsiveDialog } from "../../src/components/Dialog";
import { Button, TextField } from "@linagora/twake-mui";
import { TwakeMuiThemeProvider } from "@linagora/twake-mui";
describe("ResponsiveDialog", () => {
const mockOnClose = jest.fn();
@@ -1,5 +1,3 @@
// __test__/features/calendars/calendarApi.test.ts
import {
addSharedCalendar,
exportCalendar,
@@ -9,12 +7,12 @@ import {
postCalendar,
proppatchCalendar,
removeCalendar,
} from "../../../src/features/Calendars/CalendarApi";
import { clientConfig } from "../../../src/features/User/oidcAuth";
import { api } from "../../../src/utils/apiUtils";
} from "@/features/Calendars/CalendarApi";
import { clientConfig } from "@/features/User/oidcAuth";
import { api } from "@/utils/apiUtils";
clientConfig.url = "https://example.com";
jest.mock("../../../src/utils/apiUtils");
jest.mock("@/utils/apiUtils");
describe("Calendar API", () => {
afterEach(() => {
@@ -1,11 +1,11 @@
import { screen, fireEvent, waitFor } from "@testing-library/react";
import CalendarPopover from "../../../src/components/Calendar/CalendarModal";
import CalendarPopover from "@/components/Calendar/CalendarModal";
import { getSecretLink } from "@/features/Calendars/CalendarApi";
import { Calendar } from "@/features/Calendars/CalendarTypes";
import * as eventThunks from "@/features/Calendars/services";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
import { Calendar } from "../../../src/features/Calendars/CalendarTypes";
import { getSecretLink } from "../../../src/features/Calendars/CalendarApi";
jest.mock("../../../src/features/Calendars/CalendarApi", () => ({
jest.mock("@/features/Calendars/CalendarApi", () => ({
getSecretLink: jest.fn(),
}));
@@ -108,7 +108,7 @@ describe("CalendarPopover (editing mode)", () => {
link: "/calendars/user/cal1",
name: "Work Calendar",
description: "Team meetings",
color: "#33B679",
color: { light: "#33B679" },
owner: "alice",
ownerEmails: ["alice@example.com"],
visibility: "public",
@@ -181,7 +181,7 @@ describe("CalendarPopover (editing mode)", () => {
calId: "user1/cal1",
calLink: "/calendars/user/cal1",
patch: {
color: "#33B679",
color: { light: "#33B679" },
desc: "Team meetings",
name: "Updated Calendar",
},
@@ -213,7 +213,7 @@ describe("CalendarPopover - Tabs Scenarios", () => {
link: "/calendars/user1/cal1.json",
name: "Work Calendar",
description: "Team meetings",
color: "#33B679",
color: { light: "#33B679" },
owner: "alice",
ownerEmails: ["alice@example.com"],
visibility: "public",
@@ -1,37 +1,36 @@
import * as calAPI from "@/features/Calendars/CalendarApi";
import reducer, {
addEvent,
removeEvent,
createCalendar,
updateEventLocal,
removeEvent,
removeTempCal,
getTempCalendarsListAsync,
putEventAsync,
updateEventLocal,
} from "@/features/Calendars/CalendarSlice";
import { Calendar } from "@/features/Calendars/CalendarTypes";
import {
addSharedCalendarAsync,
createCalendarAsync,
deleteEventAsync,
getCalendarDetailAsync,
getCalendarsListAsync,
getEventAsync,
patchCalendarAsync,
removeCalendarAsync,
getTempCalendarsListAsync,
moveEventAsync,
patchACLCalendarAsync,
createCalendarAsync,
addSharedCalendarAsync,
deleteEventAsync,
} from "../../../src/features/Calendars/CalendarSlice";
import { getCalendarsListAsync } from "../../../src/features/Calendars/services/getCalendarsListAsync";
import { getCalendarDetailAsync } from "../../../src/features/Calendars/services/getCalendarDetailAsync";
import * as calAPI from "../../../src/features/Calendars/CalendarApi";
import * as userAPI from "../../../src/features/User/userAPI";
patchCalendarAsync,
putEventAsync,
removeCalendarAsync,
} from "@/features/Calendars/services";
import { CalendarEvent } from "@/features/Events/EventsTypes";
import * as userAPI from "@/features/User/userAPI";
import userReducer, { setUserData } from "@/features/User/userSlice";
import { configureStore } from "@reduxjs/toolkit";
import { Calendar } from "../../../src/features/Calendars/CalendarTypes";
import { CalendarEvent } from "../../../src/features/Events/EventsTypes";
import { setUserData } from "../../../src/features/User/userSlice";
import userReducer from "../../../src/features/User/userSlice";
jest.mock("../../../src/features/Calendars/CalendarApi");
jest.mock("../../../src/features/User/userAPI");
jest.mock("../../../src/features/Events/EventApi");
jest.mock("../../../src/features/Events/eventUtils");
jest.mock("../../../src/utils/apiUtils");
jest.mock("@/features/Calendars/CalendarApi");
jest.mock("@/features/User/userAPI");
jest.mock("@/features/Events/EventApi");
jest.mock("@/features/Events/eventUtils");
jest.mock("@/utils/apiUtils");
describe("CalendarSlice", () => {
const initialState = {
@@ -1,10 +1,10 @@
import CalendarApp from "@/components/Calendar/Calendar";
import * as calendarUtils from "@/components/Calendar/utils/calendarUtils";
import { updateSlotLabelVisibility } from "@/components/Calendar/utils/calendarUtils";
import EventPreviewModal from "@/features/Events/EventDisplayPreview";
import { CalendarEvent } from "@/features/Events/EventsTypes";
import * as SettingsSlice from "@/features/Settings/SettingsSlice";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import CalendarApp from "../../../src/components/Calendar/Calendar";
import { updateSlotLabelVisibility } from "../../../src/components/Calendar/utils/calendarUtils";
import EventPreviewModal from "../../../src/features/Events/EventDisplayPreview";
import * as SettingsSlice from "../../../src/features/Settings/SettingsSlice";
import * as calendarUtils from "../../../src/components/Calendar/utils/calendarUtils";
import { CalendarEvent } from "../../../src/features/Events/EventsTypes";
import { renderWithProviders } from "../../utils/Renderwithproviders";
describe("Calendar - Timezone Integration", () => {
@@ -199,7 +199,6 @@ describe("EventDisplayPreview - Timezone Display", () => {
onClose={mockOnClose}
eventId="allDayEvent"
calId="user1/cal1"
event={allDayEvent}
/>,
baseState
);
@@ -236,7 +235,6 @@ describe("EventDisplayPreview - Timezone Display", () => {
eventId="event1"
calId="user1/cal1"
onClose={mockOnClose}
event={baseEvent}
/>,
state
);
@@ -1,5 +1,5 @@
import { screen, fireEvent, waitFor, cleanup } from "@testing-library/react";
import { TimezoneSelector } from "../../../src/components/Calendar/TimezoneSelector";
import { TimezoneSelector } from "@/components/Calendar/TimezoneSelector";
import { cleanup, fireEvent, screen, waitFor } from "@testing-library/react";
import { renderWithProviders } from "../../utils/Renderwithproviders";
describe("TimezoneSelector", () => {
@@ -1,16 +1,16 @@
import { configureStore } from "@reduxjs/toolkit";
import reducer from "../../../../src/features/Calendars/CalendarSlice";
import * as fetchSyncTokenChanges from "@/features/Calendars/api/fetchSyncTokenChanges";
import reducer from "@/features/Calendars/CalendarSlice";
import { Calendar } from "@/features/Calendars/CalendarTypes";
import {
refreshCalendarWithSyncToken,
SyncTokenUpdates,
} from "../../../../src/features/Calendars/services/refreshCalendar";
import { Calendar } from "../../../../src/features/Calendars/CalendarTypes";
import { CalendarEvent } from "../../../../src/features/Events/EventsTypes";
import * as fetchSyncTokenChanges from "../../../../src/features/Calendars/api/fetchSyncTokenChanges";
import * as EventApi from "../../../../src/features/Events/EventApi";
} from "@/features/Calendars/services/refreshCalendar";
import * as EventApi from "@/features/Events/EventApi";
import { CalendarEvent } from "@/features/Events/EventsTypes";
import { configureStore } from "@reduxjs/toolkit";
jest.mock("../../../../src/features/Calendars/api/fetchSyncTokenChanges");
jest.mock("../../../../src/features/Events/EventApi");
jest.mock("@/features/Calendars/api/fetchSyncTokenChanges");
jest.mock("@/features/Events/EventApi");
describe("refreshCalendarWithSyncToken", () => {
const mockCalendar: Calendar = {
@@ -1,4 +1,4 @@
import { EventErrorHandler } from "../../../src/components/Error/EventErrorHandler";
import { EventErrorHandler } from "@/components/Error/EventErrorHandler";
describe("EventErrorHandler", () => {
it("calls the callback when a new error is reported", () => {
+9 -8
View File
@@ -1,17 +1,18 @@
import {
putEvent,
moveEvent,
deleteEvent,
importEventFromFile,
moveEvent,
putEvent,
searchEvent,
} from "../../../src/features/Events/EventApi";
import { CalendarEvent } from "../../../src/features/Events/EventsTypes";
import { calendarEventToJCal } from "../../../src/features/Events/eventUtils";
import { clientConfig } from "../../../src/features/User/oidcAuth";
import { api } from "../../../src/utils/apiUtils";
} from "@/features/Events/EventApi";
import { CalendarEvent } from "@/features/Events/EventsTypes";
import { calendarEventToJCal } from "@/features/Events/eventUtils";
import { clientConfig } from "@/features/User/oidcAuth";
import { api } from "@/utils/apiUtils";
clientConfig.url = "https://example.com";
jest.mock("../../../src/utils/apiUtils");
jest.mock("@/utils/apiUtils");
const day = new Date();
+18 -17
View File
@@ -1,23 +1,24 @@
import * as appHooks from "@/app/hooks";
import { AppDispatch } from "@/app/store";
import { InfoRow } from "@/components/Event/InfoRow";
import { LONG_DATE_FORMAT } from "@/components/Event/utils/dateTimeFormatters";
import {
stringAvatar,
stringToColor,
} from "@/components/Event/utils/eventUtils";
import * as calendarSlice from "@/features/Calendars/CalendarSlice";
import * as eventThunks from "@/features/Calendars/services";
import EventPreviewModal from "@/features/Events/EventDisplayPreview";
import EventUpdateModal from "@/features/Events/EventUpdateModal";
import {
screen,
fireEvent,
waitFor,
act,
cleanup,
fireEvent,
screen,
waitFor,
} from "@testing-library/react";
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import EventUpdateModal from "../../../src/features/Events/EventUpdateModal";
import EventPreviewModal from "../../../src/features/Events/EventDisplayPreview";
import { InfoRow } from "../../../src/components/Event/InfoRow";
import {
stringToColor,
stringAvatar,
} from "../../../src/components/Event/utils/eventUtils";
import * as appHooks from "../../../src/app/hooks";
import { ThunkDispatch } from "@reduxjs/toolkit";
import dayjs from "dayjs";
import { LONG_DATE_FORMAT } from "../../../src/components/Event/utils/dateTimeFormatters";
import { renderWithProviders } from "../../utils/Renderwithproviders";
describe("Event Preview Display", () => {
const mockOnClose = jest.fn();
@@ -747,7 +748,7 @@ describe("Event Preview Display", () => {
beforeEach(() => {
jest.clearAllMocks();
const dispatch = jest.fn() as ThunkDispatch<any, any, any>;
const dispatch = jest.fn() as AppDispatch;
jest.spyOn(appHooks, "useAppDispatch").mockReturnValue(dispatch);
});
@@ -1831,7 +1832,7 @@ describe("Event Full Display", () => {
(promise as any).unwrap = () => promise;
return () => promise as any;
});
const spyRemove = jest.spyOn(eventThunks, "removeEvent");
const spyRemove = jest.spyOn(calendarSlice, "removeEvent");
const testDate = new Date("2025-01-15T10:00:00.000Z");
const testEndDate = new Date("2025-01-15T11:00:00.000Z");
+4 -4
View File
@@ -1,12 +1,12 @@
import * as eventThunks from "@/features/Calendars/services";
import EventPopover from "@/features/Events/EventModal";
import { api } from "@/utils/apiUtils";
import { DateSelectArg } from "@fullcalendar/core";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
import EventPopover from "../../../src/features/Events/EventModal";
import { api } from "../../../src/utils/apiUtils";
import { renderWithProviders } from "../../utils/Renderwithproviders";
jest.mock("../../../src/utils/apiUtils");
jest.mock("@/utils/apiUtils");
describe("EventPopover", () => {
beforeEach(() => {
@@ -1,26 +1,25 @@
import { screen, fireEvent, waitFor, act } from "@testing-library/react";
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import EventUpdateModal from "../../../src/features/Events/EventUpdateModal";
import { EditModeDialog } from "../../../src/components/Event/EditModeDialog";
import * as EventApi from "../../../src/features/Events/EventApi";
import { RootState } from "@/app/store";
import {
createEventHandlers,
EventHandlersProps,
} from "../../../src/components/Calendar/handlers/eventHandlers";
import EventPreviewModal from "../../../src/features/Events/EventDisplayPreview";
} from "@/components/Calendar/handlers/eventHandlers";
import { EditModeDialog } from "@/components/Event/EditModeDialog";
import * as eventThunks from "@/features/Calendars/services";
import * as EventApi from "@/features/Events/EventApi";
import EventPreviewModal from "@/features/Events/EventDisplayPreview";
import EventUpdateModal from "@/features/Events/EventUpdateModal";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import preview from "jest-preview";
import { renderWithProviders } from "../../utils/Renderwithproviders";
jest.mock("../../../src/components/Event/utils/eventUtils", () => {
const actual = jest.requireActual(
"../../../src/components/Event/utils/eventUtils"
);
jest.mock("@/components/Event/utils/eventUtils", () => {
const actual = jest.requireActual("@/components/Event/utils/eventUtils");
return {
...actual,
refreshCalendars: jest.fn(() => Promise.resolve()),
refreshSingularCalendar: jest.fn(() => Promise.resolve()),
};
});
import preview from "jest-preview";
const mockOnClose = jest.fn();
const day = new Date("2025-03-15T10:00:00Z");
@@ -102,7 +101,7 @@ const basePreloadedState = {
pending: false,
templist: {},
},
};
} as unknown as RootState;
describe("EditModeDialog Component", () => {
beforeEach(() => {
@@ -946,7 +945,7 @@ describe("handleRSVP function", () => {
const {
handleRSVP,
} = require("../../../src/components/Event/eventHandlers/eventHandlers");
} = require("@/components/Event/eventHandlers/eventHandlers");
jest.spyOn(eventThunks, "putEventAsync").mockImplementation((payload) => {
const promise = Promise.resolve(payload);
@@ -992,7 +991,7 @@ describe("handleDelete function", () => {
const {
handleDelete,
} = require("../../../src/components/Event/eventHandlers/eventHandlers");
} = require("@/components/Event/eventHandlers/eventHandlers");
jest
.spyOn(eventThunks, "deleteEventAsync")
@@ -1028,7 +1027,7 @@ describe("handleDelete function", () => {
const {
handleDelete,
} = require("../../../src/components/Event/eventHandlers/eventHandlers");
} = require("@/components/Event/eventHandlers/eventHandlers");
jest
.spyOn(eventThunks, "deleteEventInstanceAsync")
@@ -1059,7 +1058,7 @@ describe("handleDelete function", () => {
const {
handleDelete,
} = require("../../../src/components/Event/eventHandlers/eventHandlers");
} = require("@/components/Event/eventHandlers/eventHandlers");
jest
.spyOn(eventThunks, "deleteEventAsync")
@@ -1,12 +1,12 @@
import { screen, fireEvent, waitFor, act } from "@testing-library/react";
import * as eventUtils from "@/components/Event/utils/eventUtils";
import * as CalendarApi from "@/features/Calendars/CalendarApi";
import * as EventApi from "@/features/Events/EventApi";
import EventUpdateModal from "@/features/Events/EventUpdateModal";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import EventUpdateModal from "../../../src/features/Events/EventUpdateModal";
import * as EventApi from "../../../src/features/Events/EventApi";
import * as CalendarApi from "../../../src/features/Calendars/CalendarApi";
import * as eventUtils from "../../../src/components/Event/utils/eventUtils";
jest.mock("../../../src/features/Events/EventApi");
jest.mock("../../../src/features/Calendars/CalendarApi");
jest.mock("@/features/Events/EventApi");
jest.mock("@/features/Calendars/CalendarApi");
describe("EventUpdateModal Timezone Handling", () => {
const mockOnClose = jest.fn();
@@ -1,7 +1,6 @@
import { screen, fireEvent } from "@testing-library/react";
import ImportAlert from "@/features/Events/ImportAlert";
import { fireEvent, screen } from "@testing-library/react";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import ImportAlert from "../../../src/features/Events/ImportAlert";
import { clearError } from "../../../src/features/Calendars/CalendarSlice";
// Mock the ErrorSnackbar component since we want to test ImportAlert logic,
// but we can also test integration if we don't mock it.
+16 -15
View File
@@ -1,21 +1,22 @@
import * as appHooks from "@/app/hooks";
import CalendarLayout from "@/components/Calendar/CalendarLayout";
import * as calendarUtils from "@/components/Calendar/utils/calendarUtils";
import * as eventUtils from "@/components/Event/utils/eventUtils";
import * as CalendarSlice from "@/features/Calendars/CalendarSlice";
import { Calendar } from "@/features/Calendars/CalendarTypes";
import * as eventThunks from "@/features/Calendars/services";
import EventPreviewModal from "@/features/Events/EventDisplayPreview";
import EventPopover from "@/features/Events/EventModal";
import { CalendarEvent } from "@/features/Events/EventsTypes";
import EventUpdateModal from "@/features/Events/EventUpdateModal";
import * as userApi from "@/features/User/userAPI";
import { DateSelectArg } from "@fullcalendar/core";
import { jest } from "@jest/globals";
import { ThunkDispatch } from "@reduxjs/toolkit";
import "@testing-library/jest-dom";
import { screen, waitFor, fireEvent, act } from "@testing-library/react";
import * as appHooks from "../../../src/app/hooks";
import * as eventUtils from "../../../src/components/Event/utils/eventUtils";
import * as userApi from "../../../src/features/User/userAPI";
import * as calendarUtils from "../../../src/components/Calendar/utils/calendarUtils";
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
import EventPreviewModal from "../../../src/features/Events/EventDisplayPreview";
import EventPopover from "../../../src/features/Events/EventModal";
import EventUpdateModal from "../../../src/features/Events/EventUpdateModal";
import CalendarLayout from "../../../src/components/Calendar/CalendarLayout";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import { act, fireEvent, screen, waitFor } from "@testing-library/react";
import { SpiedFunction } from "jest-mock";
import { Calendar } from "../../../src/features/Calendars/CalendarTypes";
import { CalendarEvent } from "../../../src/features/Events/EventsTypes";
import { DateSelectArg } from "@fullcalendar/core";
import { renderWithProviders } from "../../utils/Renderwithproviders";
describe("Update tempcalendars called with correct params", () => {
const today = new Date();
@@ -612,7 +613,7 @@ describe("Update tempcalendars called with correct params", () => {
});
it("should call emptyEventsCal with correct params before refreshing", async () => {
const emptyEventsCalSpy = jest.spyOn(eventThunks, "emptyEventsCal");
const emptyEventsCalSpy = jest.spyOn(CalendarSlice, "emptyEventsCal");
const preloadedState = createPreloadedState(true);
+4 -8
View File
@@ -1,16 +1,12 @@
import {
CalendarEvent,
RepetitionObject,
} from "../../../src/features/Events/EventsTypes";
import { CalendarEvent, RepetitionObject } from "@/features/Events/EventsTypes";
import {
calendarEventToJCal,
parseCalendarEvent,
combineMasterDateWithFormTime,
detectRecurringEventChanges,
normalizeRepetition,
normalizeTimezone,
detectRecurringEventChanges,
} from "../../../src/features/Events/eventUtils";
import { TIMEZONES } from "../../../src/utils/timezone-data";
parseCalendarEvent,
} from "@/features/Events/eventUtils";
describe("parseCalendarEvent", () => {
const baseColor = { light: "#00FF00" };
@@ -1,8 +1,8 @@
import SearchBar from "@/components/Menubar/EventSearchBar";
import * as searchThunk from "@/features/Search/SearchSlice";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import SearchBar from "../../../src/components/Menubar/EventSearchBar";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import * as searchThunk from "../../../src/features/Search/SearchSlice";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "../../utils/Renderwithproviders";
describe("EventSearchBar", () => {
const today = new Date();
@@ -1,5 +1,5 @@
import SearchResultsPage from "@/features/Search/SearchResultsPage";
import { screen } from "@testing-library/react";
import SearchResultsPage from "../../../src/features/Search/SearchResultsPage";
import { renderWithProviders } from "../../utils/Renderwithproviders";
describe("SearchResultsPage", () => {
@@ -1,13 +1,12 @@
// SearchSlice.test.ts
import { configureStore } from "@reduxjs/toolkit";
import * as EventApi from "@/features/Events/EventApi";
import searchResultReducer, {
searchEventsAsync,
setResults,
setHits,
} from "../../../src/features/Search/SearchSlice";
import * as EventApi from "../../../src/features/Events/EventApi";
setResults,
} from "@/features/Search/SearchSlice";
import { configureStore } from "@reduxjs/toolkit";
jest.mock("../../../src/features/Events/EventApi");
jest.mock("@/features/Events/EventApi");
describe("SearchSlice", () => {
let store: any;
@@ -1,19 +1,19 @@
import { configureStore } from "@reduxjs/toolkit";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import SettingsPage from "../../../src/features/Settings/SettingsPage";
import SettingsPage from "@/features/Settings/SettingsPage";
import settingsReducer, {
setIsBrowserDefaultTimeZone,
setTimeZone,
} from "../../../src/features/Settings/SettingsSlice";
} from "@/features/Settings/SettingsSlice";
import userReducer, {
getOpenPaasUserDataAsync,
setTimezone as setUserTimeZone,
} from "../../../src/features/User/userSlice";
import { api } from "../../../src/utils/apiUtils";
import { browserDefaultTimeZone } from "../../../src/utils/timezone";
} from "@/features/User/userSlice";
import { api } from "@/utils/apiUtils";
import { browserDefaultTimeZone } from "@/utils/timezone";
import { configureStore } from "@reduxjs/toolkit";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import { renderWithProviders } from "../../utils/Renderwithproviders";
jest.mock("../../../src/utils/apiUtils");
jest.mock("@/utils/apiUtils");
describe("Timezone synchronization after getOpenPaasUserDataAsync", () => {
let apiGetSpy: jest.SpyInstance;
@@ -1,10 +1,10 @@
import { fireEvent, screen, waitFor } from "@testing-library/react";
import SettingsPage from "@/features/Settings/SettingsPage";
import { api } from "@/utils/apiUtils";
import "@testing-library/jest-dom";
import SettingsPage from "../../../src/features/Settings/SettingsPage";
import { fireEvent, screen, waitFor } from "@testing-library/react";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import { api } from "../../../src/utils/apiUtils";
jest.mock("../../../src/utils/apiUtils");
jest.mock("@/utils/apiUtils");
describe("SettingsPage", () => {
beforeEach(() => {
+8 -8
View File
@@ -1,12 +1,12 @@
import * as appHooks from "@/app/hooks";
import { AppDispatch } from "@/app/store";
import HandleLogin from "@/features/User/HandleLogin";
import * as oidcAuth from "@/features/User/oidcAuth";
import { clientConfig } from "@/features/User/oidcAuth";
import * as apiUtils from "@/utils/apiUtils";
import { screen, waitFor } from "@testing-library/react";
import thunk, { ThunkDispatch } from "redux-thunk";
import HandleLogin from "../../../src/features/User/HandleLogin";
import * as oidcAuth from "../../../src/features/User/oidcAuth";
import { renderWithProviders } from "../../utils/Renderwithproviders";
import { clientConfig } from "../../../src/features/User/oidcAuth";
import * as apiUtils from "../../../src/utils/apiUtils";
import * as appHooks from "../../../src/app/hooks";
import { push } from "redux-first-history";
import { renderWithProviders } from "../../utils/Renderwithproviders";
clientConfig.url = "https://example.com";
@@ -14,7 +14,7 @@ describe("HandleLogin", () => {
beforeEach(() => {
jest.clearAllMocks();
jest.spyOn(apiUtils, "redirectTo").mockImplementation(() => {});
const dispatch = jest.fn() as ThunkDispatch<any, any, any>;
const dispatch = jest.fn() as AppDispatch;
jest.spyOn(appHooks, "useAppDispatch").mockReturnValue(dispatch);
sessionStorage.clear();
});
+24 -28
View File
@@ -1,28 +1,27 @@
// __test__/features/user/CallbackResume.test.tsx
import { render, waitFor } from "@testing-library/react";
import { CallbackResume } from "../../../src/features/User/LoginCallback";
import { useAppDispatch } from "../../../src/app/hooks";
import * as oidcAuth from "../../../src/features/User/oidcAuth";
import { push } from "redux-first-history";
import { useAppDispatch } from "@/app/hooks";
import { getCalendarsListAsync } from "@/features/Calendars/services/getCalendarsListAsync";
import { CallbackResume } from "@/features/User/LoginCallback";
import * as oidcAuth from "@/features/User/oidcAuth";
import {
getOpenPaasUserDataAsync,
setTokens,
setUserData,
getOpenPaasUserDataAsync,
} from "../../../src/features/User/userSlice";
import { getCalendarsListAsync } from "../../../src/features/Calendars/services/getCalendarsListAsync";
} from "@/features/User/userSlice";
import { render, waitFor } from "@testing-library/react";
import { push } from "redux-first-history";
import { renderWithProviders } from "../../utils/Renderwithproviders";
// Mocks
jest.mock("../../../src/app/hooks", () => ({
jest.mock("@/app/hooks", () => ({
useAppDispatch: jest.fn(),
useAppSelector: jest.fn(() => ({})),
}));
jest.mock("../../../src/features/User/oidcAuth", () => ({
jest.mock("@/features/User/oidcAuth", () => ({
Callback: jest.fn(),
}));
jest.mock("../../../src/features/User/userSlice", () => {
jest.mock("@/features/User/userSlice", () => {
const mockGetUser = Object.assign(
jest.fn(() => ({ type: "GET_USER_ID" })),
{
@@ -39,23 +38,20 @@ jest.mock("../../../src/features/User/userSlice", () => {
};
});
jest.mock(
"../../../src/features/Calendars/services/getCalendarsListAsync",
() => {
const mockGetCalendars = Object.assign(
jest.fn(() => ({ type: "GET_CALENDARS" })),
{
pending: { type: "GET_CALENDARS/pending" },
fulfilled: { type: "GET_CALENDARS/fulfilled" },
rejected: { type: "GET_CALENDARS/rejected" },
}
);
jest.mock("@/features/Calendars/services/getCalendarsListAsync", () => {
const mockGetCalendars = Object.assign(
jest.fn(() => ({ type: "GET_CALENDARS" })),
{
pending: { type: "GET_CALENDARS/pending" },
fulfilled: { type: "GET_CALENDARS/fulfilled" },
rejected: { type: "GET_CALENDARS/rejected" },
}
);
return {
getCalendarsListAsync: mockGetCalendars,
};
}
);
return {
getCalendarsListAsync: mockGetCalendars,
};
});
describe("CallbackResume", () => {
const dispatch = jest.fn();
+5 -5
View File
@@ -1,13 +1,13 @@
// __tests__/auth.test.ts
import * as client from "openid-client";
import {
Auth,
Callback,
clientConfig,
getClientConfig,
Auth,
Logout,
Callback,
} from "../../../src/features/User/oidcAuth";
import * as apiUtils from "../../../src/utils/apiUtils";
} from "@/features/User/oidcAuth";
import * as apiUtils from "@/utils/apiUtils";
import * as client from "openid-client";
clientConfig.url = "https://example.com";
const localAdress = "https://local.exemple.com";
+4 -4
View File
@@ -1,11 +1,11 @@
import { clientConfig } from "../../../src/features/User/oidcAuth";
import { clientConfig } from "@/features/User/oidcAuth";
import {
getOpenPaasUser,
updateUserConfigurations,
} from "../../../src/features/User/userAPI";
import { api } from "../../../src/utils/apiUtils";
} from "@/features/User/userAPI";
import { api } from "@/utils/apiUtils";
jest.mock("../../../src/utils/apiUtils");
jest.mock("@/utils/apiUtils");
clientConfig.url = "https://example.com";
@@ -1,11 +1,11 @@
import { cleanup, render, waitFor, act } from "@testing-library/react";
import { Provider } from "react-redux";
import { configureStore } from "@reduxjs/toolkit";
import { setSelectedCalendars } from "@/utils/storage/setSelectedCalendars";
import { createWebSocketConnection } from "@/websocket/connection/createConnection";
import { registerToCalendars } from "@/websocket/operations/registerToCalendars";
import { unregisterToCalendars } from "@/websocket/operations/unregisterToCalendars";
import { WebSocketGate } from "@/websocket/WebSocketGate";
import { setSelectedCalendars } from "@/utils/storage/setSelectedCalendars";
import { configureStore } from "@reduxjs/toolkit";
import { act, cleanup, render, waitFor } from "@testing-library/react";
import { Provider } from "react-redux";
jest.mock("@/websocket/connection/createConnection");
jest.mock("@/websocket/operations/registerToCalendars");
@@ -1,7 +1,7 @@
import { waitFor } from "@testing-library/dom";
import { fetchWebSocketTicket } from "@/websocket/api/fetchWebSocketTicket";
import { createWebSocketConnection } from "@/websocket/connection/createConnection";
import { WS_INBOUND_EVENTS } from "@/websocket/protocols";
import { waitFor } from "@testing-library/dom";
import { setupWebsocket } from "./utils/setupWebsocket";
jest.mock("@/websocket/api/fetchWebSocketTicket");
@@ -1,8 +1,8 @@
import { updateCalendars } from "@/websocket/messaging/updateCalendars";
import { refreshCalendarWithSyncToken } from "@/features/Calendars/services/refreshCalendar";
import { RootState, store } from "@/app/store";
import { WS_INBOUND_EVENTS } from "@/websocket/protocols";
import { refreshCalendarWithSyncToken } from "@/features/Calendars/services/refreshCalendar";
import { getDisplayedCalendarRange } from "@/utils/CalendarRangeManager";
import { updateCalendars } from "@/websocket/messaging/updateCalendars";
import { WS_INBOUND_EVENTS } from "@/websocket/protocols";
import { waitFor } from "@testing-library/dom";
jest.mock("@/features/Calendars/services/refreshCalendar");
@@ -1,5 +1,5 @@
import { WS_INBOUND_EVENTS } from "@/websocket/protocols";
import { parseMessage } from "@/websocket/messaging/parseMessage";
import { WS_INBOUND_EVENTS } from "@/websocket/protocols";
describe("parseMessage", () => {
it("should return empty set for non-object messages", () => {
@@ -1,5 +1,3 @@
// src/websocket/__tests__/unregisterToCalendars.test.ts
import { unregisterToCalendars } from "@/websocket/operations/unregisterToCalendars";
describe("unregisterToCalendars", () => {
+3 -3
View File
@@ -1,9 +1,9 @@
import {
getDisplayedDate,
setDisplayedDateAndRange,
calendarRangeManager,
getDisplayedCalendarRange,
} from "../../src/utils/CalendarRangeManager";
getDisplayedDate,
setDisplayedDateAndRange,
} from "@/utils/CalendarRangeManager";
describe("CalendarRangeManager", () => {
beforeEach(() => {
+3 -3
View File
@@ -1,12 +1,12 @@
import type { AppStore, RootState } from "@/app/store";
import { setupStore } from "@/app/store";
import { TwakeMuiThemeProvider } from "@linagora/twake-mui";
import type { RenderOptions } from "@testing-library/react";
import { render } from "@testing-library/react";
import React, { PropsWithChildren } from "react";
import { Provider } from "react-redux";
import { MemoryRouter } from "react-router-dom";
import { I18nContext } from "twake-i18n";
import { TwakeMuiThemeProvider } from "@linagora/twake-mui";
import type { AppStore, RootState } from "../../src/app/store";
import { setupStore } from "../../src/app/store";
interface ExtendedRenderOptions extends Omit<RenderOptions, "queries"> {
preloadedState?: Partial<RootState>;
store?: AppStore;
+1 -1
View File
@@ -1,4 +1,4 @@
import { getInitials, stringToGradient } from "../../src/utils/avatarUtils";
import { getInitials, stringToGradient } from "@/utils/avatarUtils";
jest.mock("@linagora/twake-mui", () => ({
nameToColor: jest.fn((name: string) => {
+1 -1
View File
@@ -1,4 +1,4 @@
import { getCalendarVisibility } from "../../src/components/Calendar/utils/calendarUtils";
import { getCalendarVisibility } from "@/components/Calendar/utils/calendarUtils";
interface AclEntry {
privilege: string;
+1 -1
View File
@@ -1,4 +1,4 @@
import { getCalendarRange } from "../../src/utils/dateUtils";
import { getCalendarRange } from "@/utils/dateUtils";
describe("getCalendarRange", () => {
it("Nov 2025 (5 weeks): 2025-10-27 to 2025-11-30", () => {
+3 -3
View File
@@ -1,6 +1,6 @@
import { findCalendarById } from "../../src/utils/findCalendarById";
import { Calendar } from "../../src/features/Calendars/CalendarTypes";
import { RootState } from "../../src/app/store";
import { RootState } from "@/app/store";
import { Calendar } from "@/features/Calendars/CalendarTypes";
import { findCalendarById } from "@/utils";
describe("findCalendarById", () => {
const mockCalendar1: Calendar = {
+2 -2
View File
@@ -1,5 +1,5 @@
import { getUserDisplayName } from "../../src/utils/userUtils";
import { userData } from "../../src/features/User/userDataTypes";
import { userData } from "@/features/User/userDataTypes";
import { getUserDisplayName } from "@/utils/userUtils";
describe("userUtils", () => {
describe("getUserDisplayName", () => {