guideAnchor.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 = TestStubs.Config({
  14. user: TestStubs.User({
  15. isSuperuser: false,
  16. dateJoined: new Date(2020, 0, 1),
  17. }),
  18. });
  19. });
  20. it('renders, async advances, async 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. await userEvent.click(screen.getByLabelText('Next'));
  37. expect(await screen.findByText('Narrow Down Suspects')).toBeInTheDocument();
  38. expect(screen.queryByText('Identify Your Issues')).not.toBeInTheDocument();
  39. // Clicking on the button in the last step should finish the guide.
  40. const finishMock = MockApiClient.addMockResponse({
  41. method: 'PUT',
  42. url: '/assistant/',
  43. });
  44. await userEvent.click(screen.getByLabelText('Enough Already'));
  45. expect(finishMock).toHaveBeenCalledWith(
  46. '/assistant/',
  47. expect.objectContaining({
  48. method: 'PUT',
  49. data: {
  50. guide: 'issue',
  51. status: 'viewed',
  52. },
  53. })
  54. );
  55. });
  56. it('dismisses', async function () {
  57. render(
  58. <div>
  59. <GuideAnchor target="issue_number" />
  60. <GuideAnchor target="exception" />
  61. </div>
  62. );
  63. GuideStore.fetchSucceeded(serverGuide);
  64. expect(await screen.findByText('Identify Your Issues')).toBeInTheDocument();
  65. const dismissMock = MockApiClient.addMockResponse({
  66. method: 'PUT',
  67. url: '/assistant/',
  68. });
  69. await userEvent.click(screen.getByLabelText('Dismiss'));
  70. expect(dismissMock).toHaveBeenCalledWith(
  71. '/assistant/',
  72. expect.objectContaining({
  73. method: 'PUT',
  74. data: {
  75. guide: 'issue',
  76. status: 'dismissed',
  77. },
  78. })
  79. );
  80. expect(screen.queryByText('Identify Your Issues')).not.toBeInTheDocument();
  81. });
  82. it('renders no container when inactive', function () {
  83. render(
  84. <GuideAnchor target="target 1">
  85. <span data-test-id="child-div" />
  86. </GuideAnchor>
  87. );
  88. expect(screen.queryByTestId('guide-container')).not.toBeInTheDocument();
  89. expect(screen.getByTestId('child-div')).toBeInTheDocument();
  90. });
  91. it('renders children when disabled', function () {
  92. render(
  93. <GuideAnchor disabled target="exception">
  94. <div data-test-id="child-div" />
  95. </GuideAnchor>
  96. );
  97. expect(screen.queryByTestId('guide-container')).not.toBeInTheDocument();
  98. expect(screen.getByTestId('child-div')).toBeInTheDocument();
  99. });
  100. it('if forceHide is true, async do not render guide', async function () {
  101. render(
  102. <div>
  103. <GuideAnchor target="issue_number" />
  104. <GuideAnchor target="exception" />
  105. </div>
  106. );
  107. GuideStore.fetchSucceeded(serverGuide);
  108. expect(await screen.findByText('Identify Your Issues')).toBeInTheDocument();
  109. GuideStore.setForceHide(true);
  110. expect(screen.queryByText('Identify Your Issues')).not.toBeInTheDocument();
  111. GuideStore.setForceHide(false);
  112. expect(await screen.findByText('Identify Your Issues')).toBeInTheDocument();
  113. });
  114. });