index.spec.tsx 3.2 KB

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