index.spec.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import {OrganizationContext} from 'sentry/views/organizationContext';
  5. import UserFeedback from 'sentry/views/userFeedback';
  6. describe('UserFeedback', function () {
  7. const {organization, routerContext} = initializeOrg();
  8. const pageLinks =
  9. '<https://sentry.io/api/0/organizations/sentry/user-feedback/?statsPeriod=14d&cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1", ' +
  10. '<https://sentry.io/api/0/organizations/sentry/user-feedback/?statsPeriod=14d&cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"';
  11. const project = TestStubs.Project({isMember: true});
  12. beforeEach(function () {
  13. ProjectsStore.loadInitialData([project]);
  14. MockApiClient.addMockResponse({
  15. url: '/organizations/org-slug/user-feedback/',
  16. body: [TestStubs.UserFeedback()],
  17. headers: {Link: pageLinks},
  18. });
  19. MockApiClient.addMockResponse({
  20. url: '/organizations/org-slug/environments/',
  21. body: TestStubs.Environments(),
  22. });
  23. });
  24. afterEach(function () {
  25. ProjectsStore.reset();
  26. });
  27. it('renders', function () {
  28. const params = {
  29. organization: TestStubs.Organization(),
  30. location: {query: {}, search: ''},
  31. params: {
  32. orgId: organization.slug,
  33. },
  34. };
  35. MockApiClient.addMockResponse({
  36. url: '/organizations/org-slug/projects/',
  37. body: [project],
  38. headers: {Link: pageLinks},
  39. });
  40. render(
  41. <OrganizationContext.Provider value={organization}>
  42. <UserFeedback {...params} />
  43. </OrganizationContext.Provider>,
  44. {context: routerContext}
  45. );
  46. expect(screen.getByText('Something bad happened')).toBeInTheDocument();
  47. });
  48. it('renders no project message', function () {
  49. ProjectsStore.loadInitialData([]);
  50. const params = {
  51. organization: TestStubs.Organization(),
  52. location: {query: {}, search: ''},
  53. params: {
  54. orgId: organization.slug,
  55. },
  56. };
  57. render(
  58. <OrganizationContext.Provider value={organization}>
  59. <UserFeedback {...params} />
  60. </OrganizationContext.Provider>,
  61. {context: routerContext}
  62. );
  63. expect(
  64. screen.getByText('You need at least one project to use this view')
  65. ).toBeInTheDocument();
  66. });
  67. it('renders empty state', function () {
  68. MockApiClient.addMockResponse({
  69. url: '/organizations/org-slug/user-feedback/',
  70. body: [],
  71. });
  72. const params = {
  73. organization: TestStubs.Organization({
  74. projects: [TestStubs.Project({isMember: true})],
  75. }),
  76. location: {query: {}, search: ''},
  77. params: {
  78. orgId: organization.slug,
  79. },
  80. };
  81. render(
  82. <OrganizationContext.Provider value={organization}>
  83. <UserFeedback {...params} />
  84. </OrganizationContext.Provider>,
  85. {context: routerContext}
  86. );
  87. expect(screen.getByTestId('user-feedback-empty')).toBeInTheDocument();
  88. });
  89. it('renders empty state with project query', function () {
  90. MockApiClient.addMockResponse({
  91. url: '/organizations/org-slug/user-feedback/',
  92. body: [],
  93. });
  94. const params = {
  95. organization: TestStubs.Organization({
  96. projects: [TestStubs.Project({isMember: true})],
  97. }),
  98. location: {pathname: 'sentry', query: {project: '112'}, search: ''},
  99. params: {
  100. orgId: organization.slug,
  101. },
  102. };
  103. render(
  104. <OrganizationContext.Provider value={organization}>
  105. <UserFeedback {...params} />
  106. </OrganizationContext.Provider>,
  107. {context: routerContext}
  108. );
  109. expect(screen.getByTestId('user-feedback-empty')).toBeInTheDocument();
  110. expect(screen.getByRole('button', {name: 'All Issues'})).toHaveAttribute(
  111. 'href',
  112. 'sentry?project=112&status='
  113. );
  114. });
  115. it('renders empty state with multi project query', function () {
  116. MockApiClient.addMockResponse({
  117. url: '/organizations/org-slug/user-feedback/',
  118. body: [],
  119. });
  120. const params = {
  121. organization: TestStubs.Organization({
  122. projects: [TestStubs.Project({isMember: true})],
  123. }),
  124. location: {pathname: 'sentry', query: {project: ['112', '113']}, search: ''},
  125. params: {
  126. orgId: organization.slug,
  127. },
  128. };
  129. render(
  130. <OrganizationContext.Provider value={organization}>
  131. <UserFeedback {...params} />
  132. </OrganizationContext.Provider>,
  133. {context: routerContext}
  134. );
  135. expect(screen.getByTestId('user-feedback-empty')).toBeInTheDocument();
  136. expect(screen.getByRole('button', {name: 'All Issues'})).toHaveAttribute(
  137. 'href',
  138. 'sentry?project=112&project=113&status='
  139. );
  140. });
  141. });