groupEvents.spec.jsx 3.3 KB

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