utils.spec.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {
  2. getColdAppStartPerformance,
  3. getWarmAppStartPerformance,
  4. type MetricValue,
  5. PerformanceScore,
  6. } from 'sentry/views/insights/mobile/screens/utils';
  7. import {VitalState} from 'sentry/views/performance/vitalDetail/utils';
  8. jest.mock('sentry/utils/usePageFilters');
  9. jest.mock('sentry/utils/useLocation');
  10. describe('Utils', function () {
  11. describe('Cold App Start', function () {
  12. it('renders bad', function () {
  13. const value: MetricValue = {unit: 'millisecond', value: 10000, type: 'duration'};
  14. const performance = getColdAppStartPerformance(value);
  15. expect(performance.score).toBe(PerformanceScore.BAD);
  16. expect(performance.description).toBe(VitalState.POOR);
  17. });
  18. it('renders meh', function () {
  19. const value: MetricValue = {unit: 'millisecond', value: 4000, type: 'duration'};
  20. const performance = getColdAppStartPerformance(value);
  21. expect(performance.score).toBe(PerformanceScore.NEEDS_IMPROVEMENT);
  22. expect(performance.description).toBe(VitalState.MEH);
  23. });
  24. it('renders good', function () {
  25. const value: MetricValue = {unit: 'millisecond', value: 1000, type: 'duration'};
  26. const performance = getColdAppStartPerformance(value);
  27. expect(performance.score).toBe(PerformanceScore.GOOD);
  28. expect(performance.description).toBe(VitalState.GOOD);
  29. });
  30. it('renders unknown', function () {
  31. const value: MetricValue = {unit: 'millisecond', value: 0, type: 'duration'};
  32. const performance = getColdAppStartPerformance(value);
  33. expect(performance.score).toBe(PerformanceScore.NONE);
  34. expect(performance.description).toBe('');
  35. });
  36. });
  37. describe('Warm App Start', function () {
  38. it('renders bad', function () {
  39. const value: MetricValue = {unit: 'millisecond', value: 3000, type: 'duration'};
  40. const performance = getWarmAppStartPerformance(value);
  41. expect(performance.score).toBe(PerformanceScore.BAD);
  42. expect(performance.description).toBe(VitalState.POOR);
  43. });
  44. it('renders meh', function () {
  45. const value: MetricValue = {unit: 'millisecond', value: 1500, type: 'duration'};
  46. const performance = getWarmAppStartPerformance(value);
  47. expect(performance.score).toBe(PerformanceScore.NEEDS_IMPROVEMENT);
  48. expect(performance.description).toBe(VitalState.MEH);
  49. });
  50. it('renders good', function () {
  51. const value: MetricValue = {unit: 'millisecond', value: 500, type: 'duration'};
  52. const performance = getWarmAppStartPerformance(value);
  53. expect(performance.score).toBe(PerformanceScore.GOOD);
  54. expect(performance.description).toBe(VitalState.GOOD);
  55. });
  56. it('renders unknown', function () {
  57. const value: MetricValue = {unit: 'millisecond', value: 0, type: 'duration'};
  58. const performance = getWarmAppStartPerformance(value);
  59. expect(performance.score).toBe(PerformanceScore.NONE);
  60. expect(performance.description).toBe('');
  61. });
  62. });
  63. });