guideAnchor.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import {ConfigFixture} from 'sentry-fixture/config';
  2. import {UserFixture} from 'sentry-fixture/user';
  3. import {act, render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  5. import ConfigStore from 'sentry/stores/configStore';
  6. import GuideStore from 'sentry/stores/guideStore';
  7. describe('GuideAnchor', function () {
  8. const serverGuide = [
  9. {
  10. guide: 'issue',
  11. seen: false,
  12. },
  13. ];
  14. const firstGuideHeader = 'How bad is it?';
  15. beforeEach(function () {
  16. ConfigStore.config = ConfigFixture({
  17. user: UserFixture({
  18. isSuperuser: false,
  19. dateJoined: '2020-01-01T00:00:00',
  20. }),
  21. });
  22. });
  23. it('renders, async advances, async and finishes', async function () {
  24. render(
  25. <div>
  26. <GuideAnchor target="issue_header_stats" />
  27. <GuideAnchor target="breadcrumbs" />
  28. <GuideAnchor target="issue_sidebar_owners" />
  29. </div>
  30. );
  31. act(() => GuideStore.fetchSucceeded(serverGuide));
  32. expect(await screen.findByText(firstGuideHeader)).toBeInTheDocument();
  33. // XXX(epurkhiser): Skip pointer event checks due to a bug with how Popper
  34. // renders the hovercard with pointer-events: none. See [0]
  35. //
  36. // [0]: https://github.com/testing-library/user-event/issues/639
  37. //
  38. // NOTE(epurkhiser): We may be able to remove the skipPointerEventsCheck
  39. // when we're on popper >= 1.
  40. await userEvent.click(screen.getByLabelText('Next'));
  41. expect(await screen.findByText('Retrace Your Steps')).toBeInTheDocument();
  42. expect(screen.queryByText(firstGuideHeader)).not.toBeInTheDocument();
  43. await userEvent.click(screen.getByLabelText('Next'));
  44. // Clicking on the button in the last step should finish the guide.
  45. const finishMock = MockApiClient.addMockResponse({
  46. method: 'PUT',
  47. url: '/assistant/',
  48. });
  49. await userEvent.click(screen.getByLabelText('Enough Already'));
  50. expect(finishMock).toHaveBeenCalledWith(
  51. '/assistant/',
  52. expect.objectContaining({
  53. method: 'PUT',
  54. data: {
  55. guide: 'issue',
  56. status: 'viewed',
  57. },
  58. })
  59. );
  60. });
  61. it('dismisses', async function () {
  62. render(
  63. <div>
  64. <GuideAnchor target="issue_header_stats" />
  65. <GuideAnchor target="breadcrumbs" />
  66. <GuideAnchor target="issue_sidebar_owners" />
  67. </div>
  68. );
  69. act(() => GuideStore.fetchSucceeded(serverGuide));
  70. expect(await screen.findByText(firstGuideHeader)).toBeInTheDocument();
  71. const dismissMock = MockApiClient.addMockResponse({
  72. method: 'PUT',
  73. url: '/assistant/',
  74. });
  75. await userEvent.click(screen.getByLabelText('Dismiss'));
  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(firstGuideHeader)).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, async do not render guide', async function () {
  107. render(
  108. <div>
  109. <GuideAnchor target="issue_header_stats" />
  110. <GuideAnchor target="breadcrumbs" />
  111. <GuideAnchor target="issue_sidebar_owners" />
  112. </div>
  113. );
  114. act(() => GuideStore.fetchSucceeded(serverGuide));
  115. expect(await screen.findByText(firstGuideHeader)).toBeInTheDocument();
  116. act(() => GuideStore.setForceHide(true));
  117. expect(screen.queryByText(firstGuideHeader)).not.toBeInTheDocument();
  118. act(() => GuideStore.setForceHide(false));
  119. expect(await screen.findByText(firstGuideHeader)).toBeInTheDocument();
  120. });
  121. });