sentryAppDetailsModal.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import SentryAppDetailsModal from 'sentry/components/modals/sentryAppDetailsModal';
  3. describe('SentryAppDetailsModal', function () {
  4. let wrapper;
  5. let org;
  6. let sentryApp;
  7. let onInstall;
  8. let isInstalled;
  9. let closeModal;
  10. const installButton = 'Button[data-test-id="install"]';
  11. let sentryAppInteractionRequest;
  12. function mount() {
  13. return mountWithTheme(
  14. <SentryAppDetailsModal
  15. sentryApp={sentryApp}
  16. organization={org}
  17. onInstall={onInstall}
  18. isInstalled={isInstalled}
  19. closeModal={closeModal}
  20. />
  21. );
  22. }
  23. beforeEach(() => {
  24. org = TestStubs.Organization();
  25. sentryApp = TestStubs.SentryApp();
  26. onInstall = jest.fn();
  27. isInstalled = false;
  28. closeModal = jest.fn();
  29. MockApiClient.addMockResponse({
  30. url: `/sentry-apps/${sentryApp.slug}/features/`,
  31. method: 'GET',
  32. body: [],
  33. });
  34. sentryAppInteractionRequest = MockApiClient.addMockResponse({
  35. url: `/sentry-apps/${sentryApp.slug}/interaction/`,
  36. method: 'POST',
  37. statusCode: 200,
  38. body: {},
  39. });
  40. wrapper = mount();
  41. });
  42. it('renders', () => {
  43. expect(wrapper.find('Name').text()).toBe(sentryApp.name);
  44. });
  45. it('records interaction request', () => {
  46. expect(sentryAppInteractionRequest).toHaveBeenCalledWith(
  47. `/sentry-apps/${sentryApp.slug}/interaction/`,
  48. expect.objectContaining({
  49. method: 'POST',
  50. data: {
  51. tsdbField: 'sentry_app_viewed',
  52. },
  53. })
  54. );
  55. });
  56. it('displays the Integrations description', () => {
  57. expect(wrapper.find('Description').text()).toContain(sentryApp.overview);
  58. });
  59. it('closes when Cancel is clicked', () => {
  60. wrapper.find({onClick: closeModal}).first().simulate('click');
  61. expect(closeModal).toHaveBeenCalled();
  62. });
  63. it('installs the Integration when Install is clicked', () => {
  64. wrapper.find(installButton).simulate('click');
  65. expect(onInstall).toHaveBeenCalled();
  66. });
  67. describe('when the User does not have permission to install Integrations', () => {
  68. beforeEach(() => {
  69. org = {...org, access: []};
  70. wrapper = mount();
  71. });
  72. it('does not display the Install button', () => {
  73. expect(wrapper.find(installButton).length).toBe(0);
  74. });
  75. });
  76. describe('when the Integration is installed', () => {
  77. beforeEach(() => {
  78. isInstalled = true;
  79. wrapper = mount();
  80. });
  81. it('disabled the Install button', () => {
  82. expect(wrapper.find(installButton).prop('disabled')).toBe(true);
  83. });
  84. });
  85. describe('when the Integration requires no permissions', () => {
  86. beforeEach(() => {
  87. sentryApp = {...sentryApp, scopes: []};
  88. wrapper = mount();
  89. });
  90. it('does not render permissions', () => {
  91. expect(wrapper.exists('Title')).toBe(false);
  92. });
  93. });
  94. });