@@ -185,6 +185,89 @@ describe('SettingsPage', () => {
185185 } ) ;
186186 } ) ;
187187
188+ it ( 'asks for confirmation before removing a channel route' , async ( ) => {
189+ const user = userEvent . setup ( ) ;
190+ const confirmSpy = vi . spyOn ( window , 'confirm' ) . mockReturnValue ( false ) ;
191+ requestMock . mockImplementation ( ( path : string , options ?: RequestInit ) => {
192+ if ( options ?. method === 'PUT' ) {
193+ return Promise . resolve ( { status : 'ok' } ) ;
194+ }
195+ return Promise . resolve ( {
196+ status : 'ok' ,
197+ installation : {
198+ id : 'chinst_test' ,
199+ state : 'ready' ,
200+ route : {
201+ provider : 'slack' ,
202+ principalId : 'shared-slack-app' ,
203+ externalScopeType : 'workspace' ,
204+ externalTenantId : 'T_workspace' ,
205+ } ,
206+ allowedActions : [ 'manage_channels' ] ,
207+ connections : [
208+ {
209+ id : 'chconn_test' ,
210+ displayName : 'zeno' ,
211+ isDefault : true ,
212+ status : 'ready' ,
213+ routes : [
214+ {
215+ id : 'chroute_existing' ,
216+ externalChannelId : 'C_EXISTING' ,
217+ externalChannelType : 'channel' ,
218+ requireMention : false ,
219+ enabled : true ,
220+ } ,
221+ ] ,
222+ } ,
223+ ] ,
224+ } ,
225+ connection : {
226+ id : 'chconn_test' ,
227+ displayName : 'zeno' ,
228+ isDefault : true ,
229+ status : 'ready' ,
230+ routes : [
231+ {
232+ id : 'chroute_existing' ,
233+ externalChannelId : 'C_EXISTING' ,
234+ externalChannelType : 'channel' ,
235+ requireMention : false ,
236+ enabled : true ,
237+ } ,
238+ ] ,
239+ } ,
240+ path,
241+ } ) ;
242+ } ) ;
243+
244+ render (
245+ < MemoryRouter initialEntries = { [ '/slack/channels/installations/chinst_test/connections/chconn_test' ] } >
246+ < SettingsPage />
247+ </ MemoryRouter > ,
248+ ) ;
249+
250+ await screen . findByText ( 'C_EXISTING' ) ;
251+ await user . click ( screen . getByRole ( 'button' , { name : 'Remove' } ) ) ;
252+ expect ( confirmSpy ) . toHaveBeenCalledWith ( 'Remove channel route C_EXISTING?' ) ;
253+ expect (
254+ requestMock . mock . calls . some ( ( [ , options ] ) => ( options as RequestInit | undefined ) ?. method === 'PUT' ) ,
255+ ) . toBe ( false ) ;
256+
257+ confirmSpy . mockReturnValue ( true ) ;
258+ await user . click ( screen . getByRole ( 'button' , { name : 'Remove' } ) ) ;
259+
260+ await waitFor ( ( ) => {
261+ const putCall = requestMock . mock . calls . find (
262+ ( [ , options ] ) => ( options as RequestInit | undefined ) ?. method === 'PUT' ,
263+ ) ;
264+ expect ( putCall ) . toBeDefined ( ) ;
265+ const payload = JSON . parse ( String ( ( putCall ?. [ 1 ] as RequestInit ) . body ) ) ;
266+ expect ( payload ) . toEqual ( { channelPolicies : [ ] } ) ;
267+ } ) ;
268+ confirmSpy . mockRestore ( ) ;
269+ } ) ;
270+
188271 it ( 'shows an empty state when installs have no channel connections' , async ( ) => {
189272 requestMock . mockResolvedValue ( {
190273 status : 'ok' ,
0 commit comments