The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix SDK subscription not working under StrictMode (#70663)
Mahatthana (Kelvin) Nomsawadi6351e5bc0e9c
diff --git a/e2e/test-component/scenarios/embedding-sdk/subscriptions.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/subscriptions.cy.spec.tsxindex ffd0bd46f2f..d2e798ce99f 100644--- a/e2e/test-component/scenarios/embedding-sdk/subscriptions.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/subscriptions.cy.spec.tsx@@ -77,6 +77,7 @@ describe("scenarios > embedding-sdk > subscriptions", () => {mountSdkContent(<StaticDashboard dashboardId={dashboardId} withSubscriptions />,+ { strictMode: true },);});@@ -85,6 +86,9 @@ describe("scenarios > embedding-sdk > subscriptions", () => {cy.icon("subscription").click();cy.findByText("Email this dashboard").should("be.visible");+ // EMB-1413+ cy.findByDisplayValue("Hourly").click();+cy.log("can customize filter values");cy.findByRole("heading", {name: "Set filter values for when this gets sent",@@ -107,6 +111,7 @@ describe("scenarios > embedding-sdk > subscriptions", () => {mountSdkContent(<InteractiveDashboard dashboardId={dashboardId} withSubscriptions />,+ { strictMode: true },);});@@ -115,6 +120,9 @@ describe("scenarios > embedding-sdk > subscriptions", () => {cy.icon("subscription").click();cy.findByText("Email this dashboard").should("be.visible");+ // EMB-1413+ cy.findByDisplayValue("Hourly").click();+cy.log("can customize filter values");cy.findByRole("heading", {name: "Set filter values for when this gets sent",@@ -137,6 +145,7 @@ describe("scenarios > embedding-sdk > subscriptions", () => {mountSdkContent(<EditableDashboard dashboardId={dashboardId} withSubscriptions />,+ { strictMode: true },);});@@ -145,6 +154,9 @@ describe("scenarios > embedding-sdk > subscriptions", () => {cy.icon("subscription").click();cy.findByText("Email this dashboard").should("be.visible");+ // EMB-1413+ cy.findByDisplayValue("Hourly").click();+cy.log("can customize filter values");cy.findByRole("heading", {name: "Set filter values for when this gets sent",diff --git a/e2e/test/scenarios/admin/databases.cy.spec.js b/e2e/test/scenarios/admin/databases.cy.spec.jsindex 8cef332cbf1..8599f90f6ff 100644--- a/e2e/test/scenarios/admin/databases.cy.spec.js+++ b/e2e/test/scenarios/admin/databases.cy.spec.js@@ -807,8 +807,7 @@ describe("scenarios > admin > databases > sample database", () => {cy.findByLabelText(/Choose when syncs and scans happen/).click({force: true,});- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Hourly").click();+ cy.findByDisplayValue("Hourly").click();H.popover().within(() => {cy.findByText("Daily").click({ force: true });});@@ -819,10 +818,7 @@ describe("scenarios > admin > databases > sample database", () => {.click();H.popover().findByText("Regularly, on a schedule").click();- cy.findAllByRole("button", { name: /Daily/ })- .should("have.length", 2)- .eq(1)- .click();+ cy.findAllByDisplayValue("Daily").should("have.length", 2).eq(1).click();H.popover().findByText("Weekly").click();cy.button("Save changes").click();diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding/embed-options.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding/embed-options.cy.spec.tsindex 0524c117a23..d2d34bc89a8 100644--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding/embed-options.cy.spec.ts+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding/embed-options.cy.spec.ts@@ -114,7 +114,7 @@ describe("EE", () => {cy.log("set up the second subscription");cy.button("Set up a new schedule").click();- cy.findByText("Hourly").click();+ cy.findByDisplayValue("Hourly").click();});H.popover().findByRole("option", { name: "Daily" }).click();diff --git a/e2e/test/scenarios/sharing/alert/alert.cy.spec.js b/e2e/test/scenarios/sharing/alert/alert.cy.spec.jsindex 8812d988c3e..8241983239d 100644--- a/e2e/test/scenarios/sharing/alert/alert.cy.spec.js+++ b/e2e/test/scenarios/sharing/alert/alert.cy.spec.js@@ -162,7 +162,8 @@ describe("scenarios > alert", () => {const adminSubscriptionError = `You're only allowed to email subscriptions to addresses ending in ${allowedDomain}`;function addEmailRecipient(email) {- cy.findByRole("textbox").click().type(`${email}`).blur();+ // Mantine Select has the role `textbox` 🤦+ cy.findAllByRole("textbox").first().click().type(`${email}`).blur();}function setAllowedDomains() {diff --git a/e2e/test/scenarios/sharing/subscriptions.cy.spec.js b/e2e/test/scenarios/sharing/subscriptions.cy.spec.jsindex 85ea37312bd..834d0ccb8f1 100644--- a/e2e/test/scenarios/sharing/subscriptions.cy.spec.js+++ b/e2e/test/scenarios/sharing/subscriptions.cy.spec.js@@ -82,21 +82,16 @@ describe("scenarios > dashboard > subscriptions", () => {it("should not enable subscriptions without the recipient (metabase#17657)", () => {openDashboardSubscriptions();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Email it").click();+ H.sidebar().findByText("Email it").click();// Make sure no recipients have been assignedcy.findByPlaceholderText("Enter user names or email addresses");// Change the schedule to "Monthly"- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Hourly").click();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Monthly").click();+ cy.findByDisplayValue("Hourly").click();+ H.popover().findByText("Monthly").click();- H.sidebar().within(() => {- cy.button("Done").should("be.disabled");- });+ H.sidebar().button("Done").should("be.disabled");});it("should allow creation of a new email subscription", () => {@@ -113,7 +108,7 @@ describe("scenarios > dashboard > subscriptions", () => {cy.findByPlaceholderText("Enter user names or email addresses").click();H.popover().should("be.visible").and("contain", `${admin.first_name}`);cy.realPress("Escape");- H.popover({ skipVisibilityCheck: true }).should("not.exist");+ H.popover({ skipVisibilityCheck: true }).should("not.be.visible");cy.findByPlaceholderText("Enter user names or email addresses").should("not.have.value",);@@ -354,21 +349,20 @@ describe("scenarios > dashboard > subscriptions", () => {it("should not display 'null' day of the week (metabase#14405)", () => {assignRecipient();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("To:").click();- cy.findAllByTestId("select-button").contains("Hourly").click();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Monthly").click();- cy.findAllByTestId("select-button").contains("First").click();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("15th (Midpoint)").click();- cy.findAllByTestId("select-button").contains("15th (Midpoint)").click();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("First").click();+ H.sidebar().findByText("To:").click();++ cy.findByDisplayValue("Hourly").click();+ H.popover().findByText("Monthly").click();++ cy.findByDisplayValue("First").click();+ H.popover().findByText("15th (Midpoint)").click();++ cy.findByDisplayValue("15th (Midpoint)").click();+ H.popover().findByText("First").click();+clickButton("Done");// Implicit assertion (word mustn't contain string "null")- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText(/^Emailed monthly on the first (?!null)/);+ H.sidebar().findByText(/^Emailed monthly on the first (?!null)/);});it("should work when using dashboard default filter value on native query with required parameter (metabase#15705)", () => {diff --git a/frontend/src/metabase/common/components/SchedulePicker/DynamicWidthSelect.tsx b/frontend/src/metabase/common/components/SchedulePicker/DynamicWidthSelect.tsxnew file mode 100644index 00000000000..746b1276609--- /dev/null+++ b/frontend/src/metabase/common/components/SchedulePicker/DynamicWidthSelect.tsx@@ -0,0 +1,94 @@+import { useMemo } from "react";++import { useSelector } from "metabase/lib/redux";+import { getSetting } from "metabase/selectors/settings";+import type { SelectProps } from "metabase/ui";+import { Select } from "metabase/ui";++import {+ getLongestSelectLabel,+ measureTextWidthSafely,+} from "../Schedule/utils";++// Icon + padding + extra buffer + scrollbar (for dropdown)+const BUFFER = 60;++// Use when somehow `measureTextWidthSafely` fails+const DEFAULT_WIDTH = 50;++const MIN_DROPDOWN_WIDTH = 150;++/**+ * A Select component with independent width calculations for button and dropdown.+ * - Button width: Based on currently selected option (with optional min-width)+ * - Dropdown width: Based on longest option in the list+ *+ * Created specifically for SchedulePicker (which is deprecated).+ */+export const DynamicWidthSelect = <Value extends string = string>({+ value,+ minButtonWidth,+ ...props+}: Omit<+ SelectProps<Value>,+ "value" | "onChange" | "comboboxProps" | "styles"+> & {+ value: Value | null | undefined;+ onChange: (newValue: Value | null) => void;+ minButtonWidth?: number;+}) => {+ const fontFamily = useSelector((state) =>+ getSetting(state, "application-font"),+ );++ const { buttonWidth, dropdownWidth } = useMemo(() => {+ const fontStyle = { family: fontFamily };++ // Calculate button width based on selected value+ const selectedLabel = getSelectedLabel(props.data, value);+ const measuredButtonWidth =+ measureTextWidthSafely(selectedLabel, DEFAULT_WIDTH, fontStyle) + BUFFER;+ const buttonWidth = Math.max(measuredButtonWidth, minButtonWidth || 0);++ // Calculate dropdown width based on longest option+ const longestLabel = getLongestSelectLabel(props.data);+ const dropdownWidth =+ measureTextWidthSafely(longestLabel, DEFAULT_WIDTH, fontStyle) + BUFFER;++ return { buttonWidth, dropdownWidth };+ }, [props.data, value, fontFamily, minButtonWidth]);++ return (+ <Select+ styles={{+ wrapper: { width: buttonWidth },+ }}+ comboboxProps={{+ position: "bottom-end",+ width: Math.max(MIN_DROPDOWN_WIDTH, dropdownWidth),+ }}+ value={value}+ {...props}+ />+ );+};++const getSelectedLabel = (+ data: SelectProps["data"],+ value: string | null | undefined,+): string => {+ if (!value) {+ return "";+ }+ for (const option of data) {+ if (+ typeof option === "object" &&+ option &&+ "value" in option &&+ option.value === value+ ) {+ return option.label;+ }+ }+ return value;+};diff --git a/frontend/src/metabase/common/components/SchedulePicker/SchedulePicker.tsx b/frontend/src/metabase/common/components/SchedulePicker/SchedulePicker.tsxindex ce913c8b83f..dfa9e4d550f 100644--- a/frontend/src/metabase/common/components/SchedulePicker/SchedulePicker.tsx+++ b/frontend/src/metabase/common/components/SchedulePicker/SchedulePicker.tsx@@ -2,8 +2,6 @@ import cx from "classnames";import { type CSSProperties, Component } from "react";import { t } from "ttag";-import type { SelectChangeEvent } from "metabase/common/components/Select";-import { Select } from "metabase/common/components/Select";import CS from "metabase/css/core/index.css";import {AM_PM_OPTIONS,@@ -15,7 +13,12 @@ import {import { capitalize } from "metabase/lib/formatting/strings";import { useSelector } from "metabase/lib/redux";import { getApplicationName } from "metabase/selectors/whitelabel";-import { Box, type BoxProps, SegmentedControl } from "metabase/ui";+import {+ Box,+ type BoxProps,+ SegmentedControl,+ type SelectOption,+} from "metabase/ui";import type {ScheduleDayType,ScheduleFrameType,@@ -23,6 +26,9 @@ import type {ScheduleType,} from "metabase-types/api";+import type { SelectOption as LegacySelectOption } from "../Select";++import { DynamicWidthSelect } from "./DynamicWidthSelect";import {PickerRow,PickerSpacedRow,@@ -68,6 +74,16 @@ export interface SchedulePickerProps {const DEFAULT_DAY = "mon";+/**+ * Transforms legacy Select data format to Mantine Select data format+ */+function toMantineData(options: LegacySelectOption[]): SelectOption[] {+ return options.map((option) => ({+ label: option.name ?? "",+ value: option.value.toString(),+ }));+}+/*** @deprecated use "metabase/common/components/Schedule" instead*/@@ -147,28 +163,37 @@ export class SchedulePicker extends Component<SchedulePickerProps> {const { schedule } = this.props;const DAY_OPTIONS = [- { name: t`Calendar Day`, value: null },- ...getDayOfWeekOptions(),+ { label: t`Calendar Day`, value: "" },+ ...toMantineData(getDayOfWeekOptions()),];return (<PickerSpacedRow><PickerText>{t`on the`}</PickerText>- <Select- value={schedule.schedule_frame}- onChange={(e: SelectChangeEvent<ScheduleFrameType>) =>- this.handleChangeProperty("schedule_frame", e.target.value)+ <DynamicWidthSelect+ minButtonWidth={110}+ value={schedule.schedule_frame ?? ""}+ onChange={(value) =>+ this.handleChangeProperty(+ "schedule_frame",+ value as ScheduleFrameType,+ )}- options={MONTH_DAY_OPTIONS}+ data={toMantineData(MONTH_DAY_OPTIONS)}/>{schedule.schedule_frame !== "mid" && (<span className={CS.mx1}>- <Select- value={schedule.schedule_day}- onChange={(e: SelectChangeEvent<ScheduleDayType>) =>- this.handleChangeProperty("schedule_day", e.target.value)+ <DynamicWidthSelect+ minButtonWidth={110}+ value={schedule.schedule_day ?? ""}+ onChange={(value) =>+ this.handleChangeProperty(+ "schedule_day",+ // We only need to convert this option back to null because it's the only option we change from `null` to `""` in this file.+ (value || null) as ScheduleDayType,+ )}- options={DAY_OPTIONS}+ data={DAY_OPTIONS}/></span>)}@@ -182,12 +207,13 @@ export class SchedulePicker extends Component<SchedulePickerProps> {return (<PickerRow><span className={cx(CS.textBold, CS.mx1)}>{t`on`}</span>- <Select- value={schedule.schedule_day}- onChange={(e: SelectChangeEvent<ScheduleDayType>) =>- this.handleChangeProperty("schedule_day", e.target.value)+ <DynamicWidthSelect+ minButtonWidth={110}+ value={schedule.schedule_day ?? ""}+ onChange={(value) =>+ this.handleChangeProperty("schedule_day", value as ScheduleDayType)}- options={getDayOfWeekOptions()}+ data={toMantineData(getDayOfWeekOptions())}/></PickerRow>);@@ -197,16 +223,20 @@ export class SchedulePicker extends Component<SchedulePickerProps> {const { schedule } = this.props;const minuteOfHour = isNaN(schedule.schedule_minute as number)? 0- : schedule.schedule_minute;+ : (schedule.schedule_minute ?? 0);return (<PickerSpacedRow><PickerText>{t`at`}</PickerText>- <Select+ <DynamicWidthSelect+ minButtonWidth={110}className={CS.mr1}- value={minuteOfHour}- options={MINUTE_OPTIONS}- onChange={(e: SelectChangeEvent<number>) =>- this.handleChangeProperty("schedule_minute", e.target.value)+ value={minuteOfHour.toString()}+ data={toMantineData(MINUTE_OPTIONS)}+ onChange={(value) =>+ this.handleChangeProperty(+ "schedule_minute",+ value ? parseInt(value) : 0,+ )}/><span className={CS.textBold}>{t`minutes past the hour`}</span>@@ -228,14 +258,15 @@ export class SchedulePicker extends Component<SchedulePickerProps> {<><PickerSpacedRow><PickerText>{t`at`}</PickerText>- <Select+ <DynamicWidthSelect+ minButtonWidth={110}className={CS.mr1}- value={hour}- options={HOUR_OPTIONS}- onChange={(e: SelectChangeEvent<number>) =>+ value={hour.toString()}+ data={toMantineData(HOUR_OPTIONS)}+ onChange={(value) =>this.handleChangeProperty("schedule_hour",- e.target.value + amPm * 12,+ (value ? parseInt(value) : 0) + amPm * 12,)}/>@@ -281,16 +312,18 @@ export class SchedulePicker extends Component<SchedulePickerProps> {<Box mt={mt} className={className} style={style}><PickerRow><PickerText>{textBeforeInterval}</PickerText>- <Select+ <DynamicWidthSelect+ minButtonWidth={110}value={scheduleType}- onChange={(e: SelectChangeEvent<ScheduleType>) =>- this.handleChangeProperty("schedule_type", e.target.value)- }- options={scheduleOptions}- optionNameFn={(o: ScheduleType) =>- optionNameTranslations[o] || capitalize(o)+ onChange={(value) =>+ this.handleChangeProperty("schedule_type", value as ScheduleType)}- optionValueFn={(o: ScheduleType) => o}+ data={scheduleOptions.map((scheduleOption) => ({+ label:+ optionNameTranslations[scheduleOption] ||+ capitalize(scheduleOption),+ value: scheduleOption,+ }))}/>{scheduleType === "weekly" && this.renderDayPicker()}</PickerRow>diff --git a/frontend/src/metabase/common/components/SchedulePicker/SchedulePicker.unit.spec.tsx b/frontend/src/metabase/common/components/SchedulePicker/SchedulePicker.unit.spec.tsxnew file mode 100644index 00000000000..8eb1c694fab--- /dev/null+++ b/frontend/src/metabase/common/components/SchedulePicker/SchedulePicker.unit.spec.tsx@@ -0,0 +1,418 @@+import userEvent from "@testing-library/user-event";++import { renderWithProviders, screen, within } from "__support__/ui";++import type { SchedulePickerProps } from "./SchedulePicker";+import { SchedulePicker } from "./SchedulePicker";++const DEFAULT_SCHEDULE_OPTIONS = [+ "hourly",+ "daily",+ "weekly",+ "monthly",+] as const;++const setup = (props?: Partial<SchedulePickerProps>) => {+ const onScheduleChange = jest.fn();+ const defaultProps: SchedulePickerProps = {+ schedule: {+ schedule_type: "daily",+ schedule_day: null,+ schedule_frame: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ scheduleOptions: [...DEFAULT_SCHEDULE_OPTIONS],+ onScheduleChange,+ ...props,+ };++ const { rerender } = renderWithProviders(+ <SchedulePicker {...defaultProps} />,+ );++ return {+ onScheduleChange,+ rerender: (newProps?: Partial<SchedulePickerProps>) =>+ rerender(<SchedulePicker {...defaultProps} {...newProps} />),+ props: defaultProps,+ };+};++describe("SchedulePicker", () => {+ describe("monthly schedule - schedule_frame selection", () => {+ it("should convert empty string to null when changing schedule_frame", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: "mon",+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ // Find the "First" select input by display value+ const frameSelect = screen.getByDisplayValue("First");+ await userEvent.click(frameSelect);++ // Select "15th (Midpoint)" which should result in null for non-day frames+ const listbox = await screen.findByRole("listbox");+ const midOption = within(listbox).getByText("15th (Midpoint)");+ await userEvent.click(midOption);++ // Verify that onScheduleChange was called with the correct value+ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "monthly",+ schedule_frame: "mid",+ schedule_day: null, // Should be null when frame is "mid"+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_frame",+ value: "mid",+ },+ );+ });++ it("should handle selecting 'first' frame correctly", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "mid",+ schedule_day: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ const frameSelect = screen.getByDisplayValue("15th (Midpoint)");+ await userEvent.click(frameSelect);++ const listbox = await screen.findByRole("listbox");+ const firstOption = within(listbox).getByText("First");+ await userEvent.click(firstOption);++ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: "mon", // Should default to "mon" when switching to first/last+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_frame",+ value: "first",+ },+ );+ });++ it("should handle selecting 'last' frame correctly", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "mid",+ schedule_day: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ const frameSelect = screen.getByDisplayValue("15th (Midpoint)");+ await userEvent.click(frameSelect);++ const listbox = await screen.findByRole("listbox");+ const lastOption = within(listbox).getByText("Last");+ await userEvent.click(lastOption);++ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "monthly",+ schedule_frame: "last",+ schedule_day: "mon",+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_frame",+ value: "last",+ },+ );+ });+ });++ describe("monthly schedule - schedule_day selection (Calendar Day)", () => {+ it("should convert empty string to null when selecting 'Calendar Day'", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: "mon",+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ // Find the "Monday" select input+ const daySelect = screen.getByDisplayValue("Monday");+ await userEvent.click(daySelect);++ // Select "Calendar Day" which has an empty string value+ const listbox = await screen.findByRole("listbox");+ const calendarDayOption = within(listbox).getByText("Calendar Day");+ await userEvent.click(calendarDayOption);++ // Verify that onScheduleChange was called with null, not "" because Mantine Select uses ""+ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_day",+ value: null,+ },+ );+ });++ it("should handle selecting a specific weekday correctly", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ // When schedule_day is null, it displays as "Calendar Day"+ const daySelect = screen.getByDisplayValue("Calendar Day");+ await userEvent.click(daySelect);++ // Select a specific weekday+ const listbox = await screen.findByRole("listbox");+ const wednesdayOption = within(listbox).getByText("Wednesday");+ await userEvent.click(wednesdayOption);++ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: "wed",+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_day",+ value: "wed",+ },+ );+ });+ });++ describe("monthly schedule - day picker visibility", () => {+ it("should hide day picker when schedule_frame is 'mid'", () => {+ setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "mid",+ schedule_day: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ // Should have "on the" text+ expect(screen.getByText("on the")).toBeInTheDocument();++ // Should have the "15th (Midpoint)" select+ expect(screen.getByDisplayValue("15th (Midpoint)")).toBeInTheDocument();++ // Verify that there's no "Calendar Day" or weekday option visible+ // (the day picker is not rendered when frame is "mid")+ expect(+ screen.queryByDisplayValue("Calendar Day"),+ ).not.toBeInTheDocument();+ expect(screen.queryByDisplayValue("Monday")).not.toBeInTheDocument();+ });++ it("should show day picker when schedule_frame is 'first'", () => {+ setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: "mon",+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ // When frame is "first", day picker should be visible+ expect(screen.getByDisplayValue("First")).toBeInTheDocument();+ expect(screen.getByDisplayValue("Monday")).toBeInTheDocument();+ expect(screen.getByText("on the")).toBeInTheDocument();+ });++ it("should show day picker when schedule_frame is 'last'", () => {+ setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "last",+ schedule_day: "fri",+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ expect(screen.getByDisplayValue("Last")).toBeInTheDocument();+ expect(screen.getByDisplayValue("Friday")).toBeInTheDocument();+ expect(screen.getByText("on the")).toBeInTheDocument();+ });+ });++ describe("weekly schedule - schedule_day selection", () => {+ it("should handle selecting a weekday correctly", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "weekly",+ schedule_day: "mon",+ schedule_frame: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ // Find the "Monday" select in weekly view+ const daySelect = screen.getByDisplayValue("Monday");+ await userEvent.click(daySelect);++ const listbox = await screen.findByRole("listbox");+ const fridayOption = within(listbox).getByText("Friday");+ await userEvent.click(fridayOption);++ // Verify the day was changed correctly+ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "weekly",+ schedule_day: "fri",+ schedule_frame: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_day",+ value: "fri",+ },+ );+ });+ });++ describe("schedule type changes", () => {+ it("should clear frame and day when switching to daily", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: "mon",+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ const typeSelect = screen.getByDisplayValue("Monthly");+ await userEvent.click(typeSelect);++ const listbox = await screen.findByRole("listbox");+ const dailyOption = within(listbox).getByText("Daily");+ await userEvent.click(dailyOption);++ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "daily",+ schedule_day: null,+ schedule_frame: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_type",+ value: "daily",+ },+ );+ });++ it("should set default day and clear frame when switching to weekly", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "daily",+ schedule_day: null,+ schedule_frame: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ const typeSelect = screen.getByDisplayValue("Daily");+ await userEvent.click(typeSelect);++ const listbox = await screen.findByRole("listbox");+ const weeklyOption = within(listbox).getByText("Weekly");+ await userEvent.click(weeklyOption);++ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "weekly",+ schedule_day: "mon",+ schedule_frame: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_type",+ value: "weekly",+ },+ );+ });++ it("should set default values when switching to monthly", async () => {+ const { onScheduleChange } = setup({+ schedule: {+ schedule_type: "daily",+ schedule_day: null,+ schedule_frame: null,+ schedule_hour: 8,+ schedule_minute: 0,+ },+ });++ // Find and click the "Daily" select+ const typeSelect = screen.getByDisplayValue("Daily");+ await userEvent.click(typeSelect);++ const listbox = await screen.findByRole("listbox");+ const monthlyOption = within(listbox).getByText("Monthly");+ await userEvent.click(monthlyOption);++ expect(onScheduleChange).toHaveBeenCalledWith(+ {+ schedule_type: "monthly",+ schedule_frame: "first",+ schedule_day: "mon",+ schedule_hour: 8,+ schedule_minute: 0,+ },+ {+ name: "schedule_type",+ value: "monthly",+ },+ );+ });+ });+});