utils.spec.tsx 2.7 KB

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