index.spec.jsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} 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, 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. expect(screen.getByRole('button', {name: 'All Issues'})).toHaveAttribute(
  90. 'href',
  91. 'sentry?project=112&status='
  92. );
  93. });
  94. it('renders empty state with multi project query', function () {
  95. MockApiClient.addMockResponse({
  96. url: '/organizations/org-slug/user-feedback/',
  97. body: [],
  98. });
  99. const params = {
  100. organization: TestStubs.Organization({
  101. projects: [TestStubs.Project({isMember: true})],
  102. }),
  103. location: {pathname: 'sentry', query: {project: ['112', '113']}, search: ''},
  104. params: {
  105. orgId: organization.slug,
  106. },
  107. };
  108. render(<UserFeedback {...params} />, {context: routerContext});
  109. expect(screen.getByTestId('user-feedback-empty')).toBeInTheDocument();
  110. expect(screen.getByRole('button', {name: 'All Issues'})).toHaveAttribute(
  111. 'href',
  112. 'sentry?project=112&project=113&status='
  113. );
  114. });
  115. });