projectPerformance.spec.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import ProjectPerformance from 'sentry/views/settings/projectPerformance/projectPerformance';
  3. describe('projectPerformance', function () {
  4. const org = TestStubs.Organization({
  5. features: ['performance-view', 'performance-issues-dev'],
  6. });
  7. const project = TestStubs.ProjectDetails();
  8. const configUrl = '/projects/org-slug/project-slug/transaction-threshold/configure/';
  9. let getMock, postMock, deleteMock, performanceIssuesMock;
  10. beforeEach(function () {
  11. MockApiClient.clearMockResponses();
  12. getMock = MockApiClient.addMockResponse({
  13. url: configUrl,
  14. method: 'GET',
  15. body: {
  16. id: project.id,
  17. threshold: '300',
  18. metric: 'duration',
  19. },
  20. statusCode: 200,
  21. });
  22. postMock = MockApiClient.addMockResponse({
  23. url: configUrl,
  24. method: 'POST',
  25. body: {
  26. id: project.id,
  27. threshold: '400',
  28. metric: 'lcp',
  29. },
  30. statusCode: 200,
  31. });
  32. deleteMock = MockApiClient.addMockResponse({
  33. url: configUrl,
  34. method: 'DELETE',
  35. statusCode: 200,
  36. });
  37. MockApiClient.addMockResponse({
  38. url: '/projects/org-slug/project-slug/',
  39. method: 'GET',
  40. body: {},
  41. statusCode: 200,
  42. });
  43. performanceIssuesMock = MockApiClient.addMockResponse({
  44. url: '/projects/org-slug/project-slug/performance-issues/configure/',
  45. method: 'GET',
  46. body: {},
  47. statusCode: 200,
  48. });
  49. });
  50. it('renders the fields', async function () {
  51. const wrapper = mountWithTheme(
  52. <ProjectPerformance
  53. params={{orgId: org.slug, projectId: project.slug}}
  54. organization={org}
  55. project={project}
  56. />
  57. );
  58. await tick();
  59. expect(wrapper.find('input[name="threshold"]').prop('value')).toBe('300');
  60. expect(wrapper.find('input[name="metric"]').prop('value')).toBe('duration');
  61. expect(getMock).toHaveBeenCalledTimes(1);
  62. });
  63. it('updates the field', async function () {
  64. const wrapper = mountWithTheme(
  65. <ProjectPerformance
  66. params={{orgId: org.slug, projectId: project.slug}}
  67. organization={org}
  68. project={project}
  69. />
  70. );
  71. await tick();
  72. wrapper
  73. .find('input[name="threshold"]')
  74. .simulate('change', {target: {value: '400'}})
  75. .simulate('blur');
  76. await tick();
  77. expect(postMock).toHaveBeenCalledWith(
  78. configUrl,
  79. expect.objectContaining({
  80. data: {threshold: '400'},
  81. })
  82. );
  83. expect(wrapper.find('input[name="threshold"]').prop('value')).toBe('400');
  84. });
  85. it('clears the data', async function () {
  86. const wrapper = mountWithTheme(
  87. <ProjectPerformance
  88. params={{orgId: org.slug, projectId: project.slug}}
  89. organization={org}
  90. project={project}
  91. />
  92. );
  93. await tick();
  94. wrapper.find('Actions').find('Button').simulate('click');
  95. await tick();
  96. expect(deleteMock).toHaveBeenCalled();
  97. });
  98. it('does not get performance issues settings without the feature flag', async function () {
  99. const org_without_perf_issues = TestStubs.Organization({
  100. features: ['performance-view'],
  101. });
  102. mountWithTheme(
  103. <ProjectPerformance
  104. params={{orgId: org.slug, projectId: project.slug}}
  105. organization={org_without_perf_issues}
  106. project={project}
  107. />
  108. );
  109. await tick();
  110. expect(performanceIssuesMock).not.toHaveBeenCalled();
  111. });
  112. });