groupEventDetailsContainer.spec.tsx 3.2 KB

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