utils.spec.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import ProjectsStore from 'sentry/stores/projectsStore';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import {getCurrentLandingDisplay} from 'sentry/views/performance/landing/utils';
  5. function initializeData(projects, query = {}) {
  6. const organization = TestStubs.Organization({
  7. features: [],
  8. projects,
  9. });
  10. const initialData = initializeOrg({
  11. organization,
  12. router: {
  13. location: {
  14. query: query || {},
  15. },
  16. },
  17. projects,
  18. project: projects[0],
  19. });
  20. const eventView = EventView.fromLocation(initialData.router.location);
  21. ProjectsStore.loadInitialData(initialData.organization.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 = [TestStubs.Project()];
  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 = [TestStubs.Project()];
  38. const data = initializeData(projects, {landingDisplay: 'frontend_pageload'});
  39. expect(getCurrentLandingDisplay(data.router.location, projects).label).toEqual(
  40. 'Web Vitals'
  41. );
  42. });
  43. it('returns frontend display if project matches', function () {
  44. const projects = [TestStubs.Project({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('Web Vitals');
  49. });
  50. it('returns backend display if project matches', function () {
  51. const projects = [TestStubs.Project({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 = [TestStubs.Project({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 = [TestStubs.Project()];
  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. });