utils.spec.jsx 2.7 KB

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