[#64] added missing test file
This commit is contained in:
committed by
Benoit TELLIER
parent
06984ded1a
commit
b6f8097769
@@ -1,193 +1,158 @@
|
|||||||
import { CalendarApi } from "@fullcalendar/core";
|
import { screen, fireEvent } from "@testing-library/react";
|
||||||
import { jest } from "@jest/globals";
|
|
||||||
import { ThunkDispatch } from "@reduxjs/toolkit";
|
|
||||||
import "@testing-library/jest-dom";
|
import "@testing-library/jest-dom";
|
||||||
import { screen } from "@testing-library/react";
|
|
||||||
import * as appHooks from "../../src/app/hooks";
|
|
||||||
import CalendarApp from "../../src/components/Calendar/Calendar";
|
|
||||||
import { renderWithProviders } from "../utils/Renderwithproviders";
|
|
||||||
import CalendarSelection from "../../src/components/Calendar/CalendarSelection";
|
import CalendarSelection from "../../src/components/Calendar/CalendarSelection";
|
||||||
|
import { renderWithProviders } from "../utils/Renderwithproviders";
|
||||||
|
|
||||||
describe("CalendarSelection", () => {
|
describe("CalendarSelection", () => {
|
||||||
const today = new Date();
|
const baseUser = {
|
||||||
const start = new Date(today);
|
userData: {
|
||||||
start.setHours(10, 0, 0, 0);
|
sub: "test",
|
||||||
const end = new Date(today);
|
email: "test@test.com",
|
||||||
end.setHours(11, 0, 0, 0);
|
sid: "mockSid",
|
||||||
|
openpaasId: "user1",
|
||||||
|
},
|
||||||
|
tokens: { accessToken: "token" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const calendarsMock = {
|
||||||
|
"user1/cal1": {
|
||||||
|
name: "Calendar personnal",
|
||||||
|
id: "user1/cal1",
|
||||||
|
color: "#FF0000",
|
||||||
|
ownerEmails: ["alice@example.com"],
|
||||||
|
},
|
||||||
|
"user2/cal1": {
|
||||||
|
name: "Calendar delegated",
|
||||||
|
delegated: true,
|
||||||
|
id: "user2/cal1",
|
||||||
|
color: "#00FF00",
|
||||||
|
ownerEmails: ["bob@example.com"],
|
||||||
|
},
|
||||||
|
"user3/cal1": {
|
||||||
|
name: "Calendar shared",
|
||||||
|
id: "user3/cal1",
|
||||||
|
color: "#0000FF",
|
||||||
|
ownerEmails: ["charlie@example.com"],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
it("renders personal, delegated and shared calendars", () => {
|
||||||
|
renderWithProviders(
|
||||||
|
<CalendarSelection
|
||||||
|
selectedCalendars={["user1/cal1"]}
|
||||||
|
setSelectedCalendars={jest.fn()}
|
||||||
|
/>,
|
||||||
|
{
|
||||||
|
user: baseUser,
|
||||||
|
calendars: { list: calendarsMock, pending: false },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
it("renders the all the calendars in list", async () => {
|
|
||||||
const preloadedState = {
|
|
||||||
user: {
|
|
||||||
userData: {
|
|
||||||
sub: "test",
|
|
||||||
email: "test@test.com",
|
|
||||||
sid: "mockSid",
|
|
||||||
openpaasId: "user1",
|
|
||||||
},
|
|
||||||
tokens: { accessToken: "token" }, // required to avoid redirect
|
|
||||||
},
|
|
||||||
calendars: {
|
|
||||||
list: {
|
|
||||||
"user1/cal1": {
|
|
||||||
name: "Calendar personnal",
|
|
||||||
id: "user1/cal1",
|
|
||||||
color: "#FF0000",
|
|
||||||
ownerEmails: ["alice@example.com"],
|
|
||||||
events: {
|
|
||||||
event1: {
|
|
||||||
id: "event1",
|
|
||||||
calId: "user1/cal1",
|
|
||||||
uid: "event1",
|
|
||||||
title: "Test Event",
|
|
||||||
start: start.toISOString(),
|
|
||||||
end: end.toISOString(),
|
|
||||||
partstat: "ACCEPTED",
|
|
||||||
organizer: {
|
|
||||||
cn: "Alice",
|
|
||||||
cal_address: "alice@example.com",
|
|
||||||
},
|
|
||||||
attendee: [
|
|
||||||
{
|
|
||||||
cn: "Alice",
|
|
||||||
partstat: "ACCEPTED",
|
|
||||||
rsvp: "TRUE",
|
|
||||||
role: "REQ-PARTICIPANT",
|
|
||||||
cutype: "INDIVIDUAL",
|
|
||||||
cal_address: "alice@example.com",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"user2/cal1": {
|
|
||||||
name: "Calendar delegated",
|
|
||||||
delegated: true,
|
|
||||||
id: "user2/cal1",
|
|
||||||
color: "#FF0000",
|
|
||||||
ownerEmails: ["alice@example.com"],
|
|
||||||
events: {
|
|
||||||
event1: {
|
|
||||||
id: "event1",
|
|
||||||
calId: "user2/cal1",
|
|
||||||
uid: "event1",
|
|
||||||
title: "Test Event",
|
|
||||||
start: start.toISOString(),
|
|
||||||
end: end.toISOString(),
|
|
||||||
partstat: "ACCEPTED",
|
|
||||||
organizer: {
|
|
||||||
cn: "Alice",
|
|
||||||
cal_address: "alice@example.com",
|
|
||||||
},
|
|
||||||
attendee: [
|
|
||||||
{
|
|
||||||
cn: "Alice",
|
|
||||||
partstat: "ACCEPTED",
|
|
||||||
rsvp: "TRUE",
|
|
||||||
role: "REQ-PARTICIPANT",
|
|
||||||
cutype: "INDIVIDUAL",
|
|
||||||
cal_address: "alice@example.com",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"user3/cal1": {
|
|
||||||
name: "Calendar shared",
|
|
||||||
id: "user3/cal1",
|
|
||||||
color: "#FF0000",
|
|
||||||
ownerEmails: ["alice@example.com"],
|
|
||||||
events: {
|
|
||||||
event1: {
|
|
||||||
id: "event1",
|
|
||||||
calId: "user3/cal1",
|
|
||||||
uid: "event1",
|
|
||||||
title: "Test Event",
|
|
||||||
start: start.toISOString(),
|
|
||||||
end: end.toISOString(),
|
|
||||||
partstat: "ACCEPTED",
|
|
||||||
organizer: {
|
|
||||||
cn: "Alice",
|
|
||||||
cal_address: "alice@example.com",
|
|
||||||
},
|
|
||||||
attendee: [
|
|
||||||
{
|
|
||||||
cn: "Alice",
|
|
||||||
partstat: "ACCEPTED",
|
|
||||||
rsvp: "TRUE",
|
|
||||||
role: "REQ-PARTICIPANT",
|
|
||||||
cutype: "INDIVIDUAL",
|
|
||||||
cal_address: "alice@example.com",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
pending: false,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
renderWithProviders(<CalendarApp />, preloadedState);
|
|
||||||
expect(screen.getByText("Personnal Calendars")).toBeInTheDocument();
|
expect(screen.getByText("Personnal Calendars")).toBeInTheDocument();
|
||||||
expect(screen.getByText("Delegated Calendars")).toBeInTheDocument();
|
expect(screen.getByText("Delegated Calendars")).toBeInTheDocument();
|
||||||
expect(screen.getByText("Shared Calendars")).toBeInTheDocument();
|
expect(screen.getByText("Shared Calendars")).toBeInTheDocument();
|
||||||
|
|
||||||
expect(screen.getByLabelText("Calendar personnal")).toBeInTheDocument();
|
expect(screen.getByLabelText("Calendar personnal")).toBeChecked();
|
||||||
expect(screen.getByLabelText("Calendar delegated")).toBeInTheDocument();
|
expect(screen.getByLabelText("Calendar delegated")).not.toBeChecked();
|
||||||
expect(screen.getByLabelText("Calendar shared")).toBeInTheDocument();
|
expect(screen.getByLabelText("Calendar shared")).not.toBeChecked();
|
||||||
});
|
});
|
||||||
it("renders only personnal calendars in list", async () => {
|
|
||||||
const preloadedState = {
|
it("toggles a calendar selection on click", () => {
|
||||||
user: {
|
const setSelectedCalendars = jest.fn();
|
||||||
userData: {
|
|
||||||
sub: "test",
|
renderWithProviders(
|
||||||
email: "test@test.com",
|
<CalendarSelection
|
||||||
sid: "mockSid",
|
selectedCalendars={[]}
|
||||||
openpaasId: "user1",
|
setSelectedCalendars={setSelectedCalendars}
|
||||||
},
|
/>,
|
||||||
tokens: { accessToken: "token" }, // required to avoid redirect
|
{
|
||||||
},
|
user: baseUser,
|
||||||
calendars: {
|
calendars: { list: calendarsMock, pending: false },
|
||||||
list: {
|
}
|
||||||
"user1/cal1": {
|
);
|
||||||
name: "Calendar personnal",
|
|
||||||
id: "user1/cal1",
|
const checkbox = screen.getByLabelText("Calendar personnal");
|
||||||
color: "#FF0000",
|
fireEvent.click(checkbox);
|
||||||
ownerEmails: ["alice@example.com"],
|
|
||||||
events: {
|
expect(setSelectedCalendars).toHaveBeenCalledWith(expect.any(Function));
|
||||||
event1: {
|
|
||||||
id: "event1",
|
const updater = setSelectedCalendars.mock.calls[0][0];
|
||||||
calId: "user1/cal1",
|
expect(updater([])).toEqual(["user1/cal1"]);
|
||||||
uid: "event1",
|
});
|
||||||
title: "Test Event",
|
|
||||||
start: start.toISOString(),
|
it("removes calendar from selection if already selected", () => {
|
||||||
end: end.toISOString(),
|
const setSelectedCalendars = jest.fn();
|
||||||
partstat: "ACCEPTED",
|
|
||||||
organizer: {
|
renderWithProviders(
|
||||||
cn: "Alice",
|
<CalendarSelection
|
||||||
cal_address: "alice@example.com",
|
selectedCalendars={["user1/cal1"]}
|
||||||
},
|
setSelectedCalendars={setSelectedCalendars}
|
||||||
attendee: [
|
/>,
|
||||||
{
|
{
|
||||||
cn: "Alice",
|
user: baseUser,
|
||||||
partstat: "ACCEPTED",
|
calendars: { list: calendarsMock, pending: false },
|
||||||
rsvp: "TRUE",
|
}
|
||||||
role: "REQ-PARTICIPANT",
|
);
|
||||||
cutype: "INDIVIDUAL",
|
|
||||||
cal_address: "alice@example.com",
|
const checkbox = screen.getByLabelText("Calendar personnal");
|
||||||
},
|
fireEvent.click(checkbox);
|
||||||
],
|
|
||||||
},
|
const updater = setSelectedCalendars.mock.calls[0][0];
|
||||||
},
|
expect(updater(["user1/cal1"])).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("opens CalendarPopover when Add button is clicked", () => {
|
||||||
|
renderWithProviders(
|
||||||
|
<CalendarSelection
|
||||||
|
selectedCalendars={[]}
|
||||||
|
setSelectedCalendars={jest.fn()}
|
||||||
|
/>,
|
||||||
|
{
|
||||||
|
user: baseUser,
|
||||||
|
calendars: { list: calendarsMock, pending: false },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const addButton = screen.getByRole("button");
|
||||||
|
fireEvent.click(addButton);
|
||||||
|
|
||||||
|
expect(screen.getByRole("presentation")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders only personal calendars if no delegated/shared exist", () => {
|
||||||
|
renderWithProviders(
|
||||||
|
<CalendarSelection
|
||||||
|
selectedCalendars={[]}
|
||||||
|
setSelectedCalendars={jest.fn()}
|
||||||
|
/>,
|
||||||
|
{
|
||||||
|
user: baseUser,
|
||||||
|
calendars: {
|
||||||
|
list: {
|
||||||
|
"user1/cal1": calendarsMock["user1/cal1"],
|
||||||
},
|
},
|
||||||
|
pending: false,
|
||||||
},
|
},
|
||||||
pending: false,
|
}
|
||||||
},
|
);
|
||||||
};
|
|
||||||
renderWithProviders(<CalendarApp />, preloadedState);
|
|
||||||
expect(screen.getByText("Personnal Calendars")).toBeInTheDocument();
|
expect(screen.getByText("Personnal Calendars")).toBeInTheDocument();
|
||||||
expect(screen.queryByText("Delegated Calendars")).not.toBeInTheDocument();
|
expect(screen.queryByText("Delegated Calendars")).not.toBeInTheDocument();
|
||||||
expect(screen.queryByText("Shared Calendars")).not.toBeInTheDocument();
|
expect(screen.queryByText("Shared Calendars")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
expect(screen.getByLabelText("Calendar personnal")).toBeInTheDocument();
|
it("renders nothing when no calendars are present", () => {
|
||||||
|
renderWithProviders(
|
||||||
|
<CalendarSelection
|
||||||
|
selectedCalendars={[]}
|
||||||
|
setSelectedCalendars={jest.fn()}
|
||||||
|
/>,
|
||||||
|
{
|
||||||
|
user: baseUser,
|
||||||
|
calendars: { list: {}, pending: false },
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(screen.queryByLabelText(/Calendar/)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user