guideAnchor.spec.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import GuideStore from 'sentry/stores/guideStore';
  5. describe('GuideAnchor', function () {
  6. const serverGuide = [
  7. {
  8. guide: 'issue',
  9. seen: false,
  10. },
  11. ];
  12. beforeEach(function () {
  13. ConfigStore.config = {
  14. user: {
  15. isSuperuser: false,
  16. dateJoined: new Date(2020, 0, 1),
  17. },
  18. };
  19. });
  20. it('renders, advances, and finishes', async function () {
  21. render(
  22. <div>
  23. <GuideAnchor target="issue_number" />
  24. <GuideAnchor target="exception" />
  25. </div>
  26. );
  27. GuideStore.fetchSucceeded(serverGuide);
  28. expect(await screen.findByText('Identify Your Issues')).toBeInTheDocument();
  29. // XXX(epurkhiser): Skip pointer event checks due to a bug with how Popper
  30. // renders the hovercard with pointer-events: none. See [0]
  31. //
  32. // [0]: https://github.com/testing-library/user-event/issues/639
  33. //
  34. // NOTE(epurkhiser): We may be able to remove the skipPointerEventsCheck
  35. // when we're on popper >= 1.
  36. userEvent.click(screen.getByLabelText('Next'), undefined, {
  37. skipPointerEventsCheck: true,
  38. });
  39. expect(await screen.findByText('Narrow Down Suspects')).toBeInTheDocument();
  40. expect(screen.queryByText('Identify Your Issues')).not.toBeInTheDocument();
  41. // Clicking on the button in the last step should finish the guide.
  42. const finishMock = MockApiClient.addMockResponse({
  43. method: 'PUT',
  44. url: '/assistant/',
  45. });
  46. userEvent.click(screen.getByLabelText('Enough Already'), undefined, {
  47. skipPointerEventsCheck: true,
  48. });
  49. expect(finishMock).toHaveBeenCalledWith(
  50. '/assistant/',
  51. expect.objectContaining({
  52. method: 'PUT',
  53. data: {
  54. guide: 'issue',
  55. status: 'viewed',
  56. },
  57. })
  58. );
  59. });
  60. it('dismisses', async function () {
  61. render(
  62. <div>
  63. <GuideAnchor target="issue_number" />
  64. <GuideAnchor target="exception" />
  65. </div>
  66. );
  67. GuideStore.fetchSucceeded(serverGuide);
  68. expect(await screen.findByText('Identify Your Issues')).toBeInTheDocument();
  69. const dismissMock = MockApiClient.addMockResponse({
  70. method: 'PUT',
  71. url: '/assistant/',
  72. });
  73. userEvent.click(screen.getByLabelText('Dismiss'), undefined, {
  74. skipPointerEventsCheck: true,
  75. });
  76. expect(dismissMock).toHaveBeenCalledWith(
  77. '/assistant/',
  78. expect.objectContaining({
  79. method: 'PUT',
  80. data: {
  81. guide: 'issue',
  82. status: 'dismissed',
  83. },
  84. })
  85. );
  86. expect(screen.queryByText('Identify Your Issues')).not.toBeInTheDocument();
  87. });
  88. it('renders no container when inactive', function () {
  89. render(
  90. <GuideAnchor target="target 1">
  91. <span data-test-id="child-div" />
  92. </GuideAnchor>
  93. );
  94. expect(screen.queryByTestId('guide-container')).not.toBeInTheDocument();
  95. expect(screen.getByTestId('child-div')).toBeInTheDocument();
  96. });
  97. it('renders children when disabled', function () {
  98. render(
  99. <GuideAnchor disabled target="exception">
  100. <div data-test-id="child-div" />
  101. </GuideAnchor>
  102. );
  103. expect(screen.queryByTestId('guide-container')).not.toBeInTheDocument();
  104. expect(screen.getByTestId('child-div')).toBeInTheDocument();
  105. });
  106. it('if forceHide is true, do not render guide', async function () {
  107. render(
  108. <div>
  109. <GuideAnchor target="issue_number" />
  110. <GuideAnchor target="exception" />
  111. </div>
  112. );
  113. GuideStore.fetchSucceeded(serverGuide);
  114. expect(await screen.findByText('Identify Your Issues')).toBeInTheDocument();
  115. GuideStore.setForceHide(true);
  116. expect(screen.queryByText('Identify Your Issues')).not.toBeInTheDocument();
  117. GuideStore.setForceHide(false);
  118. expect(await screen.findByText('Identify Your Issues')).toBeInTheDocument();
  119. });
  120. });