issueReplayCount.spec.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import IssueReplayCount from 'sentry/components/group/issueReplayCount';
  4. import ReplayCountContext from 'sentry/components/replays/replayCountContext';
  5. jest.mock('sentry/components/replays/replayCountContext');
  6. describe('IssueReplayCount', function () {
  7. const groupId = '3363325111';
  8. const {organization, routerContext} = initializeOrg();
  9. it('does not render when a group has undefined count', async function () {
  10. const mockReplaysCount = {};
  11. const {container} = render(
  12. <ReplayCountContext.Provider value={mockReplaysCount}>
  13. <IssueReplayCount groupId={groupId} />
  14. </ReplayCountContext.Provider>
  15. );
  16. await waitFor(() => {
  17. expect(container).toBeEmptyDOMElement();
  18. });
  19. });
  20. it('does not render when a group has a count of zero', async function () {
  21. const mockReplaysCount = {
  22. [groupId]: 0,
  23. };
  24. const {container} = render(
  25. <ReplayCountContext.Provider value={mockReplaysCount}>
  26. <IssueReplayCount groupId={groupId} />
  27. </ReplayCountContext.Provider>
  28. );
  29. await waitFor(() => {
  30. expect(container).toBeEmptyDOMElement();
  31. });
  32. });
  33. it('renders the correct replay count', async function () {
  34. const mockReplaysCount = {
  35. [groupId]: 2,
  36. };
  37. const {container} = render(
  38. <ReplayCountContext.Provider value={mockReplaysCount}>
  39. <IssueReplayCount groupId={groupId} />
  40. </ReplayCountContext.Provider>,
  41. {context: routerContext}
  42. );
  43. await waitFor(() => {
  44. expect(container).not.toBeEmptyDOMElement();
  45. const replayCount = screen.getByLabelText('replay-count');
  46. expect(replayCount).toHaveTextContent('2');
  47. expect(replayCount).toHaveAttribute(
  48. 'href',
  49. `/organizations/${organization.slug}/issues/${groupId}/replays/`
  50. );
  51. });
  52. });
  53. });