eventCustomPerformanceMetrics.spec.tsx 3.8 KB

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