utils.spec.tsx 2.6 KB

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