index.spec.tsx 3.3 KB

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