eventCustomPerformanceMetrics.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {browserHistory} from 'react-router';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import EventCustomPerformanceMetrics from 'sentry/components/events/eventCustomPerformanceMetrics';
  5. import {Event} from 'sentry/types/event';
  6. describe('EventCustomPerformanceMetrics', function () {
  7. beforeEach(function () {
  8. browserHistory.push = jest.fn();
  9. });
  10. it('should not render anything', function () {
  11. const {router, organization} = initializeOrg();
  12. render(
  13. <EventCustomPerformanceMetrics
  14. location={router.location}
  15. organization={organization}
  16. event={{} as Event}
  17. />
  18. );
  19. expect(screen.queryByText('Custom Performance Metrics')).not.toBeInTheDocument();
  20. });
  21. it('should not render non custom performance metrics', function () {
  22. const {router, organization} = initializeOrg();
  23. const event = TestStubs.Event({
  24. measurements: {lcp: {value: 10, unit: 'millisecond'}},
  25. });
  26. render(
  27. <EventCustomPerformanceMetrics
  28. location={router.location}
  29. organization={organization}
  30. event={event}
  31. />
  32. );
  33. expect(screen.queryByText('Custom Performance Metrics')).not.toBeInTheDocument();
  34. expect(screen.queryByText('Largest Contentful Paint')).not.toBeInTheDocument();
  35. });
  36. it('should render custom performance metrics', function () {
  37. const {router, organization} = initializeOrg();
  38. const event = TestStubs.Event({
  39. measurements: {
  40. 'custom.count': {unit: 'none', value: 10},
  41. 'custom.duration': {unit: 'millisecond', value: 123},
  42. 'custom.size': {unit: 'kibibyte', value: 456},
  43. 'custom.percentage': {unit: 'ratio', value: 0.3},
  44. lcp: {value: 10, unit: 'millisecond'},
  45. },
  46. });
  47. render(
  48. <EventCustomPerformanceMetrics
  49. location={router.location}
  50. organization={organization}
  51. event={event}
  52. />
  53. );
  54. screen.getByText('Custom Performance Metrics');
  55. screen.getByText('custom.count');
  56. screen.getByText('custom.duration');
  57. screen.getByText('custom.size');
  58. screen.getByText('custom.percentage');
  59. screen.getByText('10');
  60. screen.getByText('123.00ms');
  61. screen.getByText('456.0 KiB');
  62. screen.getByText('30%');
  63. expect(screen.queryByText('Largest Contentful Paint')).not.toBeInTheDocument();
  64. });
  65. it('should render custom performance metrics context menu', async function () {
  66. const {router, organization} = initializeOrg();
  67. const event = TestStubs.Event({
  68. measurements: {
  69. 'custom.size': {unit: 'kibibyte', value: 456},
  70. },
  71. });
  72. render(
  73. <EventCustomPerformanceMetrics
  74. location={router.location}
  75. organization={organization}
  76. event={event}
  77. />
  78. );
  79. expect(screen.getByLabelText('Widget actions')).toBeInTheDocument();
  80. await userEvent.click(screen.getByLabelText('Widget actions'));
  81. expect(screen.getByText('Show events with this value')).toBeInTheDocument();
  82. expect(screen.getByText('Hide events with this value')).toBeInTheDocument();
  83. expect(screen.getByText('Show events with values greater than')).toBeInTheDocument();
  84. expect(screen.getByText('Show events with values less than')).toBeInTheDocument();
  85. });
  86. it('should render custom performance metrics custom unit', function () {
  87. const {router, organization} = initializeOrg();
  88. const event = TestStubs.Event({
  89. measurements: {
  90. 'custom.unit': {unit: 'customunit', value: 456},
  91. },
  92. });
  93. render(
  94. <EventCustomPerformanceMetrics
  95. location={router.location}
  96. organization={organization}
  97. event={event}
  98. />
  99. );
  100. expect(screen.getByText('456 customunit')).toBeInTheDocument();
  101. });
  102. });