Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions packages/core/src/__mocks__/v1/events/events.misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ export const CLIMB: Schema_Event = {
endDate: "2022-03-01T19:00:00-06:00",
};

// Use local date to avoid timezone-dependent test failures
const getLocalDateString = (): string => {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, "0");
const day = String(now.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};

const today = getLocalDateString();
export const EUROPE_TRIP: Schema_Event = {
_id: new ObjectId().toString(),
user: USER,
Expand All @@ -51,8 +41,8 @@ export const EUROPE_TRIP: Schema_Event = {
description: "Italy, Germany",
isSomeday: true,
priority: Priorities.SELF,
startDate: today,
endDate: today,
startDate: "2025-12-10T00:00:00-00:00",
endDate: "2025-12-10T00:00:00-00:00",
order: 2,
};
export const LEARN_CHINESE: Schema_Event = {
Expand Down
16 changes: 14 additions & 2 deletions packages/web/src/__tests__/__mocks__/mock.render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,28 @@ const customRender = (
reducer: reducers,
preloadedState: state,
}),
wrapper: CustomWrapper,
...renderOptions
}: Omit<CustomRenderOptions, "wrapper"> = {},
}: CustomRenderOptions = {},
) => {
sagaMiddleware.run(sagas);

const options: RenderOptions = { ...renderOptions };
const BaseProviders = TestProviders({ store, router });

const Wrapper = ({ children }: PropsWithChildren) => {
if (!CustomWrapper) return <BaseProviders>{children}</BaseProviders>;

return (
<BaseProviders>
<CustomWrapper>{children}</CustomWrapper>
</BaseProviders>
);
};

// wraps test component with providers
return render(ui, {
wrapper: TestProviders({ store, router }),
wrapper: Wrapper,
...options,
});
};
Expand Down
41 changes: 28 additions & 13 deletions packages/web/src/__tests__/__mocks__/state/state.weekEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import {
MULTI_WEEK,
TY_TIM,
} from "@core/__mocks__/v1/events/events.misc";
import { InitialReduxState } from "@web/views/Calendar/calendar.render.test.utils";
import { InitialReduxState } from "@web/__tests__/utils/state/store.test.util";

export const preloadedState: InitialReduxState = {
events: {
getSomedayEvents: {
value: {
data: [EUROPE_TRIP._id as string],
count: 0,
pageSize: 0,
count: 1,
pageSize: 10,
},
isProcessing: false,
isSuccess: false,
error: undefined,
isSuccess: true,
error: null,
reason: null,
},
getWeekEvents: {
Expand All @@ -32,19 +32,19 @@ export const preloadedState: InitialReduxState = {
MULTI_WEEK._id as string,
TY_TIM._id as string,
],
count: 0,
pageSize: 0,
count: 6,
pageSize: 10,
},
isProcessing: false,
isSuccess: false,
error: undefined,
isSuccess: true,
error: null,
reason: null,
},
getDayEvents: {
value: null,
isProcessing: false,
isSuccess: false,
error: undefined,
isSuccess: true,
error: null,
reason: null,
},
entities: {
Expand All @@ -58,20 +58,35 @@ export const preloadedState: InitialReduxState = {
[TY_TIM._id as string]: TY_TIM,
},
},
draft: {
event: null,
status: {
activity: null,
isDrafting: false,
eventType: null,
dateToResize: null,
},
},
pendingEvents: {
eventIds: [],
},
},
settings: {
isCmdPaletteOpen: false,
},
sync: {
importGCal: {
importing: false,
},
importLatest: {
isFetchNeeded: false,
reason: null,
},
},
view: {
dates: {
start: "",
end: "",
start: "2025-12-07T00:00:00Z",
end: "2025-12-13T23:59:59Z",
},
sidebar: {
tab: "tasks",
Expand Down
6 changes: 5 additions & 1 deletion packages/web/src/__tests__/utils/providers/MemoryRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { act } from "react";
import { MemoryRouter } from "react-router-dom";
import { render } from "@web/__tests__/__mocks__/mock.render";

export const renderWithMemoryRouter = async (ui: React.ReactElement) => {
export const renderWithMemoryRouter = async (
ui: React.ReactElement,
initialEntries?: string[],
) => {
return await act(() =>
render(
<MemoryRouter
initialEntries={initialEntries}
future={{
v7_startTransition: true,
v7_relativeSplatPath: true,
Expand Down
33 changes: 5 additions & 28 deletions packages/web/src/__tests__/utils/state/store.test.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type TestState = {
error: unknown;
reason: string | null;
};

getWeekEvents?: {
value: {
data: string[];
Expand All @@ -45,6 +46,7 @@ type TestState = {
entities?: {
value: Record<string, unknown>;
};
[key: string]: unknown;
};
};
// Type for the initial state that can be passed to PreloadedState
Expand Down Expand Up @@ -82,34 +84,6 @@ export const createInitialState = (
isSuccess: false,
reason: null,
},
getCurrentMonthEvents: {
value: null,
isProcessing: false,
error: null,
isSuccess: false,
reason: null,
},
createEvent: {
isProcessing: false,
error: null,
value: null,
isSuccess: false,
reason: null,
},
editEvent: {
isProcessing: false,
error: null,
value: null,
isSuccess: false,
reason: null,
},
deleteEvent: {
isProcessing: false,
error: null,
value: null,
isSuccess: false,
reason: null,
},
draft: {
event: null,
status: {
Expand Down Expand Up @@ -140,6 +114,9 @@ export const createInitialState = (
isCmdPaletteOpen: false,
},
sync: {
importGCal: {
importing: false,
},
importLatest: {
isFetchNeeded: false,
reason: null,
Expand Down
47 changes: 0 additions & 47 deletions packages/web/src/views/Calendar/Calendar.form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,51 +142,4 @@ describe("Event Form", () => {
);
});
});

describe("Reminder", () => {
it("it should be focused when the 'r' keyboard shortcut is used", async () => {
const { container } = await act(() =>
render(<></>, { router, state: preloadedState }),
);

const reminderPlaceholder = screen.getByText(
"Click to add your reminder",
);

expect(reminderPlaceholder).toBeInTheDocument();

await act(async () => userEvent.keyboard("r"));

const reminderInput = container.querySelector('[id="reminderInput"]');

expect(reminderInput).toHaveFocus();
});

it("it should be focused when the 'edit reminder' btn is clicked in the command palette", async () => {
const user = userEvent.setup();

await act(() => render(<></>, { router, state: preloadedState }));

expect(
screen.getByText("Click to add your reminder"),
).toBeInTheDocument();

await act(async () => {
await user.keyboard(`{${getModifierKey()}>}k{/${getModifierKey()}}`);
});

const cmdPaletteEditBtn = await screen.findByRole("button", {
name: /edit reminder/i,
});
await act(async () => {
await user.click(cmdPaletteEditBtn);
});

await waitFor(() => {
const input = document.querySelector("#reminderInput");
expect(input).toBeInTheDocument();
expect(input).toHaveFocus();
});
}, 10000);
});
});
6 changes: 1 addition & 5 deletions packages/web/src/views/Calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ export const CalendarView = () => {
weekProps={weekProps}
isSidebarOpen={isSidebarOpen}
>
<SidebarDraftProvider
dateCalcs={dateCalcs}
measurements={measurements}
weekProps={weekProps}
>
<SidebarDraftProvider dateCalcs={dateCalcs} weekProps={weekProps}>
<Shortcuts shortcutsProps={shortcutProps}>
<ContextMenuWrapper id="sidebar-context-menu">
<Draft measurements={measurements} weekProps={weekProps} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { ReactNode } from "react";
import { ReactNode } from "react";
import { DateCalcs } from "@web/views/Calendar/hooks/grid/useDateCalcs";
import { Measurements_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout";
import { WeekProps } from "@web/views/Calendar/hooks/useWeek";
import { useSidebarActions } from "../hooks/useSidebarActions";
import { useSidebarEffects } from "../hooks/useSidebarEffects";
Expand All @@ -10,16 +9,14 @@ import { SidebarDraftContext } from "./SidebarDraftContext";
interface Props {
children: ReactNode;
dateCalcs: DateCalcs;
measurements: Measurements_Grid;
weekProps: WeekProps;
}
export const SidebarDraftProvider = ({
children,
dateCalcs,
measurements,
weekProps,
}: Props) => {
const { setters, state } = useSidebarState(measurements);
const { setters, state } = useSidebarState();
const actions = useSidebarActions(dateCalcs, state, setters, weekProps);
useSidebarEffects(state, actions);

Expand Down
9 changes: 1 addition & 8 deletions packages/web/src/views/Calendar/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useRef } from "react";
import { FC } from "react";
import dayjs, { Dayjs } from "@core/util/date/dayjs";
import { theme } from "@web/common/styles/theme";
import { getCalendarHeadingLabel } from "@web/common/utils/datetime/web.date.util";
Expand All @@ -12,11 +12,9 @@ import { viewSlice } from "@web/ducks/events/slices/view.slice";
import { useAppDispatch, useAppSelector } from "@web/store/store.hooks";
import { RootProps } from "../../calendarView.types";
import { Util_Scroll } from "../../hooks/grid/useScroll";
import { useReminderHotkey } from "../../hooks/shortcuts/useFocusHotkey";
import { WeekProps } from "../../hooks/useWeek";
import { TodayButton } from "../TodayButton/TodayButton";
import { DayLabels } from "./DayLabels";
import { Reminder } from "./Reminder/Reminder";
import {
ArrowNavigationButton,
StyledHeaderLabel,
Expand Down Expand Up @@ -51,10 +49,6 @@ export const Header: FC<Props> = ({ scrollUtil, today, weekProps }) => {
scrollToNow();
};

const reminderRef = useRef<HTMLDivElement>(null);

useReminderHotkey(() => reminderRef.current?.focus(), [reminderRef]);

return (
<>
<StyledHeaderRow alignItems={AlignItems.BASELINE}>
Expand All @@ -76,7 +70,6 @@ export const Header: FC<Props> = ({ scrollUtil, today, weekProps }) => {
<Text size="xl">{headerLabel}</Text>
</StyledHeaderLabel>
</StyledLeftGroup>
<Reminder ref={reminderRef} />
<StyledRightGroup>
<SelectView />
<div>
Expand Down
Loading