sentryAppExternalIssueForm.spec.jsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import React from 'react';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {Client} from 'app/api';
  4. import {addQueryParamsToExistingUrl} from 'app/utils/queryString';
  5. import SentryAppExternalIssueForm from 'app/components/group/sentryAppExternalIssueForm';
  6. describe('SentryAppExternalIssueForm', () => {
  7. let wrapper;
  8. let group;
  9. let sentryApp;
  10. let sentryAppInstallation;
  11. let component;
  12. beforeEach(() => {
  13. group = TestStubs.Group({
  14. title: 'ApiError: Broken',
  15. shortId: 'SEN123',
  16. permalink: 'https://sentry.io/organizations/sentry/issues/123/?project=1',
  17. });
  18. component = TestStubs.SentryAppComponent();
  19. sentryApp = TestStubs.SentryApp();
  20. sentryAppInstallation = TestStubs.SentryAppInstallation({sentryApp});
  21. });
  22. describe('create', () => {
  23. beforeEach(() => {
  24. wrapper = mountWithTheme(
  25. <SentryAppExternalIssueForm
  26. group={group}
  27. sentryAppInstallation={sentryAppInstallation}
  28. config={component.schema}
  29. action="create"
  30. api={new Client()}
  31. />,
  32. TestStubs.routerContext()
  33. );
  34. });
  35. it('specifies the action', () => {
  36. expect(wrapper.find('HiddenField[name="action"]').prop('value')).toEqual('create');
  37. });
  38. it('specifies the group', () => {
  39. expect(wrapper.find('HiddenField[name="groupId"]').prop('value')).toEqual(group.id);
  40. });
  41. it('specifies the uri', () => {
  42. expect(wrapper.find('HiddenField[name="uri"]').prop('value')).toEqual(
  43. component.schema.create.uri
  44. );
  45. });
  46. it('renders each required_fields field', () => {
  47. component.schema.create.required_fields.forEach(field => {
  48. expect(wrapper.exists(`#${field.name}`)).toBe(true);
  49. });
  50. });
  51. it('submits to the New External Issue endpoint', () => {
  52. const url = `/sentry-app-installations/${
  53. sentryAppInstallation.uuid
  54. }/external-issues/`;
  55. expect(wrapper.find('Form').prop('apiEndpoint')).toEqual(url);
  56. expect(wrapper.find('Form').prop('apiMethod')).toEqual('POST');
  57. });
  58. it('renders prepopulated defaults', () => {
  59. const titleField = wrapper.find('Input#title');
  60. const descriptionField = wrapper.find('TextArea#description');
  61. const url = addQueryParamsToExistingUrl(group.permalink, {
  62. referrer: sentryApp.name,
  63. });
  64. expect(titleField.prop('value')).toEqual(`${group.title}`);
  65. expect(descriptionField.prop('value')).toEqual(
  66. `Sentry Issue: [${group.shortId}](${url})`
  67. );
  68. });
  69. });
  70. describe('link', () => {
  71. beforeEach(() => {
  72. wrapper = mountWithTheme(
  73. <SentryAppExternalIssueForm
  74. group={group}
  75. sentryAppInstallation={sentryAppInstallation}
  76. config={component.schema}
  77. action="link"
  78. api={new Client()}
  79. />,
  80. TestStubs.routerContext()
  81. );
  82. });
  83. it('specifies the action', () => {
  84. expect(wrapper.find('HiddenField[name="action"]').prop('value')).toEqual('link');
  85. });
  86. it('specifies the group', () => {
  87. expect(wrapper.find('HiddenField[name="groupId"]').prop('value')).toEqual(group.id);
  88. });
  89. it('specifies the uri', () => {
  90. expect(wrapper.find('HiddenField[name="uri"]').prop('value')).toEqual(
  91. component.schema.link.uri
  92. );
  93. });
  94. it('renders each required_fields field', () => {
  95. component.schema.link.required_fields.forEach(field => {
  96. expect(wrapper.exists(`#${field.name}`)).toBe(true);
  97. });
  98. });
  99. it('submits to the New External Issue endpoint', () => {
  100. const url = `/sentry-app-installations/${
  101. sentryAppInstallation.uuid
  102. }/external-issues/`;
  103. expect(wrapper.find('Form').prop('apiEndpoint')).toEqual(url);
  104. expect(wrapper.find('Form').prop('apiMethod')).toEqual('POST');
  105. });
  106. });
  107. });
  108. describe('SentryAppExternalIssueForm Async Field', () => {
  109. let wrapper;
  110. let group;
  111. let sentryApp;
  112. let sentryAppInstallation;
  113. const component = {
  114. uuid: 'ed517da4-a324-44c0-aeea-1894cd9923fb',
  115. type: 'issue-link',
  116. schema: {
  117. create: {
  118. required_fields: [
  119. {
  120. type: 'select',
  121. name: 'numbers',
  122. label: 'Numbers',
  123. uri: '/sentry/numbers',
  124. url: '/sentry/numbers',
  125. async: true,
  126. },
  127. ],
  128. },
  129. link: {
  130. required_fields: [
  131. {
  132. type: 'text',
  133. name: 'issue',
  134. label: 'Issue',
  135. },
  136. ],
  137. },
  138. },
  139. sentryApp: {
  140. uuid: 'b468fed3-afba-4917-80d6-bdac99c1ec05',
  141. slug: 'foo',
  142. name: 'Foo',
  143. },
  144. };
  145. beforeEach(() => {
  146. group = TestStubs.Group({
  147. title: 'ApiError: Broken',
  148. shortId: 'SEN123',
  149. permalink: 'https://sentry.io/organizations/sentry/issues/123/?project=1',
  150. });
  151. sentryApp = TestStubs.SentryApp();
  152. sentryAppInstallation = TestStubs.SentryAppInstallation({sentryApp});
  153. });
  154. afterEach(() => {
  155. Client.clearMockResponses();
  156. });
  157. describe('renders', () => {
  158. it('renders each required_fields field', async function() {
  159. Client.addMockResponse({
  160. method: 'GET',
  161. url:
  162. '/sentry-app-installations/d950595e-cba2-46f6-8a94-b79e42806f98/external-requests/',
  163. body: {
  164. choices: [[1, 'Issue 1'], [2, 'Issue 2']],
  165. },
  166. });
  167. wrapper = mountWithTheme(
  168. <SentryAppExternalIssueForm
  169. group={group}
  170. sentryAppInstallation={sentryAppInstallation}
  171. config={component.schema}
  172. action="create"
  173. api={new Client()}
  174. />,
  175. TestStubs.routerContext()
  176. );
  177. wrapper.find('input#numbers').simulate('change', {target: {value: 'I'}});
  178. await tick();
  179. wrapper.update();
  180. const optionLabelSelector = label => {
  181. return `[aria-label="${label}"]`;
  182. };
  183. expect(wrapper.find(optionLabelSelector('Issue 1')).exists()).toBe(true);
  184. expect(wrapper.find(optionLabelSelector('Issue 2')).exists()).toBe(true);
  185. });
  186. });
  187. });