utils.spec.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {LocationFixture} from 'sentry-fixture/locationFixture';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {
  4. TrendParameterColumn,
  5. TrendParameterLabel,
  6. } from 'sentry/views/performance/trends/types';
  7. import {
  8. getCurrentTrendParameter,
  9. performanceTypeToTrendParameterLabel,
  10. } from 'sentry/views/performance/trends/utils';
  11. import {ProjectPerformanceType} from 'sentry/views/performance/utils';
  12. describe('Trend parameter utils', function () {
  13. describe('performanceTypeToTrendParameterLabel', function () {
  14. it('returns correct trend parameter label based on performance type', function () {
  15. const lcp = {
  16. label: TrendParameterLabel.LCP,
  17. column: TrendParameterColumn.LCP,
  18. };
  19. const duration = {
  20. label: TrendParameterLabel.DURATION,
  21. column: TrendParameterColumn.DURATION,
  22. };
  23. const frontendProjectOutput = performanceTypeToTrendParameterLabel(
  24. ProjectPerformanceType.FRONTEND
  25. );
  26. expect(frontendProjectOutput).toEqual(lcp);
  27. const anyProjectOutput = performanceTypeToTrendParameterLabel(
  28. ProjectPerformanceType.ANY
  29. );
  30. expect(anyProjectOutput).toEqual(duration);
  31. const backendProjectOutput = performanceTypeToTrendParameterLabel(
  32. ProjectPerformanceType.BACKEND
  33. );
  34. expect(backendProjectOutput).toEqual(duration);
  35. const frontendOtherProjectOutput = performanceTypeToTrendParameterLabel(
  36. ProjectPerformanceType.FRONTEND_OTHER
  37. );
  38. expect(frontendOtherProjectOutput).toEqual(duration);
  39. const mobileProjectOutput = performanceTypeToTrendParameterLabel(
  40. ProjectPerformanceType.MOBILE
  41. );
  42. expect(mobileProjectOutput).toEqual(duration);
  43. });
  44. });
  45. describe('getCurrentTrendParameter', function () {
  46. it('returns trend parameter from location', () => {
  47. const location = LocationFixture({query: {trendParameter: 'FCP'}});
  48. const expectedTrendParameter = {
  49. label: TrendParameterLabel.FCP,
  50. column: TrendParameterColumn.FCP,
  51. };
  52. // project with performance type 'any'
  53. const projects = [ProjectFixture({id: '1', platform: undefined})];
  54. const output = getCurrentTrendParameter(location, projects, [1]);
  55. expect(output).toEqual(expectedTrendParameter);
  56. });
  57. it('returns default trend parameter based on project type if no trend parameter set in location', function () {
  58. const location = LocationFixture();
  59. const expectedTrendParameter = {
  60. label: TrendParameterLabel.DURATION,
  61. column: TrendParameterColumn.DURATION,
  62. };
  63. // project with performance type 'any'
  64. const projects = [ProjectFixture({id: '1', platform: undefined})];
  65. const output = getCurrentTrendParameter(location, projects, [1]);
  66. expect(output).toEqual(expectedTrendParameter);
  67. });
  68. });
  69. });