index.spec.tsx 3.9 KB

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