applyStaticWeightsToTimeseries.spec.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {applyStaticWeightsToTimeseries} from 'sentry/views/insights/browser/webVitals/utils/applyStaticWeightsToTimeseries';
  2. describe('applyStaticWeightsToTimeseries', function () {
  3. it('updates timeseries scores with static weighing', function () {
  4. const timeseriesData = {
  5. lcp: [],
  6. fcp: [],
  7. cls: [],
  8. ttfb: [],
  9. inp: [],
  10. unweightedLcp: [
  11. {name: '2024-07-01T00:00:00.000Z', value: 90},
  12. {name: '2024-07-02T00:00:00.000Z', value: 40},
  13. ],
  14. unweightedFcp: [
  15. {name: '2024-07-01T00:00:00.000Z', value: 30},
  16. {name: '2024-07-02T00:00:00.000Z', value: 20},
  17. ],
  18. unweightedCls: [
  19. {name: '2024-07-01T00:00:00.000Z', value: 10},
  20. {name: '2024-07-02T00:00:00.000Z', value: 90},
  21. ],
  22. unweightedTtfb: [
  23. {name: '2024-07-01T00:00:00.000Z', value: 22},
  24. {name: '2024-07-02T00:00:00.000Z', value: 43},
  25. ],
  26. unweightedInp: [
  27. {name: '2024-07-01T00:00:00.000Z', value: 100},
  28. {name: '2024-07-02T00:00:00.000Z', value: 0},
  29. ],
  30. total: [
  31. {name: '2024-07-01T00:00:00.000Z', value: 50},
  32. {name: '2024-07-02T00:00:00.000Z', value: 50},
  33. ],
  34. };
  35. const result = applyStaticWeightsToTimeseries(timeseriesData);
  36. expect(result).toEqual({
  37. lcp: [
  38. {name: '2024-07-01T00:00:00.000Z', value: 90 * 0.3},
  39. {name: '2024-07-02T00:00:00.000Z', value: 40 * 0.3},
  40. ],
  41. fcp: [
  42. {name: '2024-07-01T00:00:00.000Z', value: 30 * 0.15},
  43. {name: '2024-07-02T00:00:00.000Z', value: 20 * 0.15},
  44. ],
  45. cls: [
  46. {name: '2024-07-01T00:00:00.000Z', value: 10 * 0.15},
  47. {name: '2024-07-02T00:00:00.000Z', value: 90 * 0.15},
  48. ],
  49. ttfb: [
  50. {name: '2024-07-01T00:00:00.000Z', value: 22 * 0.1},
  51. {name: '2024-07-02T00:00:00.000Z', value: 43 * 0.1},
  52. ],
  53. inp: [
  54. {name: '2024-07-01T00:00:00.000Z', value: 100 * 0.3},
  55. {name: '2024-07-02T00:00:00.000Z', value: 0 * 0.3},
  56. ],
  57. total: [
  58. {name: '2024-07-01T00:00:00.000Z', value: 50},
  59. {name: '2024-07-02T00:00:00.000Z', value: 50},
  60. ],
  61. });
  62. });
  63. });