utils.spec.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {Organization} from 'sentry-fixture/organization';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import EventView from 'sentry/utils/discover/eventView';
  5. import {getCurrentLandingDisplay} from 'sentry/views/performance/landing/utils';
  6. function initializeData(projects, query = {}) {
  7. const organization = Organization({
  8. features: [],
  9. projects,
  10. });
  11. const initialData = initializeOrg({
  12. organization,
  13. router: {
  14. location: {
  15. query: query || {},
  16. },
  17. },
  18. projects,
  19. project: projects[0],
  20. });
  21. const eventView = EventView.fromLocation(initialData.router.location);
  22. ProjectsStore.loadInitialData(initialData.organization.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 = [TestStubs.Project()];
  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 = [TestStubs.Project()];
  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 = [TestStubs.Project({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 = [TestStubs.Project({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 = [TestStubs.Project({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 = [TestStubs.Project()];
  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. });