sidebar.spec.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import React from 'react';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {mountWithTheme} from 'sentry-test/enzyme';
  4. import GroupSidebar from 'app/components/group/sidebar';
  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. beforeEach(function() {
  12. MockApiClient.addMockResponse({
  13. url: '/projects/org-slug/project-slug/events/1/committers/',
  14. body: {committers: []},
  15. });
  16. MockApiClient.addMockResponse({
  17. url: '/projects/org-slug/project-slug/events/1/owners/',
  18. body: {
  19. owners: [],
  20. rules: [],
  21. },
  22. });
  23. MockApiClient.addMockResponse({
  24. url: '/groups/1/integrations/',
  25. body: [],
  26. });
  27. MockApiClient.addMockResponse({
  28. url: '/issues/1/participants/',
  29. body: [],
  30. });
  31. MockApiClient.addMockResponse({
  32. url: '/issues/1/',
  33. body: group,
  34. });
  35. MockApiClient.addMockResponse({
  36. url: '/groups/1/external-issues/',
  37. body: [],
  38. });
  39. tagsMock = MockApiClient.addMockResponse({
  40. url: '/issues/1/tags/',
  41. body: TestStubs.Tags(),
  42. });
  43. wrapper = mountWithTheme(
  44. <GroupSidebar
  45. group={group}
  46. project={project}
  47. organization={organization}
  48. event={TestStubs.Event()}
  49. environments={[environment]}
  50. />,
  51. routerContext
  52. );
  53. });
  54. afterEach(function() {
  55. MockApiClient.clearMockResponses();
  56. });
  57. describe('sidebar', function() {
  58. it('should make a request to the /tags/ endpoint to get top values', function() {
  59. expect(tagsMock).toHaveBeenCalled();
  60. });
  61. });
  62. describe('renders with tags', function() {
  63. it('renders', function() {
  64. expect(wrapper.find('SuggestedOwners')).toHaveLength(1);
  65. expect(wrapper.find('GroupReleaseStats')).toHaveLength(1);
  66. expect(wrapper.find('ExternalIssueList')).toHaveLength(1);
  67. expect(
  68. wrapper.find('GroupTagDistributionMeter[data-test-id="group-tag"]')
  69. ).toHaveLength(5);
  70. });
  71. });
  72. describe('renders without tags', function() {
  73. beforeEach(function() {
  74. group = TestStubs.Group();
  75. MockApiClient.addMockResponse({
  76. url: '/issues/1/',
  77. body: group,
  78. });
  79. MockApiClient.addMockResponse({
  80. url: '/issues/1/tags/',
  81. body: [],
  82. });
  83. wrapper = mountWithTheme(
  84. <GroupSidebar
  85. api={new MockApiClient()}
  86. group={group}
  87. organization={organization}
  88. project={project}
  89. event={TestStubs.Event()}
  90. environments={[environment]}
  91. />,
  92. routerContext
  93. );
  94. });
  95. it('renders no tags', function() {
  96. expect(wrapper.find('[data-test-id="group-tag"]')).toHaveLength(0);
  97. });
  98. it('renders empty text', function() {
  99. expect(wrapper.find('[data-test-id="no-tags"]').text()).toBe(
  100. 'No tags found in the selected environments'
  101. );
  102. });
  103. });
  104. describe('environment toggle', function() {
  105. it('re-requests tags with correct environment', function() {
  106. const stagingEnv = {name: 'staging', displayName: 'Staging', id: '2'};
  107. expect(tagsMock).toHaveBeenCalledTimes(1);
  108. wrapper.setProps({environments: [stagingEnv]});
  109. expect(tagsMock).toHaveBeenCalledTimes(2);
  110. expect(tagsMock).toHaveBeenCalledWith(
  111. '/issues/1/tags/',
  112. expect.objectContaining({
  113. query: expect.objectContaining({
  114. environment: ['staging'],
  115. }),
  116. })
  117. );
  118. });
  119. });
  120. });