sentryAppDetailsModal.spec.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {SentryAppFixture} from 'sentry-fixture/sentryApp';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import SentryAppDetailsModal from 'sentry/components/modals/sentryAppDetailsModal';
  5. function renderMockRequests({sentryAppSlug}: {sentryAppSlug: string}) {
  6. const features = MockApiClient.addMockResponse({
  7. url: `/sentry-apps/${sentryAppSlug}/features/`,
  8. method: 'GET',
  9. body: [],
  10. });
  11. const interaction = MockApiClient.addMockResponse({
  12. url: `/sentry-apps/${sentryAppSlug}/interaction/`,
  13. method: 'POST',
  14. statusCode: 200,
  15. body: {},
  16. });
  17. return {features, interaction};
  18. }
  19. describe('SentryAppDetailsModal', function () {
  20. const sentryApp = SentryAppFixture();
  21. it('renders', function () {
  22. renderMockRequests({sentryAppSlug: sentryApp.slug});
  23. render(
  24. <SentryAppDetailsModal
  25. closeModal={jest.fn()}
  26. isInstalled={false}
  27. onInstall={jest.fn()}
  28. organization={OrganizationFixture()}
  29. sentryApp={sentryApp}
  30. />
  31. );
  32. expect(screen.getByText(sentryApp.name)).toBeInTheDocument();
  33. });
  34. it('records interaction request', function () {
  35. const mockRequests = renderMockRequests({sentryAppSlug: sentryApp.slug});
  36. render(
  37. <SentryAppDetailsModal
  38. closeModal={jest.fn()}
  39. isInstalled={false}
  40. onInstall={jest.fn()}
  41. organization={OrganizationFixture()}
  42. sentryApp={sentryApp}
  43. />
  44. );
  45. expect(mockRequests.interaction).toHaveBeenCalledWith(
  46. `/sentry-apps/${sentryApp.slug}/interaction/`,
  47. expect.objectContaining({
  48. method: 'POST',
  49. data: {
  50. tsdbField: 'sentry_app_viewed',
  51. },
  52. })
  53. );
  54. });
  55. it('displays the Integrations description', function () {
  56. renderMockRequests({sentryAppSlug: sentryApp.slug});
  57. render(
  58. <SentryAppDetailsModal
  59. closeModal={jest.fn()}
  60. isInstalled={false}
  61. onInstall={jest.fn()}
  62. organization={OrganizationFixture()}
  63. sentryApp={sentryApp}
  64. />
  65. );
  66. expect(screen.getByText(String(sentryApp.overview))).toBeInTheDocument();
  67. });
  68. it('closes when Cancel is clicked', async function () {
  69. renderMockRequests({sentryAppSlug: sentryApp.slug});
  70. const handleCloseModal = jest.fn();
  71. render(
  72. <SentryAppDetailsModal
  73. closeModal={handleCloseModal}
  74. isInstalled={false}
  75. onInstall={jest.fn()}
  76. organization={OrganizationFixture()}
  77. sentryApp={sentryApp}
  78. />
  79. );
  80. await userEvent.click(screen.getByText('Cancel'));
  81. expect(handleCloseModal).toHaveBeenCalled();
  82. });
  83. it('installs the Integration when Install is clicked', async function () {
  84. renderMockRequests({sentryAppSlug: sentryApp.slug});
  85. const handleOnInstall = jest.fn();
  86. render(
  87. <SentryAppDetailsModal
  88. closeModal={jest.fn()}
  89. isInstalled={false}
  90. onInstall={handleOnInstall}
  91. organization={OrganizationFixture()}
  92. sentryApp={sentryApp}
  93. />
  94. );
  95. await userEvent.click(screen.getByRole('button', {name: 'Accept & Install'}));
  96. expect(handleOnInstall).toHaveBeenCalled();
  97. });
  98. it('does not display the Install button, when the User does not have permission to install Integrations', function () {
  99. renderMockRequests({sentryAppSlug: sentryApp.slug});
  100. const noAccessOrg = OrganizationFixture({access: []});
  101. render(
  102. <SentryAppDetailsModal
  103. closeModal={jest.fn()}
  104. isInstalled={false}
  105. onInstall={jest.fn()}
  106. organization={noAccessOrg}
  107. sentryApp={sentryApp}
  108. />,
  109. {organization: noAccessOrg}
  110. );
  111. expect(
  112. screen.queryByRole('button', {name: 'Accept & Install'})
  113. ).not.toBeInTheDocument();
  114. });
  115. it('render the Install button disabled, when the Integration is installed', function () {
  116. renderMockRequests({sentryAppSlug: sentryApp.slug});
  117. render(
  118. <SentryAppDetailsModal
  119. closeModal={jest.fn()}
  120. isInstalled
  121. onInstall={jest.fn()}
  122. organization={OrganizationFixture()}
  123. sentryApp={sentryApp}
  124. />
  125. );
  126. expect(screen.getByRole('button', {name: 'Accept & Install'})).toBeDisabled();
  127. });
  128. it('does not render permissions, when the Integration requires no permissions', function () {
  129. renderMockRequests({sentryAppSlug: sentryApp.slug});
  130. render(
  131. <SentryAppDetailsModal
  132. closeModal={jest.fn()}
  133. isInstalled={false}
  134. onInstall={jest.fn()}
  135. organization={OrganizationFixture()}
  136. sentryApp={{...sentryApp, scopes: []}}
  137. />
  138. );
  139. expect(screen.queryByText('Permissions')).not.toBeInTheDocument();
  140. });
  141. });