index.spec.tsx 3.6 KB

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