Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 84 additions & 21 deletions static/gsAdmin/views/sentryAppDetails.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,102 @@
import {SentryAppFixture} from 'sentry-fixture/sentryApp';

import {render, screen} from 'sentry-test/reactTestingLibrary';
import {
render,
renderGlobalModal,
screen,
userEvent,
waitFor,
} from 'sentry-test/reactTestingLibrary';

import {SentryAppDetails} from 'admin/views/sentryAppDetails';

function renderSentryAppDetails(overrides: Record<string, any> = {}) {
const sentryApp = {
...SentryAppFixture({slug: 'test-app', status: 'unpublished'}),
owner: {slug: 'test-org'},
isDisabled: false,
...overrides,
};

MockApiClient.addMockResponse({
url: `/sentry-apps/${sentryApp.slug}/`,
method: 'GET',
body: sentryApp,
});

render(<SentryAppDetails />, {
initialRouterConfig: {
location: {pathname: `/_admin/sentry-apps/${sentryApp.slug}/`},
route: '/_admin/sentry-apps/:sentryAppSlug/',
},
});

return sentryApp;
}

describe('SentryAppDetails', () => {
beforeEach(() => {
MockApiClient.clearMockResponses();
});

it('renders an unpublished app without crashing', async () => {
const sentryApp = {
...SentryAppFixture({
slug: 'cursor-staging',
status: 'unpublished',
}),
owner: {slug: 'cursor'},
};

MockApiClient.addMockResponse({
renderSentryAppDetails();

expect(await screen.findByRole('heading', {name: 'Sentry Apps'})).toBeInTheDocument();
expect(screen.getAllByText('unpublished')).not.toHaveLength(0);
});

it('shows disable action for a non-disabled app', async () => {
Comment thread
Christinarlong marked this conversation as resolved.
renderSentryAppDetails({isDisabled: false});

await userEvent.click(await screen.findByTestId('detail-actions'));
expect(await screen.findByText('Disable App')).toBeInTheDocument();
expect(screen.queryByText('disabled')).not.toBeInTheDocument();
});

it('shows enable action and disabled badge for a disabled app', async () => {
renderSentryAppDetails({isDisabled: true});

expect(await screen.findByText('disabled')).toBeInTheDocument();
await userEvent.click(screen.getByTestId('detail-actions'));
expect(await screen.findByText('Enable App')).toBeInTheDocument();
});

it('shows Enabled: yes for a non-disabled app', async () => {
renderSentryAppDetails({isDisabled: false});

expect(await screen.findByText('Enabled:')).toBeInTheDocument();
expect(screen.getByText('yes')).toBeInTheDocument();
});

it('shows Enabled: no for a disabled app', async () => {
renderSentryAppDetails({isDisabled: true});

expect(await screen.findByText('Enabled:')).toBeInTheDocument();
expect(screen.getAllByText('no')).toHaveLength(2);
});

it('sends PUT with isDisabled when disable action is confirmed', async () => {
const sentryApp = renderSentryAppDetails({isDisabled: false});
renderGlobalModal();

const putMock = MockApiClient.addMockResponse({
url: `/sentry-apps/${sentryApp.slug}/`,
method: 'GET',
body: sentryApp,
method: 'PUT',
body: {...sentryApp, isDisabled: true},
});

render(<SentryAppDetails />, {
initialRouterConfig: {
location: {
pathname: `/_admin/sentry-apps/${sentryApp.slug}/`,
},
route: '/_admin/sentry-apps/:sentryAppSlug/',
},
await userEvent.click(await screen.findByTestId('detail-actions'));
await userEvent.click(await screen.findByRole('option', {name: /Disable App/}));
await userEvent.click(await screen.findByRole('button', {name: 'Confirm'}));

await waitFor(() => {
expect(putMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({data: {isDisabled: true}})
);
});

expect(await screen.findByRole('heading', {name: 'Sentry Apps'})).toBeInTheDocument();
expect(screen.getAllByText('unpublished')).not.toHaveLength(0);
expect(await screen.findByText('disabled')).toBeInTheDocument();
});
});
20 changes: 18 additions & 2 deletions static/gsAdmin/views/sentryAppDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ export function SentryAppDetails() {
publishingAction = undefined;
}

const disableAction: ActionItem = data.isDisabled
? {
key: 'enable',
name: 'Enable App',
help: 'Re-enables this Sentry App',
onAction: () => onUpdateMutation.mutate({isDisabled: false}),
}
: {
key: 'disable',
name: 'Disable App',
help: 'Disables this Sentry App, blocking all API access and webhook delivery',
onAction: () => onUpdateMutation.mutate({isDisabled: true}),
};

const updateDetailsAction = {
key: 'update-details',
name: 'Update Details',
Expand All @@ -107,8 +121,8 @@ export function SentryAppDetails() {

const actions =
publishingAction === undefined
? [updateDetailsAction]
: [updateDetailsAction, publishingAction];
? [updateDetailsAction, disableAction]
: [updateDetailsAction, publishingAction, disableAction];
const sentryAppBadgeLevel: Partial<Record<string, NonNullable<BadgeItem['level']>>> = {
unpublished: 'danger',
internal: 'warning',
Expand All @@ -124,6 +138,7 @@ export function SentryAppDetails() {
<Link to={`/_admin/customers/${data.owner.slug}/`}>{data.owner.slug}</Link>
</DetailLabel>
<DetailLabel title="isAlertable" yesNo={data.isAlertable} />
<DetailLabel title="Enabled" yesNo={!data.isDisabled} />
<DetailLabel title="Popularity">{data.popularity}</DetailLabel>
<DetailLabel title="Scopes">
{data.scopes.map((scope: any) => (
Expand Down Expand Up @@ -163,6 +178,7 @@ export function SentryAppDetails() {
name: data.status,
level: sentryAppBadgeLevel[data.status] ?? 'success',
},
...(data.isDisabled ? [{name: 'disabled', level: 'danger' as const}] : []),
]}
actions={actions}
sections={[{content: overview}]}
Expand Down
Loading