utils.spec.tsx 2.8 KB

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