index.spec.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import selectEvent from 'react-select-event';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import {DiscoverLanding} from 'sentry/views/eventsV2/landing';
  5. describe('EventsV2 > Landing', function () {
  6. const eventTitle = 'Oh no something bad';
  7. const features = ['discover-basic', 'discover-query'];
  8. beforeEach(function () {
  9. ProjectsStore.loadInitialData([TestStubs.Project()]);
  10. MockApiClient.addMockResponse({
  11. url: '/organizations/org-slug/projects/',
  12. body: [],
  13. });
  14. MockApiClient.addMockResponse({
  15. url: '/organizations/org-slug/eventsv2/',
  16. body: {
  17. meta: {
  18. id: 'string',
  19. title: 'string',
  20. 'project.name': 'string',
  21. timestamp: 'date',
  22. 'user.id': 'string',
  23. },
  24. data: [
  25. {
  26. id: 'deadbeef',
  27. 'user.id': 'alberto leal',
  28. title: eventTitle,
  29. 'project.name': 'project-slug',
  30. timestamp: '2019-05-23T22:12:48+00:00',
  31. },
  32. ],
  33. },
  34. });
  35. MockApiClient.addMockResponse({
  36. url: '/organizations/org-slug/events/project-slug:deadbeef/',
  37. method: 'GET',
  38. body: {
  39. id: '1234',
  40. size: 1200,
  41. eventID: 'deadbeef',
  42. title: 'Oh no something bad',
  43. message: 'It was not good',
  44. dateCreated: '2019-05-23T22:12:48+00:00',
  45. entries: [
  46. {
  47. type: 'message',
  48. message: 'bad stuff',
  49. data: {},
  50. },
  51. ],
  52. tags: [{key: 'browser', value: 'Firefox'}],
  53. },
  54. });
  55. MockApiClient.addMockResponse({
  56. url: '/organizations/org-slug/events-stats/',
  57. method: 'GET',
  58. body: [],
  59. });
  60. MockApiClient.addMockResponse({
  61. url: '/organizations/org-slug/discover/saved/',
  62. method: 'GET',
  63. body: [],
  64. });
  65. });
  66. it('handles no projects', function () {
  67. ProjectsStore.loadInitialData([]);
  68. render(
  69. <DiscoverLanding
  70. organization={TestStubs.Organization({features})}
  71. location={{query: {}}}
  72. router={{}}
  73. />
  74. );
  75. expect(
  76. screen.getByText('You need at least one project to use this view')
  77. ).toBeInTheDocument();
  78. });
  79. it('denies access on missing feature', function () {
  80. render(
  81. <DiscoverLanding
  82. organization={TestStubs.Organization()}
  83. location={{query: {}}}
  84. router={{}}
  85. />
  86. );
  87. expect(screen.getByText("You don't have access to this feature")).toBeInTheDocument();
  88. });
  89. it('has the right sorts', function () {
  90. const org = TestStubs.Organization({features});
  91. render(<DiscoverLanding organization={org} location={{query: {}}} router={{}} />);
  92. const expectedSorts = [
  93. 'My Queries',
  94. 'Recently Edited',
  95. 'Query Name (A-Z)',
  96. 'Date Created (Newest)',
  97. 'Date Created (Oldest)',
  98. 'Most Outdated',
  99. 'Most Popular',
  100. 'Recently Viewed',
  101. ];
  102. // Open menu
  103. selectEvent.openMenu(screen.getByRole('button', {name: 'Sort By My Queries'}));
  104. // Check that all sorts are there
  105. expectedSorts.forEach(sort =>
  106. expect(screen.getAllByText(sort)[0]).toBeInTheDocument()
  107. );
  108. });
  109. it('links back to the homepage', () => {
  110. const org = TestStubs.Organization({
  111. features: [...features, 'discover-query-builder-as-landing-page'],
  112. });
  113. render(<DiscoverLanding organization={org} location={{query: {}}} router={{}} />, {
  114. context: TestStubs.routerContext(),
  115. });
  116. expect(screen.getByText('Discover')).toHaveAttribute(
  117. 'href',
  118. '/organizations/org-slug/discover/homepage/'
  119. );
  120. });
  121. });