index.spec.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {act} from 'sentry-test/reactTestingLibrary';
  3. import {triggerPress} from 'sentry-test/utils';
  4. import ProjectsStore from 'sentry/stores/projectsStore';
  5. import {DiscoverLanding} from 'sentry/views/eventsV2/landing';
  6. describe('EventsV2 > Landing', function () {
  7. const eventTitle = 'Oh no something bad';
  8. const features = ['discover-basic', 'discover-query'];
  9. beforeEach(function () {
  10. act(() => 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('handles no projects', function () {
  68. act(() => ProjectsStore.loadInitialData([]));
  69. const wrapper = mountWithTheme(
  70. <DiscoverLanding
  71. organization={TestStubs.Organization({features})}
  72. location={{query: {}}}
  73. router={{}}
  74. />
  75. );
  76. const content = wrapper.find('SentryDocumentTitle');
  77. expect(content.text()).toContain('You need at least one project to use this view');
  78. });
  79. it('denies access on missing feature', function () {
  80. const wrapper = mountWithTheme(
  81. <DiscoverLanding
  82. organization={TestStubs.Organization()}
  83. location={{query: {}}}
  84. router={{}}
  85. />
  86. );
  87. const content = wrapper.find('PageContent');
  88. expect(content.text()).toContain("You don't have access to this feature");
  89. });
  90. it('has the right sorts', async function () {
  91. const org = TestStubs.Organization({features});
  92. const wrapper = mountWithTheme(
  93. <DiscoverLanding organization={org} location={{query: {}}} router={{}} />
  94. );
  95. // Open sort menu
  96. await act(async () => {
  97. triggerPress(wrapper.find('CompactSelect Button'));
  98. await tick();
  99. wrapper.update();
  100. });
  101. const dropdownItems = wrapper.find('MenuItemWrap');
  102. expect(dropdownItems).toHaveLength(8);
  103. const expectedSorts = [
  104. 'My Queries',
  105. 'Recently Edited',
  106. 'Query Name (A-Z)',
  107. 'Date Created (Newest)',
  108. 'Date Created (Oldest)',
  109. 'Most Outdated',
  110. 'Most Popular',
  111. 'Recently Viewed',
  112. ];
  113. expect(dropdownItems.children().map(element => element.text())).toEqual(
  114. expectedSorts
  115. );
  116. });
  117. });