[#159] Can untoggle every calendars (#161)

Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
Camille Moussu
2025-10-01 09:04:59 +02:00
committed by GitHub
parent 475ab79731
commit 17c6bf7bce
3 changed files with 23 additions and 7 deletions
+17
View File
@@ -250,4 +250,21 @@ describe("calendar Availability search", () => {
expect(spy).not.toHaveBeenCalledWith();
});
it("BUGFIX: can untoggle all personnal calendars", () => {
renderWithProviders(<CalendarTestWrapper />, {
user: preloadedState.user,
calendars: {
list: { "user1/cal1": preloadedState.calendars.list["user1/cal1"] },
pending: false,
},
});
const checkbox = screen.getByLabelText("Calendar personnal");
expect(checkbox).toBeChecked();
fireEvent.click(checkbox); // toggle off
expect(checkbox).not.toBeChecked();
});
});
+5 -6
View File
@@ -100,18 +100,17 @@ export default function CalendarApp({
const fetchedRangesRef = useRef<Record<string, string>>({});
// Auto-select personal calendars when first loaded
const initialLoadRef = useRef(true);
useEffect(() => {
if (
Object.keys(calendars).length > 0 &&
userId &&
selectedCalendars.length === 0
) {
if (initialLoadRef.current && Object.keys(calendars).length > 0 && userId) {
const personalCalendarIds = Object.keys(calendars).filter(
(id) => id.split("/")[0] === userId
);
setSelectedCalendars(personalCalendarIds);
initialLoadRef.current = false;
}
}, [calendars, userId, selectedCalendars.length]);
}, [calendars, userId]);
const calendarRange = getCalendarRange(selectedDate);
@@ -94,7 +94,7 @@ export const updateCalsDetails = (
});
if (rangeKey !== previousRangeKey) {
selectedCalendars.forEach((id) => {
selectedCalendars?.forEach((id) => {
dispatch(
getCalendarDetailAsync({
calId: id,