groupEventDetailsContainer.spec.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {render, screen, waitForElementToBeRemoved} from 'sentry-test/reactTestingLibrary';
  2. import OrganizationEnvironmentsStore from 'sentry/stores/organizationEnvironmentsStore';
  3. import GroupEventDetailsContainer, {
  4. GroupEventDetailsProps,
  5. } from 'sentry/views/organizationGroupDetails/groupEventDetails';
  6. import {ReprocessingStatus} from 'sentry/views/organizationGroupDetails/utils';
  7. jest.mock(
  8. 'sentry/views/organizationGroupDetails/groupEventDetails/groupEventDetails',
  9. () => () => <div>GroupEventDetails</div>
  10. );
  11. const makeProps = (props: Partial<GroupEventDetailsProps>): GroupEventDetailsProps => {
  12. const mergedProps: GroupEventDetailsProps = {
  13. event: TestStubs.Event(),
  14. eventError: false,
  15. group: TestStubs.Group(),
  16. loadingEvent: false,
  17. onRetry: () => null,
  18. groupReprocessingStatus: ReprocessingStatus.NO_STATUS,
  19. organization: TestStubs.Organization(),
  20. project: TestStubs.Project(),
  21. params: {groupId: '0', orgId: '0', eventId: '0'},
  22. ...props,
  23. } as GroupEventDetailsProps;
  24. return mergedProps;
  25. };
  26. describe('groupEventDetailsContainer', () => {
  27. const organization = TestStubs.Organization();
  28. beforeEach(() => {
  29. OrganizationEnvironmentsStore.init();
  30. });
  31. afterEach(() => {
  32. OrganizationEnvironmentsStore.teardown();
  33. });
  34. it('fetches environments', async function () {
  35. const environmentsCall = MockApiClient.addMockResponse({
  36. url: `/organizations/${organization.slug}/environments/`,
  37. body: TestStubs.Environments(),
  38. });
  39. render(<GroupEventDetailsContainer {...makeProps({organization})} />);
  40. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  41. expect(environmentsCall).toHaveBeenCalledTimes(1);
  42. });
  43. it('displays an error on error', async function () {
  44. const environmentsCall = MockApiClient.addMockResponse({
  45. url: `/organizations/${organization.slug}/environments/`,
  46. statusCode: 400,
  47. });
  48. render(<GroupEventDetailsContainer {...makeProps({organization})} />);
  49. expect(
  50. await screen.findByText(
  51. "There was an error loading your organization's environments"
  52. )
  53. ).toBeInTheDocument();
  54. expect(environmentsCall).toHaveBeenCalledTimes(1);
  55. });
  56. it('displays an error on falsey environment', async function () {
  57. const environmentsCall = MockApiClient.addMockResponse({
  58. url: `/organizations/${organization.slug}/environments/`,
  59. body: null,
  60. });
  61. render(<GroupEventDetailsContainer {...makeProps({organization})} />);
  62. expect(
  63. await screen.findByText(
  64. "There was an error loading your organization's environments"
  65. )
  66. ).toBeInTheDocument();
  67. expect(environmentsCall).toHaveBeenCalledTimes(1);
  68. });
  69. it('unsubscribes on unmount', async function () {
  70. const unsubscribeMock = jest.fn();
  71. jest
  72. .spyOn(OrganizationEnvironmentsStore, 'listen')
  73. .mockImplementation(() => unsubscribeMock);
  74. MockApiClient.addMockResponse({
  75. url: `/organizations/${organization.slug}/environments/`,
  76. body: TestStubs.Environments(),
  77. });
  78. const {unmount} = render(
  79. <GroupEventDetailsContainer {...makeProps({organization})} />
  80. );
  81. expect(await screen.findByTestId('loading-indicator')).toBeInTheDocument();
  82. unmount();
  83. expect(unsubscribeMock).toHaveBeenCalled();
  84. });
  85. });