index.spec.tsx 3.4 KB

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