123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- import {RouteComponentPropsFixture} from 'sentry-fixture/routeComponentPropsFixture';
- import {SentryAppFixture} from 'sentry-fixture/sentryApp';
- import {SentryAppWebhookRequestFixture} from 'sentry-fixture/sentryAppWebhookRequest';
- import {render, screen, within} from 'sentry-test/reactTestingLibrary';
- import SentryApplicationDashboard from './index';
- jest.mock('sentry/components/charts/baseChart', () => {
- return jest.fn().mockImplementation(() => <div data-test-id="chart" />);
- });
- describe('Sentry Application Dashboard', function () {
- const NUM_INSTALLS = 5;
- const NUM_UNINSTALLS = 2;
- let sentryApp;
- let webhookRequest;
- afterEach(() => {
- MockApiClient.clearMockResponses();
- });
- describe('Viewing the Sentry App Dashboard for a published integration', () => {
- beforeEach(() => {
- sentryApp = SentryAppFixture({
- status: 'published',
- schema: {
- elements: [
- {type: 'stacktrace-link', uri: '/test', url: '/test'},
- {
- type: 'issue-link',
- create: {uri: '/test', required_fields: []},
- link: {uri: '/test', required_fields: []},
- },
- ],
- },
- });
- webhookRequest = SentryAppWebhookRequestFixture();
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/stats/`,
- body: {
- totalInstalls: NUM_INSTALLS,
- totalUninstalls: NUM_UNINSTALLS,
- installStats: [[1569783600, NUM_INSTALLS]],
- uninstallStats: [[1569783600, NUM_UNINSTALLS]],
- },
- });
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/requests/`,
- body: [webhookRequest],
- });
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/interaction/`,
- body: {
- componentInteractions: {
- 'stacktrace-link': [[1569783600, 1]],
- 'issue-link': [[1569783600, 1]],
- },
- views: [[1569783600, 1]],
- },
- });
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/`,
- body: sentryApp,
- });
- });
- it('shows the total install/uninstall stats', async () => {
- render(
- <SentryApplicationDashboard
- {...RouteComponentPropsFixture()}
- params={{appSlug: sentryApp.slug}}
- />
- );
- expect(await screen.findByTestId('installs')).toHaveTextContent('Total installs5');
- expect(screen.getByTestId('uninstalls')).toHaveTextContent('Total uninstalls2');
- });
- it('shows the request log', async () => {
- render(
- <SentryApplicationDashboard
- {...RouteComponentPropsFixture()}
- params={{appSlug: sentryApp.slug}}
- />
- );
- // The mock response has 1 request
- expect(await screen.findByTestId('request-item')).toBeInTheDocument();
- const requestLog = within(screen.getByTestId('request-item'));
- // Make sure that all the info is displayed
- expect(requestLog.getByText('https://example.com/webhook')).toBeInTheDocument();
- expect(requestLog.getByText('400')).toBeInTheDocument();
- expect(requestLog.getByText('issue.assigned')).toBeInTheDocument();
- expect(requestLog.getByText('Test Org')).toBeInTheDocument();
- });
- it('shows an empty message if there are no requests', async () => {
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/requests/`,
- body: [],
- });
- render(
- <SentryApplicationDashboard
- {...RouteComponentPropsFixture()}
- params={{appSlug: sentryApp.slug}}
- />
- );
- expect(
- await screen.findByText('No requests found in the last 30 days.')
- ).toBeInTheDocument();
- });
- it('shows integration and interactions chart', async () => {
- render(
- <SentryApplicationDashboard
- {...RouteComponentPropsFixture()}
- params={{appSlug: sentryApp.slug}}
- />
- );
- expect(await screen.findAllByTestId('chart')).toHaveLength(3);
- });
- });
- describe('Viewing the Sentry App Dashboard for an internal integration', () => {
- beforeEach(() => {
- sentryApp = SentryAppFixture({
- status: 'internal',
- schema: {
- elements: [{type: 'stacktrace-link', uri: '/test', url: '/test'}],
- },
- });
- webhookRequest = SentryAppWebhookRequestFixture();
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/stats/`,
- body: {
- totalInstalls: 1,
- totalUninstalls: 0,
- installStats: [[1569783600, 1]],
- uninstallStats: [[1569783600, 0]],
- },
- });
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/requests/`,
- body: [webhookRequest],
- });
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/interaction/`,
- body: {
- componentInteractions: {
- 'stacktrace-link': [[1569783600, 1]],
- },
- views: [[1569783600, 1]],
- },
- });
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/`,
- body: sentryApp,
- });
- });
- it('shows the request log', async () => {
- render(
- <SentryApplicationDashboard
- {...RouteComponentPropsFixture()}
- params={{appSlug: sentryApp.slug}}
- />
- );
- // The mock response has 1 request
- expect(await screen.findByTestId('request-item')).toBeInTheDocument();
- const requestLog = within(screen.getByTestId('request-item'));
- // Make sure that all the info is displayed
- expect(requestLog.getByText('https://example.com/webhook')).toBeInTheDocument();
- expect(requestLog.getByText('400')).toBeInTheDocument();
- expect(requestLog.getByText('issue.assigned')).toBeInTheDocument();
- // Does not show the integration views
- expect(screen.queryByText('Integration Views')).not.toBeInTheDocument();
- });
- it('shows an empty message if there are no requests', async () => {
- MockApiClient.addMockResponse({
- url: `/sentry-apps/${sentryApp.slug}/requests/`,
- body: [],
- });
- render(
- <SentryApplicationDashboard
- {...RouteComponentPropsFixture()}
- params={{appSlug: sentryApp.slug}}
- />
- );
- expect(
- await screen.findByText('No requests found in the last 30 days.')
- ).toBeInTheDocument();
- });
- it('shows the component interactions in a line chart', async () => {
- render(
- <SentryApplicationDashboard
- {...RouteComponentPropsFixture()}
- params={{appSlug: sentryApp.slug}}
- />
- );
- expect(await screen.findByTestId('chart')).toBeInTheDocument();
- });
- });
- });
|