utils.spec.tsx 2.8 KB

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