organizationGroupEvents.spec.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {browserHistory} from 'react-router';
  2. import * as PropTypes from 'prop-types';
  3. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  4. import {OrganizationContext} from 'sentry/views/organizationContext';
  5. import {GroupEvents} from 'sentry/views/organizationGroupDetails/groupEvents';
  6. const OrganizationGroupEvents = GroupEvents;
  7. describe('groupEvents', function () {
  8. let request;
  9. const organization = TestStubs.Organization();
  10. beforeEach(function () {
  11. request = MockApiClient.addMockResponse({
  12. url: '/issues/1/events/',
  13. body: [
  14. TestStubs.Event({
  15. eventID: '12345',
  16. id: '1',
  17. message: 'ApiException',
  18. groupID: '1',
  19. }),
  20. TestStubs.Event({
  21. crashFile: {
  22. sha1: 'sha1',
  23. name: 'name.dmp',
  24. dateCreated: '2019-05-21T18:01:48.762Z',
  25. headers: {'Content-Type': 'application/octet-stream'},
  26. id: '12345',
  27. size: 123456,
  28. type: 'event.minidump',
  29. },
  30. culprit: '',
  31. dateCreated: '2019-05-21T18:00:23Z',
  32. 'event.type': 'error',
  33. eventID: '123456',
  34. groupID: '1',
  35. id: '98654',
  36. location: 'main.js',
  37. message: 'TestException',
  38. platform: 'native',
  39. projectID: '123',
  40. tags: [{value: 'production', key: 'production'}],
  41. title: 'TestException',
  42. }),
  43. ],
  44. });
  45. browserHistory.push = jest.fn();
  46. });
  47. it('renders', function () {
  48. const component = mountWithTheme(
  49. <OrganizationContext.Provider value={organization}>
  50. <OrganizationGroupEvents
  51. organization={organization}
  52. api={new MockApiClient()}
  53. group={TestStubs.Group()}
  54. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  55. location={{query: {}}}
  56. />
  57. </OrganizationContext.Provider>
  58. );
  59. expect(component).toSnapshot();
  60. });
  61. it('handles search', function () {
  62. const component = shallow(
  63. <OrganizationGroupEvents
  64. organization={organization}
  65. api={new MockApiClient()}
  66. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  67. group={TestStubs.Group()}
  68. location={{query: {}}}
  69. />,
  70. {
  71. context: {...TestStubs.router()},
  72. childContextTypes: {
  73. router: PropTypes.object,
  74. },
  75. }
  76. );
  77. const list = [
  78. {searchTerm: '', expectedQuery: ''},
  79. {searchTerm: 'test', expectedQuery: 'test'},
  80. {searchTerm: 'environment:production test', expectedQuery: 'test'},
  81. ];
  82. list.forEach(item => {
  83. component.instance().handleSearch(item.searchTerm);
  84. expect(browserHistory.push).toHaveBeenCalledWith(
  85. expect.objectContaining({
  86. query: {query: item.expectedQuery},
  87. })
  88. );
  89. });
  90. });
  91. it('handles environment filtering', function () {
  92. shallow(
  93. <OrganizationGroupEvents
  94. organization={organization}
  95. api={new MockApiClient()}
  96. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  97. group={TestStubs.Group()}
  98. location={{query: {environment: ['prod', 'staging']}}}
  99. />,
  100. {
  101. context: {...TestStubs.router()},
  102. childContextTypes: {
  103. router: PropTypes.object,
  104. },
  105. }
  106. );
  107. expect(request).toHaveBeenCalledWith(
  108. '/issues/1/events/',
  109. expect.objectContaining({
  110. query: {limit: 50, query: '', environment: ['prod', 'staging']},
  111. })
  112. );
  113. });
  114. });