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
@@ -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", () => {