projectPerformance.spec.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  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', function () {
  51. render(
  52. <ProjectPerformance
  53. params={{orgId: org.slug, projectId: project.slug}}
  54. organization={org}
  55. project={project}
  56. />
  57. );
  58. expect(
  59. screen.getByRole('textbox', {name: 'Response Time Threshold (ms)'})
  60. ).toHaveValue('300');
  61. expect(getMock).toHaveBeenCalledTimes(1);
  62. });
  63. it('updates the field', async function () {
  64. render(
  65. <ProjectPerformance
  66. params={{orgId: org.slug, projectId: project.slug}}
  67. organization={org}
  68. project={project}
  69. />
  70. );
  71. const input = screen.getByRole('textbox', {name: 'Response Time Threshold (ms)'});
  72. await userEvent.clear(input);
  73. await userEvent.type(input, '400');
  74. await userEvent.tab();
  75. expect(postMock).toHaveBeenCalledWith(
  76. configUrl,
  77. expect.objectContaining({
  78. data: {threshold: '400'},
  79. })
  80. );
  81. expect(input).toHaveValue('400');
  82. });
  83. it('clears the data', async function () {
  84. render(
  85. <ProjectPerformance
  86. params={{orgId: org.slug, projectId: project.slug}}
  87. organization={org}
  88. project={project}
  89. />
  90. );
  91. await userEvent.click(screen.getByRole('button', {name: 'Reset All'}));
  92. expect(deleteMock).toHaveBeenCalled();
  93. });
  94. it('does not get performance issues settings without the feature flag', function () {
  95. const orgWithoutPerfIssues = TestStubs.Organization({
  96. features: ['performance-view'],
  97. });
  98. render(
  99. <ProjectPerformance
  100. params={{orgId: org.slug, projectId: project.slug}}
  101. organization={orgWithoutPerfIssues}
  102. project={project}
  103. />
  104. );
  105. expect(performanceIssuesMock).not.toHaveBeenCalled();
  106. });
  107. });