[#77] added event start day selected by default when repetition is set to weekly

This commit is contained in:
Camille Moussu
2025-09-08 11:23:24 +02:00
parent 353d6761b4
commit 37ab51784c
4 changed files with 42 additions and 9 deletions
+26 -6
View File
@@ -65,6 +65,7 @@ function setupRepeatEvent(props?: Partial<RepetitionObject>, state?: any) {
renderWithProviders(
<RepeatEvent
repetition={{ ...baseRepetition, ...props }}
eventStart={defaultSelectedRange.start}
setRepetition={setRepetition}
isOwn={true}
/>,
@@ -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" } });
+14 -3
View File
@@ -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 });
}
}}
>
<MenuItem value={""}>No Repetition</MenuItem>
<MenuItem value={"daily"}>Repeat daily</MenuItem>
+1
View File
@@ -466,6 +466,7 @@ export default function EventDisplayModal({
<>
<RepeatEvent
repetition={repetition}
eventStart={event.start}
setRepetition={setRepetition}
isOwn={isOwn}
/>
+1
View File
@@ -284,6 +284,7 @@ function EventPopover({
<>
<RepeatEvent
repetition={repetition}
eventStart={selectedRange?.start ?? new Date()}
setRepetition={setRepetition}
/>
<FormControl fullWidth margin="dense" size="small">