Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test ids to travel calendar days #771

Merged
merged 2 commits into from
Aug 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TravelDateCalendar } from "./TravelDateCalendar";
import { Column, Heading, Row, Spacing } from "@stenajs-webui/core";
import { Banner, Label } from "@stenajs-webui/elements";
import { parseLocalizedDateString } from "../../../features/localize-date-format/LocalizedDateParser";
import { isToday } from "date-fns";

export default {
title: "calendar/Calendar/TravelDateCalendar",
Expand Down Expand Up @@ -47,6 +48,27 @@ export const WithHeading = () => {
);
};

export const WithTestId = () => {
const [value, setValue] = useState<string>("");

const testId = (date: Date) => {
if (isToday(date)) {
return "today";
}
return undefined;
};
return (
<div style={{ display: "inline-block" }}>
<TravelDateCalendar
value={value}
onValueChange={setValue}
localeCode={"sv"}
dateTestId={testId}
/>
</div>
);
};

export const Locales = () => {
const locales = [
"sv",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface TravelDateCalendarProps
firstMonthInMonthPicker?: Date;
numMonthsInMonthPicker?: number;
size?: TravelCalendarSizeVariant;
dateTestId?: (date: Date) => string | undefined;
}

export const TravelDateCalendar: React.FC<TravelDateCalendarProps> = ({
Expand All @@ -36,6 +37,7 @@ export const TravelDateCalendar: React.FC<TravelDateCalendarProps> = ({
headingLevel,
numMonthsInMonthPicker = 12,
firstMonthInMonthPicker = new Date(),
dateTestId,
size = "medium",
}) => {
const inputProps = useTravelDateInput(
Expand Down Expand Up @@ -85,6 +87,7 @@ export const TravelDateCalendar: React.FC<TravelDateCalendarProps> = ({
selectedEndDate={selectedDate}
isValidDateRange={Boolean(selectedDate)}
multiSelectable={false}
dateTestId={dateTestId}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Column, Heading, Row, Spacing } from "@stenajs-webui/core";
import { Banner, Label } from "@stenajs-webui/elements";
import { TravelDateRangeInputValue } from "../../../features/travel-calendar/types";
import { parseLocalizedDateString } from "../../../features/localize-date-format/LocalizedDateParser";
import { isToday } from "date-fns";

export default {
title: "calendar/Calendar/TravelDateRangeCalendar",
Expand Down Expand Up @@ -52,6 +53,29 @@ export const WithHeading = () => {
);
};

export const WithTestId = () => {
const [value, setValue] = useState<TravelDateRangeInputValue | undefined>(
undefined
);
const testId = (date: Date) => {
if (isToday(date)) {
return "today";
}
return undefined;
};

return (
<div style={{ display: "inline-block" }}>
<TravelDateRangeCalendar
value={value}
onValueChange={setValue}
localeCode={"sv"}
dateTestId={testId}
/>
</div>
);
};

export const Locales = () => {
const locales = [
"sv",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface TravelDateRangeCalendarProps
firstMonthInMonthPicker?: Date;
numMonthsInMonthPicker?: number;
size?: TravelCalendarSizeVariant;
dateTestId?: (date: Date) => string | undefined;
}

export const TravelDateRangeCalendar: React.FC<
Expand All @@ -42,6 +43,7 @@ export const TravelDateRangeCalendar: React.FC<
numMonthsInMonthPicker = 12,
firstMonthInMonthPicker = new Date(),
size = "medium",
dateTestId,
}) => {
const inputProps = useTravelDateRangeInput(
value,
Expand Down Expand Up @@ -83,7 +85,12 @@ export const TravelDateRangeCalendar: React.FC<
/>

{visiblePanel === "calendar" && (
<TravelCalendar {...inputProps} size={size} multiSelectable={true} />
<TravelCalendar
{...inputProps}
size={size}
multiSelectable={true}
dateTestId={dateTestId}
/>
)}

{visiblePanel === "month-picker" && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@stenajs-webui/elements";
import { parseLocalizedDateString } from "../../../features/localize-date-format/LocalizedDateParser";
import { formatLocalizedDate } from "../../../features/localize-date-format/LocalizedDateFormatter";
import { addDays } from "date-fns";
import { addDays, isToday } from "date-fns";

export default {
title: "calendar/Input/TravelDateInput",
Expand Down Expand Up @@ -54,6 +54,28 @@ export const WithHeading = () => {
);
};

export const WithTestId = () => {
const [value, setValue] = useState<string>("");

const testId = (date: Date) => {
if (isToday(date)) {
return "today";
}
return undefined;
};

return (
<div style={{ display: "inline-block", padding: "150px 80px" }}>
<TravelDateInput
value={value}
onValueChange={setValue}
localeCode={"sv"}
dateTestId={testId}
/>
</div>
);
};

export const Sizes = () => {
const [value, setValue] = useState<string>("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface TravelDateInputProps
onHideCalendar?: () => void;
renderBelowCalendar?: (args: RenderBelowSingleDateCalendarArgs) => ReactNode;
size?: TravelCalendarSizeVariant;
dateTestId?: (date: Date) => string | undefined;
}

export const TravelDateInput: React.FC<TravelDateInputProps> = ({
Expand All @@ -65,6 +66,7 @@ export const TravelDateInput: React.FC<TravelDateInputProps> = ({
onHideCalendar,
renderBelowCalendar,
size = "medium",
dateTestId,
}) => {
const [calendarOpen, setCalendarOpen] = useState(false);
const [calendarInDom, setCalendarInDom] = useState(false);
Expand Down Expand Up @@ -204,6 +206,7 @@ export const TravelDateInput: React.FC<TravelDateInputProps> = ({
selectedStartDate={selectedDate}
selectedEndDate={selectedDate}
multiSelectable={false}
dateTestId={dateTestId}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { TravelDateRangeInputValue } from "../../../features/travel-calendar/types";
import { parseLocalizedDateString } from "../../../features/localize-date-format/LocalizedDateParser";
import { formatLocalizedDate } from "../../../features/localize-date-format/LocalizedDateFormatter";
import { addWeeks } from "date-fns";
import { addWeeks, isToday } from "date-fns";

export default {
title: "calendar/Input/TravelDateRangeInput",
Expand Down Expand Up @@ -59,6 +59,30 @@ export const WithHeading = () => {
);
};

export const WithTestId = () => {
const [value, setValue] = useState<TravelDateRangeInputValue | undefined>(
undefined
);
const testId = (date: Date) => {
if (isToday(date)) {
return "today";
}
return undefined;
};

return (
<div style={{ display: "inline-block", padding: "150px 80px" }}>
<TravelDateRangeInput
value={value}
onValueChange={setValue}
localeCode={"sv"}
heading={"Select dates"}
dateTestId={testId}
/>
</div>
);
};

export const Sizes = () => {
const [value, setValue] = useState<TravelDateRangeInputValue | undefined>(
undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface TravelDateRangeInputProps
onHideCalendar?: () => void;
renderBelowCalendar?: (args: RenderBelowCalendarArgs) => ReactNode;
size?: TravelCalendarSizeVariant;
dateTestId?: (date: Date) => string | undefined;
}

export const TravelDateRangeInput: React.FC<TravelDateRangeInputProps> = ({
Expand All @@ -68,6 +69,7 @@ export const TravelDateRangeInput: React.FC<TravelDateRangeInputProps> = ({
onHideCalendar,
renderBelowCalendar,
size = "medium",
dateTestId,
}) => {
const [calendarOpen, setCalendarOpen] = useState(false);
const [calendarInDom, setCalendarInDom] = useState(false);
Expand Down Expand Up @@ -204,6 +206,7 @@ export const TravelDateRangeInput: React.FC<TravelDateRangeInputProps> = ({
{...inputProps}
size={size}
multiSelectable={true}
dateTestId={dateTestId}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface TravelCalendarProps {
hoverDate: Date | undefined;
today: Date;
isDateDisabled: (date: Date) => boolean;
dateTestId?: (date: Date) => string | undefined;
calendarId: string;
todayIsInVisibleMonth: boolean;
size?: TravelCalendarSizeVariant;
Expand All @@ -46,6 +47,7 @@ export const TravelCalendar: React.FC<TravelCalendarProps> = ({
todayIsInVisibleMonth,
size = "medium",
multiSelectable,
dateTestId,
}) => {
return (
<table
Expand Down Expand Up @@ -84,6 +86,7 @@ export const TravelCalendar: React.FC<TravelCalendarProps> = ({
todayIsInVisibleMonth={todayIsInVisibleMonth}
calendarId={calendarId}
isDateDisabled={isDateDisabled}
dateTestId={dateTestId}
/>
))}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface TravelDateCellProps {
todayIsInVisibleMonth: boolean;
calendarId: string;
isDateDisabled: (date: Date) => boolean;
dateTestId?: (date: Date) => string | undefined;
size: TravelCalendarSizeVariant;
}

Expand All @@ -46,6 +47,7 @@ export const TravelDateCell: React.FC<TravelDateCellProps> = ({
calendarId,
isDateDisabled,
size,
dateTestId,
}) => {
const onKeyDown = useCallback<KeyboardEventHandler<HTMLTableDataCellElement>>(
async (e) => {
Expand Down Expand Up @@ -125,6 +127,7 @@ export const TravelDateCell: React.FC<TravelDateCellProps> = ({
{...(disabled
? undefined
: { "aria-selected": isSelectionStart || isSelectionEnd })}
data-testid={dateTestId?.(day.date)}
>
<div className={styles.outline} />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import {
} from "@stenajs-webui/elements";
import { Tooltip } from "@stenajs-webui/tooltip";

export type RailMenuLinkProps =
| (
| MenuButtonLinkNotSelectedProps
| MenuButtonLinkWithSelectedProps
| MenuButtonLinkWithRenderLinkProps
) & { label: string };
export type RailMenuLinkProps = (
| MenuButtonLinkNotSelectedProps
| MenuButtonLinkWithSelectedProps
| MenuButtonLinkWithRenderLinkProps
) & { label: string };

export const RailMenuLink: React.FC<RailMenuLinkProps> = ({
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import {
import { useRailContext } from "../rail/RailContext";
import { RailMenuLink } from "./RailMenuLink";

export type SidebarMenuLinkProps =
| (
| MenuButtonLinkNotSelectedProps
| MenuButtonLinkWithSelectedProps
| MenuButtonLinkWithRenderLinkProps
) & { label: string };
export type SidebarMenuLinkProps = (
| MenuButtonLinkNotSelectedProps
| MenuButtonLinkWithSelectedProps
| MenuButtonLinkWithRenderLinkProps
) & { label: string };

export const SidebarMenuLink: React.FC<SidebarMenuLinkProps> = (props) => {
const isRail = useRailContext();
Expand Down
Loading