sentryAppDetailsModal.spec.jsx 2.9 KB

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