index.spec.tsx 3.6 KB

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