Skip to content

Commit d9ad81a

Browse files
committed
address comment
1 parent 2dcc6b0 commit d9ad81a

4 files changed

Lines changed: 11 additions & 101 deletions

File tree

src/views/schedule-actions/schedule-actions-modal-content/__tests__/schedule-actions-modal-content.test.tsx

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { QueryClient } from '@tanstack/react-query';
21
import { HttpResponse } from 'msw';
32

43
import { render, screen, userEvent, waitFor } from '@/test-utils/rtl';
54

6-
import { type DeleteScheduleResponse } from '@/route-handlers/delete-schedule/delete-schedule.types';
75
import { type PauseScheduleResponse } from '@/route-handlers/pause-schedule/pause-schedule.types';
86

97
import { mockScheduleActionsConfig } from '../../__fixtures__/schedule-actions-config';
10-
import { type ScheduleAction } from '../../schedule-actions.types';
118
import ScheduleActionsModalContent from '../schedule-actions-modal-content';
129

1310
const mockScheduleParams = {
@@ -26,10 +23,9 @@ jest.mock('baseui/snackbar', () => ({
2623
}),
2724
}));
2825

29-
const mockPush = jest.fn();
3026
jest.mock('next/navigation', () => ({
3127
...jest.requireActual('next/navigation'),
32-
useRouter: () => ({ push: mockPush }),
28+
useRouter: () => ({ push: jest.fn() }),
3329
}));
3430

3531
describe(ScheduleActionsModalContent.name, () => {
@@ -92,81 +88,9 @@ describe(ScheduleActionsModalContent.name, () => {
9288
});
9389
expect(mockOnClose).not.toHaveBeenCalled();
9490
});
95-
96-
describe('delete action', () => {
97-
it('renders confirmation copy with no form inputs', () => {
98-
setup({ actionConfig: mockScheduleActionsConfig[2] });
99-
100-
expect(screen.getAllByText('Delete schedule').length).toBeGreaterThan(0);
101-
expect(
102-
screen.getByText(
103-
'Deletes the schedule permanently. In-progress workflow runs are not affected.'
104-
)
105-
).toBeInTheDocument();
106-
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
107-
});
108-
109-
it('closes without DELETE when Cancel is clicked', async () => {
110-
const { user, mockOnClose } = setup({
111-
actionConfig: mockScheduleActionsConfig[2],
112-
});
113-
114-
await user.click(screen.getByText('Cancel'));
115-
expect(mockOnClose).toHaveBeenCalled();
116-
expect(mockEnqueue).not.toHaveBeenCalled();
117-
});
118-
119-
it('DELETEs with no body, navigates to list, and shows snackbar on success', async () => {
120-
const { user, mockOnClose, getLatestRequestBody, waitForRequest } = setup(
121-
{ actionConfig: mockScheduleActionsConfig[2] }
122-
);
123-
124-
await user.click(screen.getByRole('button', { name: 'Delete schedule' }));
125-
126-
await waitForRequest();
127-
expect(getLatestRequestBody()).toBeNull();
128-
129-
await waitFor(() => {
130-
expect(mockPush).toHaveBeenCalledWith(
131-
'/domains/mock-domain/mock-cluster/schedules'
132-
);
133-
});
134-
expect(mockEnqueue).toHaveBeenCalledWith(
135-
expect.objectContaining({ message: 'Schedule deleted.' })
136-
);
137-
expect(mockOnClose).toHaveBeenCalled();
138-
});
139-
140-
it('does not invalidate describeSchedule after delete', async () => {
141-
const invalidateQueriesSpy = jest.spyOn(
142-
QueryClient.prototype,
143-
'invalidateQueries'
144-
);
145-
146-
const { user, waitForRequest } = setup({
147-
actionConfig: mockScheduleActionsConfig[2],
148-
});
149-
150-
await user.click(screen.getByRole('button', { name: 'Delete schedule' }));
151-
152-
await waitForRequest();
153-
154-
expect(invalidateQueriesSpy).not.toHaveBeenCalledWith(
155-
expect.objectContaining({
156-
queryKey: ['describeSchedule', mockScheduleParams],
157-
})
158-
);
159-
});
160-
});
16191
});
16292

163-
function setup({
164-
error,
165-
actionConfig,
166-
}: {
167-
error?: boolean;
168-
actionConfig?: ScheduleAction<any, any, any>;
169-
}) {
93+
function setup({ error }: { error?: boolean }) {
17094
const user = userEvent.setup();
17195
const mockOnClose = jest.fn();
17296
let latestRequestBody: unknown = null;
@@ -177,7 +101,7 @@ function setup({
177101

178102
render(
179103
<ScheduleActionsModalContent
180-
action={actionConfig ?? mockScheduleActionsConfig[0]}
104+
action={mockScheduleActionsConfig[0]}
181105
params={{ ...mockScheduleParams }}
182106
onCloseModal={mockOnClose}
183107
/>,
@@ -202,18 +126,6 @@ function setup({
202126
return HttpResponse.json({} satisfies PauseScheduleResponse);
203127
},
204128
},
205-
{
206-
path: '/api/domains/:domain/:cluster/schedules/:scheduleId',
207-
httpMethod: 'DELETE',
208-
mockOnce: false,
209-
httpResolver: async ({ request }) => {
210-
const text = await request.text();
211-
latestRequestBody = text ? JSON.parse(text) : null;
212-
requestPromiseResolve(null);
213-
214-
return HttpResponse.json({} satisfies DeleteScheduleResponse);
215-
},
216-
},
217129
],
218130
}
219131
);

src/views/schedule-actions/schedule-actions-modal-content/schedule-actions-modal-content.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,13 @@ export default function ScheduleActionsModalContent<
6565

6666
return request(action.apiRoute({ domain, cluster, scheduleId }), {
6767
method: httpMethod,
68-
...(httpMethod === 'POST'
69-
? { body: JSON.stringify(submissionData ?? {}) }
70-
: {}),
68+
body: JSON.stringify(submissionData ?? {}),
7169
}).then((res) => res.json() as Result);
7270
},
7371
onSuccess: (result, mutationParams) => {
74-
if (action.id !== 'delete') {
75-
queryClient.invalidateQueries({
76-
queryKey: ['describeSchedule', params],
77-
});
78-
}
72+
queryClient.invalidateQueries({
73+
queryKey: ['describeSchedule', params],
74+
});
7975

8076
action.onSuccess?.({ queryClient, params, router });
8177

src/views/schedule-actions/schedule-actions-modal/schedule-actions-modal.styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const overrides = {
1212
},
1313
Dialog: {
1414
style: (): StyleObject => ({
15-
width: '600px',
15+
width: '900px',
1616
}),
1717
},
1818
} satisfies ModalOverrides,

src/views/schedule-actions/schedule-actions.types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ export type ScheduleActionModalForm<FormData, SubmissionData> =
8686
transformFormDataToSubmission?: undefined;
8787
};
8888

89+
export type ScheduleActionHttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
90+
8991
export type ScheduleAction<
9092
Result,
9193
FormData = undefined,
@@ -107,7 +109,7 @@ export type ScheduleAction<
107109
schedule: DescribeScheduleResponse
108110
) => ScheduleActionRunnableStatus;
109111
apiRoute: (params: ScheduleActionInputParams) => string;
110-
httpMethod?: 'POST' | 'DELETE';
112+
httpMethod?: ScheduleActionHttpMethod;
111113
getConfirmSubmissionData?: () => SubmissionData;
112114
renderSuccessMessage: (
113115
props: ScheduleActionSuccessMessageProps<SubmissionData, Result>

0 commit comments

Comments
 (0)