sidebar.spec.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import React from 'react';
  2. import {shallow} from 'enzyme';
  3. import GroupSidebar from 'app/components/group/sidebar';
  4. describe('GroupSidebar', function() {
  5. let group = TestStubs.Group({tags: TestStubs.Tags()});
  6. let project = TestStubs.Project();
  7. let environment = {name: 'production', displayName: 'Production', id: '1'};
  8. let wrapper;
  9. let tagValuesMock;
  10. beforeEach(function() {
  11. MockApiClient.addMockResponse({
  12. url: '/issues/1/participants/',
  13. body: [],
  14. });
  15. MockApiClient.addMockResponse({
  16. url: '/issues/1/',
  17. body: group,
  18. });
  19. tagValuesMock = MockApiClient.addMockResponse({
  20. url: '/issues/1/tags/',
  21. body: TestStubs.TagValues(),
  22. });
  23. wrapper = shallow(
  24. <GroupSidebar
  25. group={group}
  26. project={project}
  27. event={TestStubs.Event()}
  28. environments={[environment]}
  29. />,
  30. TestStubs.routerContext()
  31. );
  32. });
  33. afterEach(function() {
  34. MockApiClient.clearMockResponses();
  35. });
  36. describe('sidebar', function() {
  37. it('should make a request to the /tags/ endpoint to get top values', function() {
  38. expect(tagValuesMock).toHaveBeenCalled();
  39. });
  40. });
  41. describe('renders with tags', function() {
  42. it('renders', function() {
  43. expect(wrapper).toMatchSnapshot();
  44. });
  45. it('renders tags', function() {
  46. expect(wrapper.find('[data-test-id="group-tag"]')).toHaveLength(4);
  47. });
  48. });
  49. describe('renders without tags', function() {
  50. beforeEach(function() {
  51. group = TestStubs.Group();
  52. MockApiClient.addMockResponse({
  53. url: '/issues/1/',
  54. body: group,
  55. });
  56. MockApiClient.addMockResponse({
  57. url: '/issues/1/tags/',
  58. body: [],
  59. });
  60. wrapper = shallow(
  61. <GroupSidebar
  62. group={group}
  63. project={project}
  64. event={TestStubs.Event()}
  65. environments={[environment]}
  66. />,
  67. TestStubs.routerContext()
  68. );
  69. });
  70. it('renders no tags', function() {
  71. expect(wrapper.find('[data-test-id="group-tag"]')).toHaveLength(0);
  72. });
  73. it('renders empty text', function() {
  74. expect(wrapper.find('[data-test-id="no-tags"]').text()).toBe(
  75. 'No tags found in the selected environments'
  76. );
  77. });
  78. });
  79. describe('subscribing', function() {
  80. let issuesApi;
  81. beforeEach(function() {
  82. issuesApi = MockApiClient.addMockResponse({
  83. url: '/projects/org-slug/project-slug/issues/',
  84. method: 'PUT',
  85. body: TestStubs.Group({isSubscribed: false}),
  86. });
  87. });
  88. it('can subscribe', function() {
  89. const btn = wrapper.find('.btn-subscribe');
  90. btn.simulate('click');
  91. expect(issuesApi).toHaveBeenCalledWith(
  92. expect.anything(),
  93. expect.objectContaining({
  94. data: {isSubscribed: true},
  95. })
  96. );
  97. });
  98. });
  99. describe('environment toggle', function() {
  100. it('re-requests tags with correct environment', function() {
  101. const stagingEnv = {name: 'staging', displayName: 'Staging', id: '2'};
  102. expect(tagValuesMock).toHaveBeenCalledTimes(1);
  103. wrapper.setProps({environments: [stagingEnv]});
  104. expect(tagValuesMock).toHaveBeenCalledTimes(2);
  105. expect(tagValuesMock).toHaveBeenCalledWith(
  106. '/issues/1/tags/',
  107. expect.objectContaining({
  108. query: expect.objectContaining({
  109. environment: ['staging'],
  110. }),
  111. })
  112. );
  113. });
  114. });
  115. });