sentryAppDetailsModal.spec.tsx 4.6 KB

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