index.spec.jsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ProjectsStore from 'sentry/stores/projectsStore';
  4. import UserFeedback from 'sentry/views/userFeedback';
  5. describe('UserFeedback', function () {
  6. const {organization, router, routerContext} = initializeOrg();
  7. const pageLinks =
  8. '<https://sentry.io/api/0/organizations/sentry/user-feedback/?statsPeriod=14d&cursor=0:0:1>; rel="previous"; results="false"; cursor="0:0:1", ' +
  9. '<https://sentry.io/api/0/organizations/sentry/user-feedback/?statsPeriod=14d&cursor=0:100:0>; rel="next"; results="true"; cursor="0:100:0"';
  10. const project = TestStubs.Project({isMember: true});
  11. beforeEach(function () {
  12. ProjectsStore.loadInitialData([project]);
  13. MockApiClient.addMockResponse({
  14. url: '/organizations/org-slug/user-feedback/',
  15. body: [TestStubs.UserFeedback()],
  16. headers: {Link: pageLinks},
  17. });
  18. MockApiClient.addMockResponse({
  19. url: '/organizations/org-slug/environments/',
  20. body: TestStubs.Environments(),
  21. });
  22. });
  23. afterEach(function () {
  24. ProjectsStore.reset();
  25. });
  26. it('renders', function () {
  27. const params = {
  28. organization: TestStubs.Organization(),
  29. location: {query: {}, search: ''},
  30. params: {
  31. orgId: organization.slug,
  32. },
  33. };
  34. MockApiClient.addMockResponse({
  35. url: '/organizations/org-slug/projects/',
  36. body: [project],
  37. headers: {Link: pageLinks},
  38. });
  39. render(<UserFeedback {...params} />, {context: routerContext});
  40. expect(screen.getByText('Something bad happened')).toBeInTheDocument();
  41. });
  42. it('renders no project message', function () {
  43. ProjectsStore.loadInitialData([]);
  44. const params = {
  45. organization: TestStubs.Organization(),
  46. location: {query: {}, search: ''},
  47. params: {
  48. orgId: organization.slug,
  49. },
  50. };
  51. render(<UserFeedback {...params} />, {context: routerContext});
  52. expect(
  53. screen.getByText('You need at least one project to use this view')
  54. ).toBeInTheDocument();
  55. });
  56. it('renders empty state', function () {
  57. MockApiClient.addMockResponse({
  58. url: '/organizations/org-slug/user-feedback/',
  59. body: [],
  60. });
  61. const params = {
  62. organization: TestStubs.Organization({
  63. projects: [TestStubs.Project({isMember: true})],
  64. }),
  65. location: {query: {}, search: ''},
  66. params: {
  67. orgId: organization.slug,
  68. },
  69. };
  70. render(<UserFeedback {...params} />, {context: routerContext});
  71. expect(screen.getByTestId('user-feedback-empty')).toBeInTheDocument();
  72. });
  73. it('renders empty state with project query', function () {
  74. MockApiClient.addMockResponse({
  75. url: '/organizations/org-slug/user-feedback/',
  76. body: [],
  77. });
  78. const params = {
  79. organization: TestStubs.Organization({
  80. projects: [TestStubs.Project({isMember: true})],
  81. }),
  82. location: {pathname: 'sentry', query: {project: '112'}, search: ''},
  83. params: {
  84. orgId: organization.slug,
  85. },
  86. };
  87. render(<UserFeedback {...params} />, {context: routerContext});
  88. expect(screen.getByTestId('user-feedback-empty')).toBeInTheDocument();
  89. });
  90. it('renders issue status filter', async function () {
  91. const params = {
  92. organization: TestStubs.Organization({
  93. projects: [TestStubs.Project({isMember: true})],
  94. }),
  95. location: router.location,
  96. params: {
  97. orgId: organization.slug,
  98. },
  99. router,
  100. };
  101. render(<UserFeedback {...params} />, {context: routerContext});
  102. // "Unresolved" is selected by default
  103. const unresolved = screen.getByRole('radio', {name: 'Unresolved'});
  104. expect(unresolved).toBeInTheDocument();
  105. expect(unresolved).toBeChecked();
  106. // Select "All Issues"
  107. const all = screen.getByRole('radio', {name: 'All Issues'});
  108. expect(all).toBeInTheDocument();
  109. expect(all).not.toBeChecked();
  110. await userEvent.click(all);
  111. expect(router.replace).toHaveBeenCalledWith(
  112. expect.objectContaining({query: {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(<UserFeedback {...params} />, {context: routerContext});
  130. expect(screen.getByTestId('user-feedback-empty')).toBeInTheDocument();
  131. });
  132. });