sidebar.spec.jsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import GroupSidebar from 'sentry/components/group/sidebar';
  4. import {OrganizationContext} from 'sentry/views/organizationContext';
  5. describe('GroupSidebar', function () {
  6. let group = TestStubs.Group({tags: TestStubs.Tags()});
  7. const {organization, project, routerContext} = initializeOrg();
  8. const environment = {name: 'production', displayName: 'Production', id: '1'};
  9. let wrapper;
  10. let tagsMock;
  11. const mountWithThemeAndOrg = (component, opts) =>
  12. mountWithTheme(component, {
  13. ...opts,
  14. wrappingComponent: ({children}) => (
  15. <OrganizationContext.Provider value={organization}>
  16. {children}
  17. </OrganizationContext.Provider>
  18. ),
  19. });
  20. beforeEach(function () {
  21. MockApiClient.addMockResponse({
  22. url: '/projects/org-slug/project-slug/events/1/committers/',
  23. body: {committers: []},
  24. });
  25. MockApiClient.addMockResponse({
  26. url: '/projects/org-slug/project-slug/events/1/owners/',
  27. body: {
  28. owners: [],
  29. rules: [],
  30. },
  31. });
  32. MockApiClient.addMockResponse({
  33. url: '/groups/1/integrations/',
  34. body: [],
  35. });
  36. MockApiClient.addMockResponse({
  37. url: '/issues/1/participants/',
  38. body: [],
  39. });
  40. MockApiClient.addMockResponse({
  41. url: '/issues/1/',
  42. body: group,
  43. });
  44. MockApiClient.addMockResponse({
  45. url: '/issues/1/current-release/',
  46. body: {},
  47. });
  48. MockApiClient.addMockResponse({
  49. url: '/groups/1/external-issues/',
  50. body: [],
  51. });
  52. MockApiClient.addMockResponse({
  53. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  54. body: [],
  55. });
  56. MockApiClient.addMockResponse({
  57. url: `/prompts-activity/`,
  58. body: {},
  59. });
  60. MockApiClient.addMockResponse({
  61. url: `/organizations/${organization.slug}/code-mappings/`,
  62. query: {project: -1},
  63. method: 'GET',
  64. body: [],
  65. });
  66. tagsMock = MockApiClient.addMockResponse({
  67. url: '/issues/1/tags/',
  68. body: TestStubs.Tags(),
  69. });
  70. wrapper = mountWithThemeAndOrg(
  71. <GroupSidebar
  72. group={group}
  73. project={project}
  74. organization={organization}
  75. event={TestStubs.Event()}
  76. environments={[environment]}
  77. />,
  78. routerContext
  79. );
  80. });
  81. afterEach(function () {
  82. MockApiClient.clearMockResponses();
  83. });
  84. describe('sidebar', function () {
  85. it('should make a request to the /tags/ endpoint to get top values', function () {
  86. expect(tagsMock).toHaveBeenCalled();
  87. });
  88. });
  89. describe('renders with tags', function () {
  90. it('renders', async function () {
  91. expect(wrapper.find('SuggestedOwners')).toHaveLength(1);
  92. expect(wrapper.find('Memo(GroupReleaseStats)')).toHaveLength(1);
  93. expect(wrapper.find('ExternalIssueList')).toHaveLength(1);
  94. await tick();
  95. wrapper.update();
  96. expect(wrapper.find('GroupTagDistributionMeter')).toHaveLength(5);
  97. });
  98. });
  99. describe('renders without tags', function () {
  100. beforeEach(async function () {
  101. group = TestStubs.Group();
  102. MockApiClient.addMockResponse({
  103. url: '/issues/1/',
  104. body: group,
  105. });
  106. MockApiClient.addMockResponse({
  107. url: '/issues/1/tags/',
  108. body: [],
  109. });
  110. wrapper = mountWithThemeAndOrg(
  111. <GroupSidebar
  112. api={new MockApiClient()}
  113. group={group}
  114. organization={organization}
  115. project={project}
  116. event={TestStubs.Event()}
  117. environments={[environment]}
  118. />,
  119. routerContext
  120. );
  121. await tick();
  122. wrapper.update();
  123. });
  124. it('renders no tags', function () {
  125. expect(wrapper.find('GroupTagDistributionMeter')).toHaveLength(0);
  126. });
  127. it('renders empty text', function () {
  128. expect(wrapper.find('[data-test-id="no-tags"]').text()).toBe(
  129. 'No tags found in the selected environments'
  130. );
  131. });
  132. });
  133. describe('environment toggle', function () {
  134. it('re-requests tags with correct environment', function () {
  135. const stagingEnv = {name: 'staging', displayName: 'Staging', id: '2'};
  136. expect(tagsMock).toHaveBeenCalledTimes(1);
  137. wrapper.setProps({environments: [stagingEnv]});
  138. expect(tagsMock).toHaveBeenCalledTimes(2);
  139. expect(tagsMock).toHaveBeenCalledWith(
  140. '/issues/1/tags/',
  141. expect.objectContaining({
  142. query: expect.objectContaining({
  143. environment: ['staging'],
  144. }),
  145. })
  146. );
  147. });
  148. });
  149. });