organizationGroupEvents.spec.jsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {shallow} from 'enzyme';
  4. import {browserHistory} from 'react-router';
  5. import OrgnanizationGroupEvents from 'app/views/groupDetails/organization/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. <OrgnanizationGroupEvents
  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. <OrgnanizationGroupEvents
  33. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  34. group={TestStubs.Group()}
  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. });