sidebar.spec.jsx 4.0 KB

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