IssueList.spec.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {IssueList} from 'sentry/components/issueList';
  3. describe('IssueList', () => {
  4. beforeEach(() => {
  5. jest.clearAllMocks();
  6. MockApiClient.clearMockResponses();
  7. });
  8. it('renders loading state', () => {
  9. const api = new MockApiClient();
  10. jest.spyOn(api, 'request').mockImplementation(() => {
  11. return new Promise(_ => {
  12. return null;
  13. });
  14. });
  15. render(
  16. <IssueList
  17. api={api}
  18. location={TestStubs.location()}
  19. endpoint="endpoint"
  20. params={{}}
  21. router={TestStubs.router()}
  22. routes={[]}
  23. />
  24. );
  25. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  26. });
  27. it('renders error state', () => {
  28. const api = new MockApiClient();
  29. MockApiClient.addMockResponse({
  30. url: 'endpoint',
  31. method: 'GET',
  32. statusCode: 400,
  33. });
  34. render(
  35. <IssueList
  36. api={api}
  37. location={TestStubs.location()}
  38. endpoint="endpoint"
  39. params={{}}
  40. router={TestStubs.router()}
  41. routes={[]}
  42. />
  43. );
  44. expect(screen.getByTestId('loading-error-message')).toBeInTheDocument();
  45. });
  46. it('refetches data on click from error state', async () => {
  47. const api = new MockApiClient();
  48. MockApiClient.addMockResponse({
  49. url: 'endpoint',
  50. method: 'GET',
  51. statusCode: 400,
  52. });
  53. const spy = jest.spyOn(api, 'request');
  54. render(
  55. <IssueList
  56. api={api}
  57. location={TestStubs.location()}
  58. endpoint="endpoint"
  59. params={{}}
  60. router={TestStubs.router()}
  61. routes={[]}
  62. />
  63. );
  64. expect(await screen.findByTestId('loading-error-message')).toBeInTheDocument();
  65. userEvent.click(screen.getByText('Retry'));
  66. expect(spy).toHaveBeenCalledTimes(2);
  67. });
  68. it('renders issue list', async () => {
  69. const api = new MockApiClient();
  70. const spy = jest.spyOn(api, 'request');
  71. MockApiClient.addMockResponse({
  72. url: 'endpoint',
  73. method: 'GET',
  74. statusCode: 200,
  75. body: [TestStubs.Group({id: '1', culprit: 'Stubbed Issue'})],
  76. });
  77. render(
  78. <IssueList
  79. api={api}
  80. query={{limit: '5'}}
  81. location={TestStubs.location({
  82. query: {
  83. cursor: '10',
  84. },
  85. })}
  86. endpoint="endpoint"
  87. params={{}}
  88. router={TestStubs.router()}
  89. routes={[]}
  90. />
  91. );
  92. expect(await screen.findByText(/Stubbed Issue/)).toBeInTheDocument();
  93. // @ts-ignore
  94. expect(spy.mock.calls[0][1].query).toEqual({
  95. cursor: '10',
  96. limit: '5',
  97. });
  98. });
  99. it('renders custom empty state', () => {
  100. const api = new MockApiClient();
  101. const CustomEmptyState = jest.fn().mockImplementation(() => <div>Empty State</div>);
  102. MockApiClient.addMockResponse({
  103. url: 'endpoint',
  104. method: 'GET',
  105. statusCode: 200,
  106. body: [],
  107. });
  108. render(
  109. <IssueList
  110. api={api}
  111. location={TestStubs.location()}
  112. endpoint="endpoint"
  113. params={{}}
  114. router={TestStubs.router()}
  115. routes={[]}
  116. renderEmpty={CustomEmptyState}
  117. />
  118. );
  119. expect(screen.getByText('Empty State')).toBeInTheDocument();
  120. expect(CustomEmptyState).toHaveBeenCalled();
  121. });
  122. it('renders empty state', () => {
  123. const api = new MockApiClient();
  124. MockApiClient.addMockResponse({
  125. url: 'endpoint',
  126. method: 'GET',
  127. statusCode: 200,
  128. body: [],
  129. });
  130. render(
  131. <IssueList
  132. api={api}
  133. location={TestStubs.location()}
  134. endpoint="endpoint"
  135. params={{}}
  136. router={TestStubs.router()}
  137. routes={[]}
  138. />
  139. );
  140. expect(screen.getByText(/Nothing to show here, move along/)).toBeInTheDocument();
  141. });
  142. });