[#64] added tests and fixed broken ones
This commit is contained in:
committed by
Benoit TELLIER
parent
9d43c15ee0
commit
06984ded1a
@@ -176,7 +176,7 @@ describe("Found Bugs", () => {
|
|||||||
fireEvent.click(nextMonthButton);
|
fireEvent.click(nextMonthButton);
|
||||||
fireEvent.click(previousMonthButton);
|
fireEvent.click(previousMonthButton);
|
||||||
const selectedTile = screen.getByText((content, element) => {
|
const selectedTile = screen.getByText((content, element) => {
|
||||||
return element?.className.includes("selectedWeek") ?? false;
|
return element?.classList.contains("selectedWeek") ?? false;
|
||||||
});
|
});
|
||||||
const ariaLabel = screen.getByRole("columnheader");
|
const ariaLabel = screen.getByRole("columnheader");
|
||||||
const shownDayDate = new Date(
|
const shownDayDate = new Date(
|
||||||
@@ -202,7 +202,7 @@ describe("Found Bugs", () => {
|
|||||||
fireEvent.click(nextMonthButton);
|
fireEvent.click(nextMonthButton);
|
||||||
const miniCalMonth = await screen.findByTitle(/mini calendar month/i);
|
const miniCalMonth = await screen.findByTitle(/mini calendar month/i);
|
||||||
const fullCalMonth = screen.getByText((content, element) => {
|
const fullCalMonth = screen.getByText((content, element) => {
|
||||||
return element?.className.includes("fc-toolbar-title") ?? false;
|
return element?.classList.contains("fc-toolbar-title") ?? false;
|
||||||
});
|
});
|
||||||
expect(miniCalMonth.innerHTML).toBe(fullCalMonth.innerHTML);
|
expect(miniCalMonth.innerHTML).toBe(fullCalMonth.innerHTML);
|
||||||
fireEvent.click(nextMonthButton);
|
fireEvent.click(nextMonthButton);
|
||||||
@@ -218,7 +218,7 @@ describe("Found Bugs", () => {
|
|||||||
fireEvent.click(nextDayButton);
|
fireEvent.click(nextDayButton);
|
||||||
|
|
||||||
const dayViewSelectedTiles = screen.getAllByText((content, element) => {
|
const dayViewSelectedTiles = screen.getAllByText((content, element) => {
|
||||||
return element?.className.includes("selectedWeek") ?? false;
|
return element?.classList.contains("selectedWeek") ?? false;
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(dayViewSelectedTiles).toHaveLength(1);
|
expect(dayViewSelectedTiles).toHaveLength(1);
|
||||||
@@ -226,7 +226,7 @@ describe("Found Bugs", () => {
|
|||||||
fireEvent.click(weekViewButton);
|
fireEvent.click(weekViewButton);
|
||||||
|
|
||||||
const weekViewSelectedTiles = screen.getAllByText((content, element) => {
|
const weekViewSelectedTiles = screen.getAllByText((content, element) => {
|
||||||
return element?.className.includes("selectedWeek") ?? false;
|
return element?.classList.contains("selectedWeek") ?? false;
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(weekViewSelectedTiles).toHaveLength(7);
|
expect(weekViewSelectedTiles).toHaveLength(7);
|
||||||
@@ -240,7 +240,7 @@ describe("Found Bugs", () => {
|
|||||||
|
|
||||||
const miniCalMonth = await screen.findByTitle(/mini calendar month/i);
|
const miniCalMonth = await screen.findByTitle(/mini calendar month/i);
|
||||||
const fullCalMonth = screen.getByText((content, element) => {
|
const fullCalMonth = screen.getByText((content, element) => {
|
||||||
return element?.className.includes("fc-toolbar-title") ?? false;
|
return element?.classList.contains("fc-toolbar-title") ?? false;
|
||||||
});
|
});
|
||||||
expect(miniCalMonth.innerHTML).toBe(fullCalMonth.innerHTML);
|
expect(miniCalMonth.innerHTML).toBe(fullCalMonth.innerHTML);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import {
|
import {
|
||||||
getCalendar,
|
getCalendar,
|
||||||
getCalendars,
|
getCalendars,
|
||||||
|
postCalendar,
|
||||||
} from "../../../src/features/Calendars/CalendarApi";
|
} from "../../../src/features/Calendars/CalendarApi";
|
||||||
import { clientConfig } from "../../../src/features/User/oidcAuth";
|
import { clientConfig } from "../../../src/features/User/oidcAuth";
|
||||||
import { api } from "../../../src/utils/apiUtils";
|
import { api } from "../../../src/utils/apiUtils";
|
||||||
@@ -15,48 +16,65 @@ describe("Calendar API", () => {
|
|||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getCalendars", () => {
|
it("fetches calendar list for a user", async () => {
|
||||||
it("fetches calendar list for a user", async () => {
|
const mockUserId = "user123";
|
||||||
const mockUserId = "user123";
|
const mockResponse = [{ id: "calendar1" }, { id: "calendar2" }];
|
||||||
const mockResponse = [{ id: "calendar1" }, { id: "calendar2" }];
|
|
||||||
|
|
||||||
(api.get as jest.Mock).mockReturnValue({
|
(api.get as jest.Mock).mockReturnValue({
|
||||||
json: jest.fn().mockResolvedValue(mockResponse),
|
json: jest.fn().mockResolvedValue(mockResponse),
|
||||||
});
|
|
||||||
|
|
||||||
const calendars = await getCalendars(mockUserId);
|
|
||||||
|
|
||||||
expect(api.get).toHaveBeenCalledWith(
|
|
||||||
`dav/calendars/${mockUserId}.json?personal=true&sharedDelegationStatus=accepted&sharedPublicSubscription=true&withRights=true`,
|
|
||||||
{
|
|
||||||
headers: { Accept: "application/calendar+json" },
|
|
||||||
}
|
|
||||||
);
|
|
||||||
expect(calendars).toEqual(mockResponse);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const calendars = await getCalendars(mockUserId);
|
||||||
|
|
||||||
|
expect(api.get).toHaveBeenCalledWith(
|
||||||
|
`dav/calendars/${mockUserId}.json?personal=true&sharedDelegationStatus=accepted&sharedPublicSubscription=true&withRights=true`,
|
||||||
|
{
|
||||||
|
headers: { Accept: "application/calendar+json" },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
expect(calendars).toEqual(mockResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getCalendar", () => {
|
it("fetches calendar events for a given ID and match window", async () => {
|
||||||
it("fetches calendar events for a given ID and match window", async () => {
|
const calendarId = "calendar1";
|
||||||
const calendarId = "calendar1";
|
const match = { start: "2025-07-01", end: "2025-07-31" };
|
||||||
const match = { start: "2025-07-01", end: "2025-07-31" };
|
const mockCalendarData = { events: ["event1", "event2"] };
|
||||||
const mockCalendarData = { events: ["event1", "event2"] };
|
|
||||||
|
|
||||||
(api as unknown as jest.Mock).mockReturnValue({
|
(api as unknown as jest.Mock).mockReturnValue({
|
||||||
json: jest.fn().mockResolvedValue(mockCalendarData),
|
json: jest.fn().mockResolvedValue(mockCalendarData),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await getCalendar(calendarId, match);
|
const result = await getCalendar(calendarId, match);
|
||||||
|
|
||||||
expect(api).toHaveBeenCalledWith(`dav/calendars/${calendarId}.json`, {
|
expect(api).toHaveBeenCalledWith(`dav/calendars/${calendarId}.json`, {
|
||||||
method: "REPORT",
|
method: "REPORT",
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json, text/plain, */*",
|
Accept: "application/json, text/plain, */*",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ match }),
|
body: JSON.stringify({ match }),
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result).toEqual(mockCalendarData);
|
expect(result).toEqual(mockCalendarData);
|
||||||
|
});
|
||||||
|
it("postCalendar", async () => {
|
||||||
|
const calId = "calId";
|
||||||
|
const userId = "userId";
|
||||||
|
const color = "calId";
|
||||||
|
const name = "new cal";
|
||||||
|
const desc = "desc";
|
||||||
|
|
||||||
|
const result = await postCalendar(userId, calId, color, name, desc);
|
||||||
|
|
||||||
|
expect(api.post).toHaveBeenCalledWith(`dav/calendars/${userId}.json`, {
|
||||||
|
headers: {
|
||||||
|
Accept: "application/json, text/plain, */*",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
id: "calId",
|
||||||
|
"dav:name": "new cal",
|
||||||
|
"apple:color": "calId",
|
||||||
|
"caldav:description": "desc",
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,16 +3,13 @@ import { useAppDispatch } from "../../../src/app/hooks";
|
|||||||
import { createCalendar } from "../../../src/features/Calendars/CalendarSlice";
|
import { createCalendar } from "../../../src/features/Calendars/CalendarSlice";
|
||||||
import CalendarPopover from "../../../src/features/Calendars/CalendarModal";
|
import CalendarPopover from "../../../src/features/Calendars/CalendarModal";
|
||||||
import { renderWithProviders } from "../../utils/Renderwithproviders";
|
import { renderWithProviders } from "../../utils/Renderwithproviders";
|
||||||
|
import * as eventThunks from "../../../src/features/Calendars/CalendarSlice";
|
||||||
jest.mock("../../../src/app/hooks");
|
|
||||||
|
|
||||||
describe("CalendarPopover", () => {
|
describe("CalendarPopover", () => {
|
||||||
const mockDispatch = jest.fn();
|
|
||||||
const mockOnClose = jest.fn();
|
const mockOnClose = jest.fn();
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
(useAppDispatch as unknown as jest.Mock).mockReturnValue(mockDispatch);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const renderPopover = (open = true) => {
|
const renderPopover = (open = true) => {
|
||||||
@@ -42,7 +39,7 @@ describe("CalendarPopover", () => {
|
|||||||
|
|
||||||
expect(screen.getByLabelText(/Name/i)).toBeInTheDocument();
|
expect(screen.getByLabelText(/Name/i)).toBeInTheDocument();
|
||||||
expect(screen.getByLabelText(/Description/i)).toBeInTheDocument();
|
expect(screen.getByLabelText(/Description/i)).toBeInTheDocument();
|
||||||
expect(screen.getByText("Create a Calendar")).toBeInTheDocument();
|
expect(screen.getByText("Calendar configuration")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("updates name and description fields", () => {
|
it("updates name and description fields", () => {
|
||||||
@@ -67,12 +64,17 @@ describe("CalendarPopover", () => {
|
|||||||
fireEvent.click(colorButtons[0]);
|
fireEvent.click(colorButtons[0]);
|
||||||
|
|
||||||
// The header background should update (check via inline style)
|
// The header background should update (check via inline style)
|
||||||
expect(screen.getByText("Create a Calendar").style.backgroundColor).toBe(
|
expect(
|
||||||
colorButtons[0].style.backgroundColor
|
screen.getByText("Calendar configuration").style.backgroundColor
|
||||||
);
|
).toBe(colorButtons[0].style.backgroundColor);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("dispatches createCalendar and calls onClose when Save clicked", () => {
|
it("dispatches createCalendar and calls onClose when Save clicked", () => {
|
||||||
|
const spy = jest
|
||||||
|
.spyOn(eventThunks, "createCalendarAsync")
|
||||||
|
.mockImplementation((payload) => {
|
||||||
|
return () => Promise.resolve(payload) as any;
|
||||||
|
});
|
||||||
renderPopover();
|
renderPopover();
|
||||||
|
|
||||||
fireEvent.change(screen.getByLabelText(/Name/i), {
|
fireEvent.change(screen.getByLabelText(/Name/i), {
|
||||||
@@ -92,13 +94,7 @@ describe("CalendarPopover", () => {
|
|||||||
|
|
||||||
fireEvent.click(screen.getByText(/Save/i));
|
fireEvent.click(screen.getByText(/Save/i));
|
||||||
|
|
||||||
expect(mockDispatch).toHaveBeenCalledWith(
|
expect(spy).toHaveBeenCalled();
|
||||||
createCalendar({
|
|
||||||
name: "Test Calendar",
|
|
||||||
description: "Test Description",
|
|
||||||
color: expectedColor,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick");
|
expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user