index.spec.jsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/discover/landing';
  5. describe('Discover > 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('denies access on missing feature', function () {
  67. render(
  68. <DiscoverLanding
  69. organization={TestStubs.Organization()}
  70. location={{query: {}}}
  71. router={{}}
  72. />
  73. );
  74. expect(screen.getByText("You don't have access to this feature")).toBeInTheDocument();
  75. });
  76. it('has the right sorts', function () {
  77. const org = TestStubs.Organization({features});
  78. render(<DiscoverLanding organization={org} location={{query: {}}} router={{}} />);
  79. const expectedSorts = [
  80. 'My Queries',
  81. 'Recently Edited',
  82. 'Query Name (A-Z)',
  83. 'Date Created (Newest)',
  84. 'Date Created (Oldest)',
  85. 'Most Outdated',
  86. 'Most Popular',
  87. 'Recently Viewed',
  88. ];
  89. // Open menu
  90. selectEvent.openMenu(screen.getByRole('button', {name: 'Sort By My Queries'}));
  91. // Check that all sorts are there
  92. expectedSorts.forEach(sort =>
  93. expect(screen.getAllByText(sort)[0]).toBeInTheDocument()
  94. );
  95. });
  96. it('links back to the homepage', () => {
  97. const org = TestStubs.Organization({
  98. features: [...features, 'discover-query-builder-as-landing-page'],
  99. });
  100. render(<DiscoverLanding organization={org} location={{query: {}}} router={{}} />, {
  101. context: TestStubs.routerContext(),
  102. });
  103. expect(screen.getByText('Discover')).toHaveAttribute(
  104. 'href',
  105. '/organizations/org-slug/discover/homepage/'
  106. );
  107. });
  108. });