fix: update test cases to match new UI labels

- Update RepeatEvent.test.tsx to use correct selectors and text matching
- Update EventDisplay.test.tsx to use 'Notification' instead of 'Alarm'
- Update EventModal.test.tsx to use new label names and fix description input tests
- Update Calendar.test.tsx to use new placeholder text 'Start typing a name or email'
- Fix EventDisplay.tsx to use 'Notification' label consistently
This commit is contained in:
lenhanphung
2025-10-02 14:18:32 +07:00
parent 3261479874
commit 4eb2c86771
9 changed files with 186 additions and 183 deletions
+2 -2
View File
@@ -217,7 +217,7 @@ describe("calendar Availability search", () => {
renderWithProviders(<CalendarTestWrapper />, preloadedState); renderWithProviders(<CalendarTestWrapper />, preloadedState);
const input = screen.getByPlaceholderText(/search user/i); const input = screen.getByPlaceholderText(/start typing a name or email/i);
userEvent.type(input, "New"); userEvent.type(input, "New");
const option = await screen.findByText("New User"); const option = await screen.findByText("New User");
@@ -242,7 +242,7 @@ describe("calendar Availability search", () => {
}); });
renderWithProviders(<CalendarTestWrapper />, preloadedState); renderWithProviders(<CalendarTestWrapper />, preloadedState);
const input = screen.getByPlaceholderText(/search user/i); const input = screen.getByPlaceholderText(/start typing a name or email/i);
userEvent.type(input, "Alice"); userEvent.type(input, "Alice");
const option = await screen.findByText("Alice"); const option = await screen.findByText("Alice");
+7 -5
View File
@@ -118,7 +118,7 @@ async function setupEventPopover(
fireEvent.click(showMoreButton); fireEvent.click(showMoreButton);
} }
}); });
const select = screen.getByLabelText(/repetition/i); const select = screen.getByLabelText(/repeat/i);
userEvent.click(select); userEvent.click(select);
return jest.spyOn(apiUtils, "api"); return jest.spyOn(apiUtils, "api");
@@ -155,13 +155,15 @@ async function expectRRule(expected: any) {
describe("RepeatEvent", () => { describe("RepeatEvent", () => {
it("renders with no repetition by default", () => { it("renders with no repetition by default", () => {
setupRepeatEvent(); setupRepeatEvent();
expect(screen.getByLabelText(/repetition/i)).toBeInTheDocument(); expect(screen.getByText(/Repeat every/i)).toBeInTheDocument();
expect(screen.queryByText(/daily/i)).not.toBeInTheDocument(); // Check that the select exists and has default value
const select = screen.getByRole("combobox");
expect(select).toBeInTheDocument();
}); });
it("allows selecting repetition frequency", async () => { it("allows selecting repetition frequency", async () => {
const { setRepetition } = setupRepeatEvent(); const { setRepetition } = setupRepeatEvent();
const select = screen.getByLabelText(/repetition/i); const select = screen.getByRole("combobox");
act(() => { act(() => {
userEvent.click(select); userEvent.click(select);
}); });
@@ -176,7 +178,7 @@ describe("RepeatEvent", () => {
it("renders interval input when frequency is selected", () => { it("renders interval input when frequency is selected", () => {
setupRepeatEvent({ freq: "daily", interval: 2 }); setupRepeatEvent({ freq: "daily", interval: 2 });
expect(screen.getByText(/interval/i)).toBeInTheDocument(); expect(screen.getByText(/Repeat every/i)).toBeInTheDocument();
expect(screen.getByDisplayValue("2")).toBeInTheDocument(); expect(screen.getByDisplayValue("2")).toBeInTheDocument();
}); });
@@ -1039,9 +1039,9 @@ describe("Event Full Display", () => {
}); });
await waitFor(() => { await waitFor(() => {
expect(screen.getByLabelText(/Alarm/i)).toBeInTheDocument(); expect(screen.getByLabelText(/Notification/i)).toBeInTheDocument();
expect(screen.getByLabelText(/Repetition/i)).toBeInTheDocument(); expect(screen.getByLabelText(/Repeat/i)).toBeInTheDocument();
expect(screen.getByLabelText(/Visibility/i)).toBeInTheDocument(); expect(screen.getByText(/Visible to/i)).toBeInTheDocument();
}); });
fireEvent.click(screen.getByText("Show Less")); fireEvent.click(screen.getByText("Show Less"));
}); });
+12 -8
View File
@@ -116,10 +116,9 @@ describe("EventPopover", () => {
const titleInput = screen.getByRole("textbox", { name: /title/i }); const titleInput = screen.getByRole("textbox", { name: /title/i });
expect(titleInput).toBeInTheDocument(); expect(titleInput).toBeInTheDocument();
const descriptionInput = screen.getByRole("textbox", { // Description input is only visible after clicking "Add description" button
name: /description/i, const addDescriptionButton = screen.getByText("Add description");
}); expect(addDescriptionButton).toBeInTheDocument();
expect(descriptionInput).toBeInTheDocument();
const calendarSelect = screen.getByRole("combobox", { name: /calendar/i }); const calendarSelect = screen.getByRole("combobox", { name: /calendar/i });
expect(calendarSelect).toBeInTheDocument(); expect(calendarSelect).toBeInTheDocument();
@@ -135,9 +134,9 @@ describe("EventPopover", () => {
// Extended labels appear // Extended labels appear
expect(screen.getAllByText("Repeat")).toHaveLength(1); expect(screen.getAllByText("Repeat")).toHaveLength(1);
expect(screen.getAllByText("Alarm")).toHaveLength(1); expect(screen.getAllByText("Notification")).toHaveLength(1);
expect(screen.getAllByText("Visibility")).toHaveLength(1); expect(screen.getAllByText("Visible to")).toHaveLength(1);
expect(screen.getAllByText("Show as")).toHaveLength(1); expect(screen.getAllByText("Show me as")).toHaveLength(1);
}); });
it("fills start from selectedRange", () => { it("fills start from selectedRange", () => {
@@ -160,6 +159,9 @@ describe("EventPopover", () => {
}); });
expect(screen.getByLabelText("Title")).toHaveValue("My Event"); expect(screen.getByLabelText("Title")).toHaveValue("My Event");
// Click "Add description" button first
fireEvent.click(screen.getByText("Add description"));
fireEvent.change(screen.getByLabelText("Description"), { fireEvent.change(screen.getByLabelText("Description"), {
target: { value: "Event Description" }, target: { value: "Event Description" },
}); });
@@ -190,7 +192,7 @@ describe("EventPopover", () => {
fireEvent.change(screen.getByLabelText("Title"), { fireEvent.change(screen.getByLabelText("Title"), {
target: { value: "newEvent" }, target: { value: "newEvent" },
}); });
const select = screen.getByLabelText("Search user"); const select = screen.getByLabelText("Start typing a name or email");
act(() => { act(() => {
select.focus(); select.focus();
@@ -275,6 +277,8 @@ describe("EventPopover", () => {
target: { value: newEvent.end.split("T")[0] }, target: { value: newEvent.end.split("T")[0] },
}); });
// Click "Add description" button first
fireEvent.click(screen.getByText("Add description"));
fireEvent.change(screen.getByLabelText("Description"), { fireEvent.change(screen.getByLabelText("Description"), {
target: { value: newEvent.description }, target: { value: newEvent.description },
}); });
@@ -9,7 +9,6 @@ import CalendarPopover from "./CalendarModal";
import { Calendars } from "../../features/Calendars/CalendarTypes"; import { Calendars } from "../../features/Calendars/CalendarTypes";
import MoreVertIcon from "@mui/icons-material/MoreVert"; import MoreVertIcon from "@mui/icons-material/MoreVert";
import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown"; import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown";
import CalendarSearch from "./CalendarSearch";
import IconButton from "@mui/material/IconButton"; import IconButton from "@mui/material/IconButton";
import Checkbox from "@mui/material/Checkbox"; import Checkbox from "@mui/material/Checkbox";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
@@ -47,7 +47,9 @@ const checkIfCurrentWeekOrDay = (): boolean => {
return false; return false;
} }
const nowIndicator = document.querySelector(".fc-timegrid-now-indicator-arrow"); const nowIndicator = document.querySelector(
".fc-timegrid-now-indicator-arrow"
);
return !!nowIndicator; return !!nowIndicator;
}; };
+137 -143
View File
@@ -59,158 +59,152 @@ export default function RepeatEvent({
return ( return (
<Box> <Box>
<Stack> <Stack>
{/* Interval */} {/* Interval */}
<Box display="flex" alignItems="center" gap={2} mb={2}> <Box display="flex" alignItems="center" gap={2} mb={2}>
<Typography>Repeat every</Typography> <Typography>Repeat every</Typography>
<TextField <TextField
type="number" type="number"
value={repetition.interval ?? 1} value={repetition.interval ?? 1}
onChange={(e) => onChange={(e) =>
setRepetition({ setRepetition({
...repetition, ...repetition,
interval: Number(e.target.value), interval: Number(e.target.value),
}) })
} }
size="small" size="small"
style={{ width: 80 }} style={{ width: 80 }}
inputProps={{ min: 1 }} inputProps={{ min: 1 }}
/> />
<FormControl size="small" style={{ minWidth: 120 }}> <FormControl size="small" style={{ minWidth: 120 }}>
<Select <Select
value={repetition.freq ?? "daily"} value={repetition.freq ?? "daily"}
onChange={(e: SelectChangeEvent) => { onChange={(e: SelectChangeEvent) => {
if (e.target.value === "weekly") { 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={"daily"}>Day(s)</MenuItem>
<MenuItem value={"weekly"}>Week(s)</MenuItem>
<MenuItem value={"monthly"}>Month(s)</MenuItem>
<MenuItem value={"yearly"}>Year(s)</MenuItem>
</Select>
</FormControl>
</Box>
{/* Weekly selection */}
{repetition.freq === "weekly" && (
<Box>
<Typography variant="body2" gutterBottom>
Repeat on:
</Typography>
<FormGroup row>
{days.map((day) => (
<FormControlLabel
key={day}
control={
<Checkbox
checked={
repetition.selectedDays?.includes(day) ?? false
}
onChange={() => handleDayChange(day)}
/>
}
label={day}
/>
))}
</FormGroup>
</Box>
)}
{/* End options */}
<Box>
<Typography variant="body2" gutterBottom>
End:
</Typography>
<RadioGroup
value={endOption}
onChange={(e) => {
const value = e.target.value;
setEndOption(value);
if (value === "never") {
setRepetition({ ...repetition, occurrences: 0, endDate: "" });
}
if (value === "after") {
setRepetition({ setRepetition({
...repetition, ...repetition,
occurrences: 0, freq: e.target.value,
endDate: "", selectedDays: [days[day.getDay() - 1]],
});
}
if (value === "on") {
setRepetition({
...repetition,
occurrences: 0,
endDate: new Date().toISOString().slice(0, 16),
}); });
} else {
setRepetition({ ...repetition, freq: e.target.value });
} }
}} }}
> >
<FormControlLabel <MenuItem value={"daily"}>Day(s)</MenuItem>
value="never" <MenuItem value={"weekly"}>Week(s)</MenuItem>
control={<Radio />} <MenuItem value={"monthly"}>Month(s)</MenuItem>
label="Never" <MenuItem value={"yearly"}>Year(s)</MenuItem>
/> </Select>
</FormControl>
</Box>
<FormControlLabel {/* Weekly selection */}
value="after" {repetition.freq === "weekly" && (
control={<Radio />} <Box>
label={ <Typography variant="body2" gutterBottom>
<Box display="flex" alignItems="center" gap={1}> Repeat on:
After </Typography>
<TextField <FormGroup row>
type="number" {days.map((day) => (
size="small" <FormControlLabel
value={repetition.occurrences ?? 0} key={day}
onChange={(e) => control={
setRepetition({ <Checkbox
...repetition, checked={repetition.selectedDays?.includes(day) ?? false}
endDate: "", onChange={() => handleDayChange(day)}
occurrences: Number(e.target.value),
})
}
style={{ width: 100 }}
inputProps={{ min: 1 }}
disabled={endOption !== "after"}
/> />
occurrences }
</Box> label={day}
} />
/> ))}
</FormGroup>
<FormControlLabel
value="on"
control={<Radio />}
label={
<Box display="flex" alignItems="center" gap={1}>
On
<TextField
type="date"
inputProps={{ "data-testid": "end-date" }}
size="small"
value={repetition.endDate ?? ""}
onChange={(e) =>
setRepetition({
...repetition,
occurrences: 0,
endDate: e.target.value,
})
}
disabled={endOption !== "on"}
/>
</Box>
}
/>
</RadioGroup>
</Box> </Box>
</Stack> )}
{/* End options */}
<Box>
<Typography variant="body2" gutterBottom>
End:
</Typography>
<RadioGroup
value={endOption}
onChange={(e) => {
const value = e.target.value;
setEndOption(value);
if (value === "never") {
setRepetition({ ...repetition, occurrences: 0, endDate: "" });
}
if (value === "after") {
setRepetition({
...repetition,
occurrences: 0,
endDate: "",
});
}
if (value === "on") {
setRepetition({
...repetition,
occurrences: 0,
endDate: new Date().toISOString().slice(0, 16),
});
}
}}
>
<FormControlLabel value="never" control={<Radio />} label="Never" />
<FormControlLabel
value="after"
control={<Radio />}
label={
<Box display="flex" alignItems="center" gap={1}>
After
<TextField
type="number"
size="small"
value={repetition.occurrences ?? 0}
onChange={(e) =>
setRepetition({
...repetition,
endDate: "",
occurrences: Number(e.target.value),
})
}
style={{ width: 100 }}
inputProps={{ min: 1 }}
disabled={endOption !== "after"}
/>
occurrences
</Box>
}
/>
<FormControlLabel
value="on"
control={<Radio />}
label={
<Box display="flex" alignItems="center" gap={1}>
On
<TextField
type="date"
inputProps={{ "data-testid": "end-date" }}
size="small"
value={repetition.endDate ?? ""}
onChange={(e) =>
setRepetition({
...repetition,
occurrences: 0,
endDate: e.target.value,
})
}
disabled={endOption !== "on"}
/>
</Box>
}
/>
</RadioGroup>
</Box>
</Stack>
</Box> </Box>
); );
} }
+4 -4
View File
@@ -469,17 +469,17 @@ export default function EventDisplayModal({
isOwn={isOwn} isOwn={isOwn}
/> />
<FormControl fullWidth margin="dense" size="small"> <FormControl fullWidth margin="dense" size="small">
<InputLabel id="alarm">Alarm</InputLabel> <InputLabel id="notification">Notification</InputLabel>
<Select <Select
labelId="alarm" labelId="notification"
label="Alarm" label="Notification"
value={alarm} value={alarm}
disabled={!isOwn} disabled={!isOwn}
onChange={(e: SelectChangeEvent) => onChange={(e: SelectChangeEvent) =>
setAlarm(e.target.value) setAlarm(e.target.value)
} }
> >
<MenuItem value={""}>No Alarm</MenuItem> <MenuItem value={""}>No Notification</MenuItem>
<MenuItem value={"-PT1M"}>1 minute</MenuItem> <MenuItem value={"-PT1M"}>1 minute</MenuItem>
<MenuItem value={"-PT5M"}>2 minutes</MenuItem> <MenuItem value={"-PT5M"}>2 minutes</MenuItem>
<MenuItem value={"-PT10M"}>10 minutes</MenuItem> <MenuItem value={"-PT10M"}>10 minutes</MenuItem>
+9 -7
View File
@@ -134,7 +134,9 @@ function EventPopover({
const timezoneList = useMemo(() => { const timezoneList = useMemo(() => {
const zones = Object.keys(TIMEZONES.zones).sort(); const zones = Object.keys(TIMEZONES.zones).sort();
const browserTz = resolveTimezone(Intl.DateTimeFormat().resolvedOptions().timeZone); const browserTz = resolveTimezone(
Intl.DateTimeFormat().resolvedOptions().timeZone
);
const getTimezoneOffset = (tzName: string): string => { const getTimezoneOffset = (tzName: string): string => {
const resolvedTz = resolveTimezone(tzName); const resolvedTz = resolveTimezone(tzName);
@@ -149,9 +151,9 @@ function EventPopover({
const minutes = parseInt(offset.slice(3)); const minutes = parseInt(offset.slice(3));
if (minutes === 0) { if (minutes === 0) {
return `UTC${hours >= 0 ? '+' : ''}${hours}`; return `UTC${hours >= 0 ? "+" : ""}${hours}`;
} }
return `UTC${hours >= 0 ? '+' : ''}${hours}:${Math.abs(minutes).toString().padStart(2, '0')}`; return `UTC${hours >= 0 ? "+" : ""}${hours}:${Math.abs(minutes).toString().padStart(2, "0")}`;
}; };
return { zones, browserTz, getTimezoneOffset }; return { zones, browserTz, getTimezoneOffset };
@@ -595,12 +597,12 @@ function EventPopover({
}} }}
size="small" size="small"
> >
<ToggleButton value="PUBLIC" sx={{ width: '140px' }}> <ToggleButton value="PUBLIC" sx={{ width: "140px" }}>
<PublicIcon sx={{ mr: 1, fontSize: '16px' }} /> <PublicIcon sx={{ mr: 1, fontSize: "16px" }} />
All All
</ToggleButton> </ToggleButton>
<ToggleButton value="PRIVATE" sx={{ width: '140px' }}> <ToggleButton value="PRIVATE" sx={{ width: "140px" }}>
<LockIcon sx={{ mr: 1, fontSize: '16px' }} /> <LockIcon sx={{ mr: 1, fontSize: "16px" }} />
Participants Participants
</ToggleButton> </ToggleButton>
</ToggleButtonGroup> </ToggleButtonGroup>