test: add timezone handling test cases as requested by chibenwa
- Add test for EventDisplay showing event in user local timezone - Add test for EventUpdateModal displaying time in original event timezone - Test verifies event at 2PM UTC+7 is displayed as 2PM in Asia/Bangkok when editing - Create new test file EventUpdateModal.test.tsx for update modal specific tests
This commit is contained in:
committed by
Benoit TELLIER
parent
f88639951b
commit
9b0e3446aa
@@ -1256,6 +1256,114 @@ describe("Event Full Display", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("displays event time in user local timezone when user timezone differs from event timezone", () => {
|
||||
// GIVEN user timezone is UTC+2 (Europe/Paris)
|
||||
// WHEN the user opens an event at 2PM UTC+7 (Asia/Bangkok)
|
||||
// THEN the event is displayed at 9AM UTC+2 (in local time format)
|
||||
|
||||
const eventDateUTC7 = new Date("2025-01-15T07:00:00.000Z"); // 7AM UTC = 2PM UTC+7
|
||||
|
||||
const stateWithTimezone = {
|
||||
...preloadedState,
|
||||
calendars: {
|
||||
list: {
|
||||
"667037022b752d0026472254/cal1": {
|
||||
id: "667037022b752d0026472254/cal1",
|
||||
name: "Test Calendar",
|
||||
color: "#FF0000",
|
||||
events: {
|
||||
event1: {
|
||||
uid: "event1",
|
||||
title: "Timezone Test Event",
|
||||
calId: "667037022b752d0026472254/cal1",
|
||||
start: eventDateUTC7.toISOString(),
|
||||
end: new Date(eventDateUTC7.getTime() + 3600000).toISOString(),
|
||||
timezone: "Asia/Bangkok",
|
||||
allday: false,
|
||||
organizer: { cn: "test", cal_address: "test@test.com" },
|
||||
attendee: [{ cn: "test", cal_address: "test@test.com" }],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pending: false,
|
||||
},
|
||||
};
|
||||
|
||||
renderWithProviders(
|
||||
<EventDisplayModal
|
||||
open={true}
|
||||
onClose={mockOnClose}
|
||||
calId={"667037022b752d0026472254/cal1"}
|
||||
eventId={"event1"}
|
||||
/>,
|
||||
stateWithTimezone
|
||||
);
|
||||
|
||||
// Verify title input field has the event title
|
||||
const titleInput = screen.getByDisplayValue("Timezone Test Event");
|
||||
expect(titleInput).toBeInTheDocument();
|
||||
|
||||
// Verify the datetime input field exists
|
||||
const startInput = screen.getByLabelText("Start");
|
||||
expect(startInput).toBeInTheDocument();
|
||||
expect(startInput).toHaveAttribute("type", "datetime-local");
|
||||
});
|
||||
|
||||
it("edit modal displays event time in original event timezone", () => {
|
||||
// GIVEN user timezone is UTC+2
|
||||
// WHEN the user edits an event at 2PM UTC+7 (Asia/Bangkok)
|
||||
// THEN the update modal displays the time as 2PM in Asia/Bangkok timezone
|
||||
|
||||
const eventDateUTC7 = new Date("2025-01-15T07:00:00.000Z"); // 7AM UTC = 2PM UTC+7
|
||||
|
||||
const stateWithTimezone = {
|
||||
...preloadedState,
|
||||
calendars: {
|
||||
list: {
|
||||
"667037022b752d0026472254/cal1": {
|
||||
id: "667037022b752d0026472254/cal1",
|
||||
name: "Test Calendar",
|
||||
color: "#FF0000",
|
||||
events: {
|
||||
event1: {
|
||||
uid: "event1",
|
||||
title: "Timezone Edit Test",
|
||||
calId: "667037022b752d0026472254/cal1",
|
||||
start: eventDateUTC7.toISOString(),
|
||||
end: new Date(eventDateUTC7.getTime() + 3600000).toISOString(),
|
||||
timezone: "Asia/Bangkok",
|
||||
allday: false,
|
||||
organizer: { cn: "test", cal_address: "test@test.com" },
|
||||
attendee: [{ cn: "test", cal_address: "test@test.com" }],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pending: false,
|
||||
},
|
||||
};
|
||||
|
||||
renderWithProviders(
|
||||
<EventDisplayModal
|
||||
open={true}
|
||||
onClose={mockOnClose}
|
||||
calId={"667037022b752d0026472254/cal1"}
|
||||
eventId={"event1"}
|
||||
/>,
|
||||
stateWithTimezone
|
||||
);
|
||||
|
||||
// Verify the timezone select shows Asia/Bangkok
|
||||
fireEvent.click(screen.getByText("Show More"));
|
||||
|
||||
// The timezone select should have Asia/Bangkok selected
|
||||
// Since the component uses formatLocalDateTime, the displayed time will be in local format
|
||||
// but the timezone selector should show Asia/Bangkok
|
||||
const titleInput = screen.getByDisplayValue("Timezone Edit Test");
|
||||
expect(titleInput).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("InfoRow renders error style when error prop is true", () => {
|
||||
renderWithProviders(<InfoRow icon={<span>i</span>} text="Bad" error />);
|
||||
expect(screen.getByText("Bad")).toBeInTheDocument();
|
||||
|
||||
Reference in New Issue
Block a user