organizationGroupEvents.spec.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import {mount, shallow} from 'sentry-test/enzyme';
  4. import {browserHistory} from 'react-router';
  5. import {GroupEvents} from 'app/views/organizationGroupDetails/groupEvents';
  6. const OrgnanizationGroupEvents = GroupEvents;
  7. describe('groupEvents', function() {
  8. let request;
  9. const routerContext = TestStubs.routerContext();
  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 = mount(
  49. <OrgnanizationGroupEvents
  50. api={new MockApiClient()}
  51. group={TestStubs.Group()}
  52. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  53. location={{query: {}}}
  54. />,
  55. routerContext
  56. );
  57. expect(component.find('tr')).toMatchSnapshot();
  58. });
  59. it('handles search', function() {
  60. const component = shallow(
  61. <OrgnanizationGroupEvents
  62. api={new MockApiClient()}
  63. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  64. group={TestStubs.Group()}
  65. location={{query: {}}}
  66. />,
  67. {
  68. context: {...TestStubs.router()},
  69. childContextTypes: {
  70. router: PropTypes.object,
  71. },
  72. }
  73. );
  74. const list = [
  75. {searchTerm: '', expectedQuery: ''},
  76. {searchTerm: 'test', expectedQuery: 'test'},
  77. {searchTerm: 'environment:production test', expectedQuery: 'test'},
  78. ];
  79. list.forEach(item => {
  80. component.instance().handleSearch(item.searchTerm);
  81. expect(browserHistory.push).toHaveBeenCalledWith(
  82. expect.objectContaining({
  83. query: {query: item.expectedQuery},
  84. })
  85. );
  86. });
  87. });
  88. it('handles environment filtering', function() {
  89. shallow(
  90. <OrgnanizationGroupEvents
  91. api={new MockApiClient()}
  92. params={{orgId: 'orgId', projectId: 'projectId', groupId: '1'}}
  93. group={TestStubs.Group()}
  94. location={{query: {environment: ['prod', 'staging']}}}
  95. />,
  96. {
  97. context: {...TestStubs.router()},
  98. childContextTypes: {
  99. router: PropTypes.object,
  100. },
  101. }
  102. );
  103. expect(request).toHaveBeenCalledWith(
  104. '/issues/1/events/',
  105. expect.objectContaining({
  106. query: {limit: 50, query: '', environment: ['prod', 'staging']},
  107. })
  108. );
  109. });
  110. });