utils.spec.tsx 2.8 KB

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