[ResponseOps][MaintenanceWindows] Fix startDate not forwarded to custom recurrence component (#223949)

## Summary

- Forwards `startDate` correctly to the `CustomRecurringSchedule`
component. The missing prop caused the monthly custom frequency
sub-options to not show up.
- Fixes the `CustomRecurringSchedule` component type to correctly
reflect the required prop.
- Removes the `custom-recurring-form` data test subject from the
`<CustomRecurringSchedule>` JSX tag. The test subject wasn't forwarded
to any DOM element, but the only test with an assertion using that test
subject was passing because it was checking its absence
(`not.toBeInTheDocument()`).

## Verification steps

1. Open the Maintenance Window creation page
2. Toggle "Repeat" on
3. In the recurrence form, check that all the custom frequencies work,
showing the correct sub-options
This commit is contained in:
Umberto Pepato 2025-06-16 14:37:01 +02:00 committed by GitHub
parent d017a33f99
commit 73a2469bff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 156 additions and 131 deletions

View file

@ -37,6 +37,8 @@ const TestWrapper = ({ children, iv = initialValue }: PropsWithChildren<{ iv?: F
return <Form form={form}>{children}</Form>;
};
const startDate = new Date().toISOString();
describe('CustomRecurringSchedule', () => {
beforeEach(() => {
jest.clearAllMocks();
@ -45,7 +47,7 @@ describe('CustomRecurringSchedule', () => {
it('renders all form fields', async () => {
render(
<TestWrapper>
<CustomRecurringSchedule />
<CustomRecurringSchedule startDate={startDate} />
</TestWrapper>
);
@ -58,7 +60,7 @@ describe('CustomRecurringSchedule', () => {
it('renders byweekday field if custom frequency = weekly', async () => {
render(
<TestWrapper>
<CustomRecurringSchedule />
<CustomRecurringSchedule startDate={startDate} />
</TestWrapper>
);
@ -83,7 +85,7 @@ describe('CustomRecurringSchedule', () => {
};
render(
<TestWrapper iv={iv}>
<CustomRecurringSchedule />
<CustomRecurringSchedule startDate={startDate} />
</TestWrapper>
);
@ -93,7 +95,7 @@ describe('CustomRecurringSchedule', () => {
it('renders bymonth field if custom frequency = monthly', async () => {
render(
<TestWrapper>
<CustomRecurringSchedule />
<CustomRecurringSchedule startDate={startDate} />
</TestWrapper>
);
@ -111,7 +113,7 @@ describe('CustomRecurringSchedule', () => {
it('should initialize the form when no initialValue provided', () => {
render(
<TestWrapper>
<CustomRecurringSchedule />
<CustomRecurringSchedule startDate={startDate} />
</TestWrapper>
);
@ -139,7 +141,7 @@ describe('CustomRecurringSchedule', () => {
};
render(
<TestWrapper iv={iv}>
<CustomRecurringSchedule />
<CustomRecurringSchedule startDate={startDate} />
</TestWrapper>
);

View file

@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import React, { useMemo } from 'react';
import React, { memo, useMemo } from 'react';
import { Frequency } from '@kbn/rrule';
import moment from 'moment';
import { css } from '@emotion/react';
@ -42,11 +42,10 @@ const styles = {
};
export interface CustomRecurringScheduleProps {
startDate?: string;
startDate: string;
}
export const CustomRecurringSchedule: React.FC = React.memo(
({ startDate }: CustomRecurringScheduleProps) => {
export const CustomRecurringSchedule = memo(({ startDate }: CustomRecurringScheduleProps) => {
const [{ recurringSchedule }] = useFormData<{ recurringSchedule: RecurringSchedule }>({
watch: [
'recurringSchedule.frequency',
@ -171,7 +170,6 @@ export const CustomRecurringSchedule: React.FC = React.memo(
) : null}
</>
);
}
);
});
CustomRecurringSchedule.displayName = 'CustomRecurringSchedule';

View file

@ -18,6 +18,7 @@ import type { RecurringSchedule } from '../types';
import { Form, useForm } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib';
import { getRecurringScheduleFormSchema } from '../schemas/recurring_schedule_form_schema';
import { RecurrenceEnd } from '../constants';
import { Frequency } from '@kbn/rrule';
const baseProps: RecurringScheduleFieldsProps = {
startDate: '2023-03-24',
@ -29,7 +30,7 @@ interface FormValue {
const initialValue: FormValue = {
recurringSchedule: {
frequency: 'CUSTOM',
frequency: Frequency.WEEKLY,
ends: RecurrenceEnd.NEVER,
},
};
@ -57,7 +58,7 @@ describe('RecurringScheduleForm', () => {
);
expect(screen.getByTestId('frequency-field')).toBeInTheDocument();
expect(screen.queryByTestId('custom-recurring-form')).not.toBeInTheDocument();
expect(screen.queryByTestId('customRecurringScheduleIntervalInput')).not.toBeInTheDocument();
expect(screen.getByTestId('ends-field')).toBeInTheDocument();
expect(screen.queryByTestId('until-field')).not.toBeInTheDocument();
expect(screen.queryByTestId('count-field')).not.toBeInTheDocument();
@ -88,4 +89,28 @@ describe('RecurringScheduleForm', () => {
await userEvent.click(btn);
expect(await screen.findByTestId('count-field')).toBeInTheDocument();
});
it('renders custom schedule if frequency = daily', async () => {
render(
<TestWrapper
iv={{ recurringSchedule: { frequency: Frequency.DAILY, ends: RecurrenceEnd.NEVER } }}
>
<RecurringScheduleFormFields {...baseProps} />
</TestWrapper>
);
expect(
await screen.findByTestId('customRecurringScheduleByWeekdayButtonGroup')
).toBeInTheDocument();
});
it('renders custom schedule if frequency = custom', async () => {
render(
<TestWrapper iv={{ recurringSchedule: { frequency: 'CUSTOM', ends: RecurrenceEnd.NEVER } }}>
<RecurringScheduleFormFields {...baseProps} />
</TestWrapper>
);
expect(await screen.findByTestId('customRecurringScheduleIntervalInput')).toBeInTheDocument();
});
});

View file

@ -59,7 +59,7 @@ export const toMoment = (value: string): Moment => moment(value);
export const toString = (value: Moment): string => value.toISOString();
export interface RecurringScheduleFieldsProps {
startDate?: string;
startDate: string;
endDate?: string;
timezone?: string[];
allowInfiniteRecurrence?: boolean;
@ -147,7 +147,7 @@ export const RecurringScheduleFormFields = memo(
/>
{(parsedSchedule?.frequency === Frequency.DAILY ||
parsedSchedule?.frequency === 'CUSTOM') && (
<CustomRecurringSchedule data-test-subj="custom-recurring-form" />
<CustomRecurringSchedule startDate={startDate} />
)}
<UseField
path="recurringSchedule.ends"