index.spec.tsx 3.4 KB

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