utils.spec.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {OrganizationFixture} from 'sentry-fixture/organization';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import type {Project} from 'sentry/types/project';
  6. import EventView from 'sentry/utils/discover/eventView';
  7. import {getCurrentLandingDisplay} from 'sentry/views/performance/landing/utils';
  8. function initializeData(projects: Project[], query: any = {}) {
  9. const organization = OrganizationFixture({
  10. features: [],
  11. });
  12. const initialData = initializeOrg({
  13. organization,
  14. router: {
  15. location: {
  16. query: query || {},
  17. },
  18. },
  19. projects,
  20. });
  21. const eventView = EventView.fromLocation(initialData.router.location);
  22. ProjectsStore.loadInitialData(initialData.projects);
  23. return {
  24. ...initialData,
  25. eventView,
  26. };
  27. }
  28. describe('Utils', function () {
  29. describe('getCurrentLandingDisplay()', function () {
  30. it('returns all by default', function () {
  31. const projects = [ProjectFixture()];
  32. const data = initializeData(projects);
  33. expect(getCurrentLandingDisplay(data.router.location, projects).label).toEqual(
  34. 'All Transactions'
  35. );
  36. });
  37. it('returns specific landing display if query is set', function () {
  38. const projects = [ProjectFixture()];
  39. const data = initializeData(projects, {landingDisplay: 'frontend_pageload'});
  40. expect(getCurrentLandingDisplay(data.router.location, projects).label).toEqual(
  41. 'All Transactions'
  42. );
  43. });
  44. it('returns frontend display if project matches', function () {
  45. const projects = [ProjectFixture({id: '22', platform: 'javascript-react'})];
  46. const data = initializeData(projects, {project: 22});
  47. expect(
  48. getCurrentLandingDisplay(data.router.location, projects, data.eventView).label
  49. ).toEqual('Frontend');
  50. });
  51. it('returns backend display if project matches', function () {
  52. const projects = [ProjectFixture({id: '22', platform: 'php'})];
  53. const data = initializeData(projects, {project: 22});
  54. expect(
  55. getCurrentLandingDisplay(data.router.location, projects, data.eventView).label
  56. ).toEqual('Backend');
  57. });
  58. it('returns all display for native platform', function () {
  59. const projects = [ProjectFixture({id: '22', platform: 'native'})];
  60. const data = initializeData(projects, {project: [22]});
  61. expect(
  62. getCurrentLandingDisplay(data.router.location, projects, data.eventView).label
  63. ).toEqual('All Transactions');
  64. });
  65. it('returns all display if multiple projects', function () {
  66. const projects = [ProjectFixture()];
  67. const data = initializeData(projects, {project: [1, 2]});
  68. expect(
  69. getCurrentLandingDisplay(data.router.location, projects, data.eventView).label
  70. ).toEqual('All Transactions');
  71. });
  72. });
  73. });