projectGroupEvents.spec.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {shallow} from 'enzyme';
  4. import {browserHistory} from 'react-router';
  5. import {GroupEvents} from 'app/views/groupDetails/project/groupEvents';
  6. describe('groupEvents', function() {
  7. beforeEach(function() {
  8. MockApiClient.addMockResponse({
  9. url: '/issues/1/events/',
  10. body: TestStubs.Events(),
  11. });
  12. browserHistory.push = jest.fn();
  13. });
  14. it('renders', function() {
  15. const component = shallow(
  16. <GroupEvents
  17. group={TestStubs.Group()}
  18. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  19. location={{query: {}}}
  20. />,
  21. {
  22. context: TestStubs.router(),
  23. childContextTypes: {
  24. router: PropTypes.object,
  25. },
  26. }
  27. );
  28. expect(component).toMatchSnapshot();
  29. });
  30. it('handles search', function() {
  31. const component = shallow(
  32. <GroupEvents
  33. group={TestStubs.Group()}
  34. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  35. location={{query: {}}}
  36. />,
  37. {
  38. context: TestStubs.router(),
  39. childContextTypes: {
  40. router: PropTypes.object,
  41. },
  42. }
  43. );
  44. const list = [
  45. {searchTerm: '', expectedQuery: ''},
  46. {searchTerm: 'test', expectedQuery: 'test'},
  47. {searchTerm: 'environment:production test', expectedQuery: 'test'},
  48. ];
  49. list.forEach(item => {
  50. component.instance().handleSearch(item.searchTerm);
  51. expect(browserHistory.push).toHaveBeenCalledWith(
  52. expect.objectContaining({
  53. query: {query: item.expectedQuery},
  54. })
  55. );
  56. });
  57. });
  58. describe('changing environment', function() {
  59. let component, eventsMock;
  60. beforeEach(function() {
  61. component = shallow(
  62. <GroupEvents
  63. group={TestStubs.Group()}
  64. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  65. location={{query: {}}}
  66. environment={TestStubs.Environments()[0]}
  67. />,
  68. {
  69. context: TestStubs.router(),
  70. childContextTypes: {
  71. router: PropTypes.object,
  72. },
  73. }
  74. );
  75. eventsMock = MockApiClient.addMockResponse({
  76. url: '/issues/1/events/',
  77. });
  78. });
  79. it('select environment', function() {
  80. component.setProps({environment: TestStubs.Environments()[1]});
  81. expect(eventsMock.mock.calls[0][1].query.environment).toEqual('staging');
  82. });
  83. it('select all environments', function() {
  84. component.setProps({environment: null});
  85. expect(eventsMock.mock.calls[0][1].query.environment).toEqual(undefined);
  86. });
  87. });
  88. });