1- import { QueryClient } from '@tanstack/react-query' ;
21import { HttpResponse } from 'msw' ;
32
43import { render , screen , userEvent , waitFor } from '@/test-utils/rtl' ;
54
6- import { type DeleteScheduleResponse } from '@/route-handlers/delete-schedule/delete-schedule.types' ;
75import { type PauseScheduleResponse } from '@/route-handlers/pause-schedule/pause-schedule.types' ;
86
97import { mockScheduleActionsConfig } from '../../__fixtures__/schedule-actions-config' ;
10- import { type ScheduleAction } from '../../schedule-actions.types' ;
118import ScheduleActionsModalContent from '../schedule-actions-modal-content' ;
129
1310const mockScheduleParams = {
@@ -26,10 +23,9 @@ jest.mock('baseui/snackbar', () => ({
2623 } ) ,
2724} ) ) ;
2825
29- const mockPush = jest . fn ( ) ;
3026jest . mock ( 'next/navigation' , ( ) => ( {
3127 ...jest . requireActual ( 'next/navigation' ) ,
32- useRouter : ( ) => ( { push : mockPush } ) ,
28+ useRouter : ( ) => ( { push : jest . fn ( ) } ) ,
3329} ) ) ;
3430
3531describe ( 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 ) ;
0 commit comments