projectPerformance.spec.jsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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({features: ['performance-view']});
  5. const project = TestStubs.ProjectDetails();
  6. const configUrl = '/projects/org-slug/project-slug/transaction-threshold/configure/';
  7. let getMock, postMock, deleteMock;
  8. beforeEach(function () {
  9. MockApiClient.clearMockResponses();
  10. getMock = MockApiClient.addMockResponse({
  11. url: configUrl,
  12. method: 'GET',
  13. body: {
  14. id: project.id,
  15. threshold: '300',
  16. metric: 'duration',
  17. },
  18. statusCode: 200,
  19. });
  20. postMock = MockApiClient.addMockResponse({
  21. url: configUrl,
  22. method: 'POST',
  23. body: {
  24. id: project.id,
  25. threshold: '400',
  26. metric: 'lcp',
  27. },
  28. statusCode: 200,
  29. });
  30. deleteMock = MockApiClient.addMockResponse({
  31. url: configUrl,
  32. method: 'DELETE',
  33. statusCode: 200,
  34. });
  35. });
  36. it('renders the fields', async function () {
  37. const wrapper = mountWithTheme(
  38. <ProjectPerformance
  39. params={{orgId: org.slug, projectId: project.slug}}
  40. organization={org}
  41. project={project}
  42. />
  43. );
  44. await tick();
  45. expect(wrapper.find('input[name="threshold"]').prop('value')).toBe('300');
  46. expect(wrapper.find('input[name="metric"]').prop('value')).toBe('duration');
  47. expect(getMock).toHaveBeenCalledTimes(1);
  48. });
  49. it('updates the field', async function () {
  50. const wrapper = mountWithTheme(
  51. <ProjectPerformance
  52. params={{orgId: org.slug, projectId: project.slug}}
  53. organization={org}
  54. project={project}
  55. />
  56. );
  57. await tick();
  58. wrapper
  59. .find('input[name="threshold"]')
  60. .simulate('change', {target: {value: '400'}})
  61. .simulate('blur');
  62. await tick();
  63. expect(postMock).toHaveBeenCalledWith(
  64. configUrl,
  65. expect.objectContaining({
  66. data: {threshold: '400'},
  67. })
  68. );
  69. expect(wrapper.find('input[name="threshold"]').prop('value')).toBe('400');
  70. });
  71. it('clears the data', async function () {
  72. const wrapper = mountWithTheme(
  73. <ProjectPerformance
  74. params={{orgId: org.slug, projectId: project.slug}}
  75. organization={org}
  76. project={project}
  77. />
  78. );
  79. await tick();
  80. wrapper.find('Actions').find('Button').simulate('click');
  81. await tick();
  82. expect(deleteMock).toHaveBeenCalled();
  83. });
  84. });