utils.spec.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import ProjectsStore from 'app/stores/projectsStore';
  3. import EventView from 'app/utils/discover/eventView';
  4. import {getCurrentLandingDisplay} from 'app/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. 'Frontend (Pageload)'
  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('Frontend (Pageload)');
  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 if multiple projects', function () {
  56. const projects = [TestStubs.Project()];
  57. const data = initializeData(projects, {project: [1, 2]});
  58. expect(
  59. getCurrentLandingDisplay(data.router.location, projects, data.eventView).label
  60. ).toEqual('All Transactions');
  61. });
  62. });
  63. });