[#77] added event start day selected by default when repetition is set to weekly
This commit is contained in:
@@ -65,6 +65,7 @@ function setupRepeatEvent(props?: Partial<RepetitionObject>, state?: any) {
|
|||||||
renderWithProviders(
|
renderWithProviders(
|
||||||
<RepeatEvent
|
<RepeatEvent
|
||||||
repetition={{ ...baseRepetition, ...props }}
|
repetition={{ ...baseRepetition, ...props }}
|
||||||
|
eventStart={defaultSelectedRange.start}
|
||||||
setRepetition={setRepetition}
|
setRepetition={setRepetition}
|
||||||
isOwn={true}
|
isOwn={true}
|
||||||
/>,
|
/>,
|
||||||
@@ -133,7 +134,18 @@ async function expectRRule(expected: any) {
|
|||||||
spyAPi.mock.calls[0][1]?.body?.toString() ?? "";
|
spyAPi.mock.calls[0][1]?.body?.toString() ?? "";
|
||||||
const [, , [vevent]] = JSON.parse(receivedPayload);
|
const [, , [vevent]] = JSON.parse(receivedPayload);
|
||||||
const rrule = vevent[1].find(([name]: any) => name === "rrule");
|
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", () => {
|
describe("RepeatEvent", () => {
|
||||||
@@ -221,7 +233,17 @@ describe("Repeat Event API calls", () => {
|
|||||||
expect(received.newEvent.organizer).toEqual(
|
expect(received.newEvent.organizer).toEqual(
|
||||||
preloadedState.user.organiserData
|
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(
|
expect(received.newEvent.color).toEqual(
|
||||||
preloadedState.calendars.list["667037022b752d0026472254/cal1"].color
|
preloadedState.calendars.list["667037022b752d0026472254/cal1"].color
|
||||||
);
|
);
|
||||||
@@ -280,23 +302,21 @@ describe("Repeat Event API calls", () => {
|
|||||||
expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick");
|
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();
|
await setupEventPopover();
|
||||||
|
|
||||||
userEvent.click(await screen.findByText(/repeat weekly/i));
|
userEvent.click(await screen.findByText(/repeat weekly/i));
|
||||||
userEvent.click(screen.getByLabelText("TH"));
|
userEvent.click(screen.getByLabelText("TH"));
|
||||||
userEvent.click(screen.getByLabelText("FR"));
|
|
||||||
|
|
||||||
await expectRRule({ freq: "weekly", byday: ["TH", "FR"] });
|
await expectRRule({ freq: "weekly", byday: ["TH", "FR"] });
|
||||||
expect(mockOnClose).toHaveBeenCalledWith({}, "backdropClick");
|
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();
|
await setupEventPopover();
|
||||||
|
|
||||||
userEvent.click(await screen.findByText(/repeat weekly/i));
|
userEvent.click(await screen.findByText(/repeat weekly/i));
|
||||||
|
|
||||||
userEvent.click(screen.getByLabelText("TH"));
|
userEvent.click(screen.getByLabelText("TH"));
|
||||||
userEvent.click(screen.getByLabelText("FR"));
|
|
||||||
|
|
||||||
const intervalInput = screen.getByDisplayValue("1");
|
const intervalInput = screen.getByDisplayValue("1");
|
||||||
fireEvent.change(intervalInput, { target: { value: "3" } });
|
fireEvent.change(intervalInput, { target: { value: "3" } });
|
||||||
|
|||||||
@@ -19,15 +19,18 @@ import { RepetitionObject } from "../../features/Events/EventsTypes";
|
|||||||
|
|
||||||
export default function RepeatEvent({
|
export default function RepeatEvent({
|
||||||
repetition,
|
repetition,
|
||||||
|
eventStart,
|
||||||
setRepetition,
|
setRepetition,
|
||||||
isOwn = true,
|
isOwn = true,
|
||||||
}: {
|
}: {
|
||||||
repetition: RepetitionObject;
|
repetition: RepetitionObject;
|
||||||
|
eventStart: Date;
|
||||||
setRepetition: Function;
|
setRepetition: Function;
|
||||||
isOwn?: boolean;
|
isOwn?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const repetitionValues = ["day", "week", "month", "year"];
|
const repetitionValues = ["day", "week", "month", "year"];
|
||||||
const days = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
|
const days = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
|
||||||
|
const day = new Date(eventStart);
|
||||||
|
|
||||||
// derive endOption based on repetition
|
// derive endOption based on repetition
|
||||||
const getEndOption = () => {
|
const getEndOption = () => {
|
||||||
@@ -61,9 +64,17 @@ export default function RepeatEvent({
|
|||||||
value={repetition.freq ?? ""}
|
value={repetition.freq ?? ""}
|
||||||
disabled={!isOwn}
|
disabled={!isOwn}
|
||||||
label="Repetition"
|
label="Repetition"
|
||||||
onChange={(e: SelectChangeEvent) =>
|
onChange={(e: SelectChangeEvent) => {
|
||||||
setRepetition({ ...repetition, freq: e.target.value })
|
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={""}>No Repetition</MenuItem>
|
||||||
<MenuItem value={"daily"}>Repeat daily</MenuItem>
|
<MenuItem value={"daily"}>Repeat daily</MenuItem>
|
||||||
|
|||||||
@@ -466,6 +466,7 @@ export default function EventDisplayModal({
|
|||||||
<>
|
<>
|
||||||
<RepeatEvent
|
<RepeatEvent
|
||||||
repetition={repetition}
|
repetition={repetition}
|
||||||
|
eventStart={event.start}
|
||||||
setRepetition={setRepetition}
|
setRepetition={setRepetition}
|
||||||
isOwn={isOwn}
|
isOwn={isOwn}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -284,6 +284,7 @@ function EventPopover({
|
|||||||
<>
|
<>
|
||||||
<RepeatEvent
|
<RepeatEvent
|
||||||
repetition={repetition}
|
repetition={repetition}
|
||||||
|
eventStart={selectedRange?.start ?? new Date()}
|
||||||
setRepetition={setRepetition}
|
setRepetition={setRepetition}
|
||||||
/>
|
/>
|
||||||
<FormControl fullWidth margin="dense" size="small">
|
<FormControl fullWidth margin="dense" size="small">
|
||||||
|
|||||||
Reference in New Issue
Block a user