Skip to content

Commit 90c4f36

Browse files
committed
fix: confirm slack route removal
1 parent cf4b57a commit 90c4f36

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

ui/src/pages/settings.test.tsx

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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',

ui/src/pages/settings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ function ConnectionSettingsPage() {
482482
};
483483

484484
const deleteRoute = async (externalChannelId: string) => {
485+
if (!window.confirm(`Remove channel route ${externalChannelId}?`)) return;
485486
await saveRoutes(routes.filter((route) => route.externalChannelId !== externalChannelId));
486487
};
487488

0 commit comments

Comments
 (0)