From 37ab51784ca354eb60fe63f3b6713e367d51e6c4 Mon Sep 17 00:00:00 2001 From: Camille Moussu Date: Mon, 8 Sep 2025 11:23:24 +0200 Subject: [PATCH] [#77] added event start day selected by default when repetition is set to weekly --- __test__/components/RepeatEvent.test.tsx | 32 +++++++++++++++++++----- src/components/Event/EventRepeat.tsx | 17 ++++++++++--- src/features/Events/EventDisplay.tsx | 1 + src/features/Events/EventModal.tsx | 1 + 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/__test__/components/RepeatEvent.test.tsx b/__test__/components/RepeatEvent.test.tsx index 065d331..0a89775 100644 --- a/__test__/components/RepeatEvent.test.tsx +++ b/__test__/components/RepeatEvent.test.tsx @@ -65,6 +65,7 @@ function setupRepeatEvent(props?: Partial, state?: any) { renderWithProviders( , @@ -133,7 +134,18 @@ async function expectRRule(expected: any) { spyAPi.mock.calls[0][1]?.body?.toString() ?? ""; const [, , [vevent]] = JSON.parse(receivedPayload); const rrule = vevent[1].find(([name]: any) => name === "rrule"); - expect(rrule[3]).toEqual(expected); + + if (rrule[3].byday) { + expect({ + ...rrule[3], + byday: rrule[3].byday.sort(), + }).toEqual({ + ...expected, + byday: expected.byday.sort(), + }); + } else { + expect(rrule[3]).toEqual(expected); + } } describe("RepeatEvent", () => { @@ -221,7 +233,17 @@ describe("Repeat Event API calls", () => { expect(received.newEvent.organizer).toEqual( preloadedState.user.organiserData ); - expect(received.newEvent.repetition).toEqual({ freq: "weekly" }); + const day = new Date(received.newEvent.start) + .toLocaleString("en-UK", { + weekday: "short", + }) + .slice(0, 2) + .toUpperCase(); + + expect(received.newEvent.repetition).toEqual({ + freq: "weekly", + selectedDays: [day], + }); expect(received.newEvent.color).toEqual( preloadedState.calendars.list["667037022b752d0026472254/cal1"].color ); @@ -280,23 +302,21 @@ describe("Repeat Event API calls", () => { expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick"); }); - it("sends correct API payload for repeat weekly on Thursday and Friday", async () => { + it("sends correct API payload for repeat weekly on Thursday and event day (Friday)", async () => { await setupEventPopover(); userEvent.click(await screen.findByText(/repeat weekly/i)); userEvent.click(screen.getByLabelText("TH")); - userEvent.click(screen.getByLabelText("FR")); await expectRRule({ freq: "weekly", byday: ["TH", "FR"] }); expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick"); }); - it("sends correct API payload for repeat weekly on Thursday and Friday and an interval of 3 weeks", async () => { + it("sends correct API payload for repeat weekly on Thursday and event day (Friday) and an interval of 3 weeks", async () => { await setupEventPopover(); userEvent.click(await screen.findByText(/repeat weekly/i)); userEvent.click(screen.getByLabelText("TH")); - userEvent.click(screen.getByLabelText("FR")); const intervalInput = screen.getByDisplayValue("1"); fireEvent.change(intervalInput, { target: { value: "3" } }); diff --git a/src/components/Event/EventRepeat.tsx b/src/components/Event/EventRepeat.tsx index 5771764..8439955 100644 --- a/src/components/Event/EventRepeat.tsx +++ b/src/components/Event/EventRepeat.tsx @@ -19,15 +19,18 @@ import { RepetitionObject } from "../../features/Events/EventsTypes"; export default function RepeatEvent({ repetition, + eventStart, setRepetition, isOwn = true, }: { repetition: RepetitionObject; + eventStart: Date; setRepetition: Function; isOwn?: boolean; }) { const repetitionValues = ["day", "week", "month", "year"]; const days = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"]; + const day = new Date(eventStart); // derive endOption based on repetition const getEndOption = () => { @@ -61,9 +64,17 @@ export default function RepeatEvent({ value={repetition.freq ?? ""} disabled={!isOwn} label="Repetition" - onChange={(e: SelectChangeEvent) => - setRepetition({ ...repetition, freq: e.target.value }) - } + onChange={(e: SelectChangeEvent) => { + if (e.target.value === "weekly") { + setRepetition({ + ...repetition, + freq: e.target.value, + selectedDays: [days[day.getDay() - 1]], + }); + } else { + setRepetition({ ...repetition, freq: e.target.value }); + } + }} > No Repetition Repeat daily diff --git a/src/features/Events/EventDisplay.tsx b/src/features/Events/EventDisplay.tsx index 3509794..e6c9ccd 100644 --- a/src/features/Events/EventDisplay.tsx +++ b/src/features/Events/EventDisplay.tsx @@ -466,6 +466,7 @@ export default function EventDisplayModal({ <> diff --git a/src/features/Events/EventModal.tsx b/src/features/Events/EventModal.tsx index 4720a34..9b2fbd6 100644 --- a/src/features/Events/EventModal.tsx +++ b/src/features/Events/EventModal.tsx @@ -284,6 +284,7 @@ function EventPopover({ <>