index.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. it('fetches environments', async function () {
  32. const environmentsCall = MockApiClient.addMockResponse({
  33. url: `/organizations/${organization.slug}/environments/`,
  34. body: TestStubs.Environments(),
  35. });
  36. render(<GroupEventDetailsContainer {...makeProps({organization})} />);
  37. await waitForElementToBeRemoved(() => screen.queryByTestId('loading-indicator'));
  38. expect(environmentsCall).toHaveBeenCalledTimes(1);
  39. });
  40. it('displays an error on error', async function () {
  41. const environmentsCall = MockApiClient.addMockResponse({
  42. url: `/organizations/${organization.slug}/environments/`,
  43. statusCode: 400,
  44. });
  45. render(<GroupEventDetailsContainer {...makeProps({organization})} />);
  46. expect(
  47. await screen.findByText(
  48. "There was an error loading your organization's environments"
  49. )
  50. ).toBeInTheDocument();
  51. expect(environmentsCall).toHaveBeenCalledTimes(1);
  52. });
  53. it('displays an error on falsey environment', async function () {
  54. const environmentsCall = MockApiClient.addMockResponse({
  55. url: `/organizations/${organization.slug}/environments/`,
  56. body: null,
  57. });
  58. render(<GroupEventDetailsContainer {...makeProps({organization})} />);
  59. expect(
  60. await screen.findByText(
  61. "There was an error loading your organization's environments"
  62. )
  63. ).toBeInTheDocument();
  64. expect(environmentsCall).toHaveBeenCalledTimes(1);
  65. });
  66. it('unsubscribes on unmount', async function () {
  67. const unsubscribeMock = jest.fn();
  68. jest
  69. .spyOn(OrganizationEnvironmentsStore, 'listen')
  70. .mockImplementation(() => unsubscribeMock);
  71. MockApiClient.addMockResponse({
  72. url: `/organizations/${organization.slug}/environments/`,
  73. body: TestStubs.Environments(),
  74. });
  75. const {unmount} = render(
  76. <GroupEventDetailsContainer {...makeProps({organization})} />
  77. );
  78. expect(await screen.findByTestId('loading-indicator')).toBeInTheDocument();
  79. unmount();
  80. expect(unsubscribeMock).toHaveBeenCalled();
  81. });
  82. });