index.spec.jsx 4.7 KB

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