groupEvents.spec.jsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/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. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  18. location={{query: {}}}
  19. />,
  20. {
  21. context: {...TestStubs.router(), group: TestStubs.Group()},
  22. childContextTypes: {
  23. router: PropTypes.object,
  24. },
  25. }
  26. );
  27. expect(component).toMatchSnapshot();
  28. });
  29. it('handles search', function() {
  30. const component = shallow(
  31. <GroupEvents
  32. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  33. location={{query: {}}}
  34. />,
  35. {
  36. context: {...TestStubs.router(), group: TestStubs.Group()},
  37. childContextTypes: {
  38. router: PropTypes.object,
  39. },
  40. }
  41. );
  42. const list = [
  43. {searchTerm: '', expectedQuery: ''},
  44. {searchTerm: 'test', expectedQuery: 'test'},
  45. {searchTerm: 'environment:production test', expectedQuery: 'test'},
  46. ];
  47. list.forEach(item => {
  48. component.instance().handleSearch(item.searchTerm);
  49. expect(browserHistory.push).toHaveBeenCalledWith(
  50. expect.objectContaining({
  51. query: {query: item.expectedQuery},
  52. })
  53. );
  54. });
  55. });
  56. describe('changing environment', function() {
  57. let component, eventsMock;
  58. beforeEach(function() {
  59. component = shallow(
  60. <GroupEvents
  61. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  62. location={{query: {}}}
  63. environment={TestStubs.Environments()[0]}
  64. />,
  65. {
  66. context: {...TestStubs.router(), group: TestStubs.Group()},
  67. childContextTypes: {
  68. router: PropTypes.object,
  69. },
  70. }
  71. );
  72. eventsMock = MockApiClient.addMockResponse({
  73. url: '/issues/1/events/',
  74. });
  75. });
  76. it('select environment', function() {
  77. component.setProps({environment: TestStubs.Environments()[1]});
  78. expect(eventsMock.mock.calls[0][1].query.environment).toEqual('staging');
  79. });
  80. it('select all environments', function() {
  81. component.setProps({environment: null});
  82. expect(eventsMock.mock.calls[0][1].query.environment).toEqual(undefined);
  83. });
  84. });
  85. });