index.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import selectEvent from 'react-select-event';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {render, screen} from 'sentry-test/reactTestingLibrary';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import {DiscoverLanding} from 'sentry/views/discover/landing';
  6. describe('Discover > Landing', function () {
  7. const eventTitle = 'Oh no something bad';
  8. const features = ['discover-basic', 'discover-query'];
  9. beforeEach(function () {
  10. ProjectsStore.loadInitialData([TestStubs.Project()]);
  11. MockApiClient.addMockResponse({
  12. url: '/organizations/org-slug/projects/',
  13. body: [],
  14. });
  15. MockApiClient.addMockResponse({
  16. url: '/organizations/org-slug/eventsv2/',
  17. body: {
  18. meta: {
  19. id: 'string',
  20. title: 'string',
  21. 'project.name': 'string',
  22. timestamp: 'date',
  23. 'user.id': 'string',
  24. },
  25. data: [
  26. {
  27. id: 'deadbeef',
  28. 'user.id': 'alberto leal',
  29. title: eventTitle,
  30. 'project.name': 'project-slug',
  31. timestamp: '2019-05-23T22:12:48+00:00',
  32. },
  33. ],
  34. },
  35. });
  36. MockApiClient.addMockResponse({
  37. url: '/organizations/org-slug/events/project-slug:deadbeef/',
  38. method: 'GET',
  39. body: {
  40. id: '1234',
  41. size: 1200,
  42. eventID: 'deadbeef',
  43. title: 'Oh no something bad',
  44. message: 'It was not good',
  45. dateCreated: '2019-05-23T22:12:48+00:00',
  46. entries: [
  47. {
  48. type: 'message',
  49. message: 'bad stuff',
  50. data: {},
  51. },
  52. ],
  53. tags: [{key: 'browser', value: 'Firefox'}],
  54. },
  55. });
  56. MockApiClient.addMockResponse({
  57. url: '/organizations/org-slug/events-stats/',
  58. method: 'GET',
  59. body: [],
  60. });
  61. MockApiClient.addMockResponse({
  62. url: '/organizations/org-slug/discover/saved/',
  63. method: 'GET',
  64. body: [],
  65. });
  66. });
  67. it('denies access on missing feature', function () {
  68. render(
  69. <DiscoverLanding
  70. organization={Organization()}
  71. {...TestStubs.routeComponentProps()}
  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 = Organization({features});
  78. render(<DiscoverLanding organization={org} {...TestStubs.routeComponentProps()} />);
  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 = Organization({features});
  98. render(<DiscoverLanding organization={org} {...TestStubs.routeComponentProps()} />, {
  99. context: TestStubs.routerContext(),
  100. });
  101. expect(screen.getByText('Discover')).toHaveAttribute(
  102. 'href',
  103. '/organizations/org-slug/discover/homepage/'
  104. );
  105. });
  106. });