123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import SentryAppDetailsModal from 'sentry/components/modals/sentryAppDetailsModal';
- function renderMockRequests({sentryAppSlug}: {sentryAppSlug: string}) {
- const features = MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryAppSlug}/features/`,
- method: 'GET',
- body: [],
- });
- const interaction = MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryAppSlug}/interaction/`,
- method: 'POST',
- statusCode: 200,
- body: {},
- });
- return {features, interaction};
- }
- describe('SentryAppDetailsModal', function () {
- const sentryApp = TestStubs.SentryApp();
- it('renders', function () {
- renderMockRequests({sentryAppSlug: sentryApp.slug});
- render(
- <SentryAppDetailsModal
- closeModal={jest.fn()}
- isInstalled={false}
- onInstall={jest.fn()}
- organization={TestStubs.Organization()}
- sentryApp={sentryApp}
- />
- );
- expect(screen.getByText(sentryApp.name)).toBeInTheDocument();
- });
- it('records interaction request', function () {
- const mockRequests = renderMockRequests({sentryAppSlug: sentryApp.slug});
- render(
- <SentryAppDetailsModal
- closeModal={jest.fn()}
- isInstalled={false}
- onInstall={jest.fn()}
- organization={TestStubs.Organization()}
- sentryApp={sentryApp}
- />
- );
- expect(mockRequests.interaction).toHaveBeenCalledWith(
- `/sentry-apps/${sentryApp.slug}/interaction/`,
- expect.objectContaining({
- method: 'POST',
- data: {
- tsdbField: 'sentry_app_viewed',
- },
- })
- );
- });
- it('displays the Integrations description', function () {
- renderMockRequests({sentryAppSlug: sentryApp.slug});
- render(
- <SentryAppDetailsModal
- closeModal={jest.fn()}
- isInstalled={false}
- onInstall={jest.fn()}
- organization={TestStubs.Organization()}
- sentryApp={sentryApp}
- />
- );
- expect(screen.getByText(sentryApp.overview)).toBeInTheDocument();
- });
- it('closes when Cancel is clicked', async function () {
- renderMockRequests({sentryAppSlug: sentryApp.slug});
- const handleCloseModal = jest.fn();
- render(
- <SentryAppDetailsModal
- closeModal={handleCloseModal}
- isInstalled={false}
- onInstall={jest.fn()}
- organization={TestStubs.Organization()}
- sentryApp={sentryApp}
- />
- );
- await userEvent.click(screen.getByText('Cancel'));
- expect(handleCloseModal).toHaveBeenCalled();
- });
- it('installs the Integration when Install is clicked', async function () {
- renderMockRequests({sentryAppSlug: sentryApp.slug});
- const handleOnInstall = jest.fn();
- render(
- <SentryAppDetailsModal
- closeModal={jest.fn()}
- isInstalled={false}
- onInstall={handleOnInstall}
- organization={TestStubs.Organization()}
- sentryApp={sentryApp}
- />
- );
- await userEvent.click(screen.getByRole('button', {name: 'Accept & Install'}));
- expect(handleOnInstall).toHaveBeenCalled();
- });
- it('does not display the Install button, when the User does not have permission to install Integrations', function () {
- renderMockRequests({sentryAppSlug: sentryApp.slug});
- const noAccessOrg = TestStubs.Organization({access: []});
- render(
- <SentryAppDetailsModal
- closeModal={jest.fn()}
- isInstalled={false}
- onInstall={jest.fn()}
- organization={noAccessOrg}
- sentryApp={sentryApp}
- />,
- {organization: noAccessOrg}
- );
- expect(
- screen.queryByRole('button', {name: 'Accept & Install'})
- ).not.toBeInTheDocument();
- });
- it('render the Install button disabled, when the Integration is installed', function () {
- renderMockRequests({sentryAppSlug: sentryApp.slug});
- render(
- <SentryAppDetailsModal
- closeModal={jest.fn()}
- isInstalled
- onInstall={jest.fn()}
- organization={TestStubs.Organization()}
- sentryApp={sentryApp}
- />
- );
- expect(screen.getByRole('button', {name: 'Accept & Install'})).toBeDisabled();
- });
- it('does not render permissions, when the Integration requires no permissions', function () {
- renderMockRequests({sentryAppSlug: sentryApp.slug});
- render(
- <SentryAppDetailsModal
- closeModal={jest.fn()}
- isInstalled={false}
- onInstall={jest.fn()}
- organization={TestStubs.Organization()}
- sentryApp={{...sentryApp, scopes: []}}
- />
- );
- expect(screen.queryByText('Permissions')).not.toBeInTheDocument();
- });
- });
|