eventVitals.spec.jsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import EventVitals from 'sentry/components/events/eventVitals';
  3. function makeEvent(measurements = {}, sdk = {version: '5.27.3'}) {
  4. const formattedMeasurements = {};
  5. for (const [name, value] of Object.entries(measurements)) {
  6. formattedMeasurements[name] = {value};
  7. }
  8. const event = {measurements: formattedMeasurements};
  9. if (sdk !== null) {
  10. event.sdk = sdk;
  11. }
  12. return event;
  13. }
  14. describe('EventVitals', function () {
  15. it('should not render anything', function () {
  16. const event = makeEvent({});
  17. const wrapper = mountWithTheme(<EventVitals event={event} />);
  18. expect(wrapper.isEmptyRender()).toBe(true);
  19. });
  20. it('should not render non web vitals', function () {
  21. const event = makeEvent({
  22. 'mark.stuff': 123,
  23. 'op.more.stuff': 123,
  24. });
  25. const wrapper = mountWithTheme(<EventVitals event={event} />);
  26. expect(wrapper.isEmptyRender()).toBe(true);
  27. });
  28. it('should render some web vitals with a header', function () {
  29. const event = makeEvent({
  30. fp: 1,
  31. fcp: 2,
  32. lcp: 3,
  33. fid: 4,
  34. cls: 0.1,
  35. ttfb: 5,
  36. 'ttfb.requesttime': 6,
  37. });
  38. const wrapper = mountWithTheme(<EventVitals event={event} />);
  39. expect(wrapper.find('SectionHeading').text()).toEqual('Web Vitals');
  40. expect(wrapper.find('WarningIconContainer').exists()).toBe(false);
  41. expect(wrapper.find('EventVital')).toHaveLength(7);
  42. });
  43. it('should render some web vitals with a heading and a sdk warning', function () {
  44. const event = makeEvent({fp: 1}, {version: '5.26.0'});
  45. const wrapper = mountWithTheme(<EventVitals event={event} />);
  46. expect(wrapper.find('SectionHeading').text()).toEqual('Web Vitals');
  47. expect(wrapper.find('WarningIconContainer').exists()).toBe(true);
  48. expect(wrapper.find('EventVital')).toHaveLength(1);
  49. });
  50. it('should show fire icon if vital failed threshold', function () {
  51. const event = makeEvent({
  52. fp: 5000,
  53. fcp: 5000,
  54. lcp: 5000,
  55. fid: 4,
  56. cls: 0.1,
  57. ttfb: 5,
  58. 'ttfb.requesttime': 6,
  59. });
  60. const wrapper = mountWithTheme(<EventVitals event={event} />);
  61. expect(wrapper.find('SectionHeading').text()).toEqual('Web Vitals');
  62. expect(wrapper.find('EventVital')).toHaveLength(7);
  63. expect(wrapper.find('IconFire')).toHaveLength(3);
  64. });
  65. });