index.spec.tsx 3.6 KB

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